10 #include "forwarder.h"
12 const char *const *argv;
13 char programid[SYS_NMLN+sizeof(PROGRAM)+3];
15 void arg_assert_fail(const char *msg) {
16 fprintf(stderr, PROGRAM ": argument error (!`%s')\n",msg);
20 void sysfail(const char *msg) {
21 fprintf(stderr, "%s: fatal system error: %s: %s\n", programid, msg, strerror(errno));
25 void fail(const char *msg) {
26 fprintf(stderr, "%s: fatal error: %s\n", programid, msg);
30 void sysdiag(const char *msg) {
31 fprintf(stderr, "%s: system/network error: %s: %s\n", programid, msg, strerror(errno));
34 void diag(const char *msg) {
35 fprintf(stderr, "%s: %s\n", programid, msg);
40 if (time(&r) == (time_t)-1) sysfail("get time of day");
44 void *xmalloc(size_t sz) {
47 if (!r) sysfail("allocate memory");
51 void write_must(int fd, const void *p_in, int sz, const char *what) {
52 const unsigned char *p= p_in;
58 if (errno == EINTR) continue;
67 void read_must(int fd, void *p_in, int sz, const char *what) {
68 unsigned char *p= p_in;
74 if (errno == EINTR) continue;
84 const char *getarg_string(void) {
92 unsigned long getarg_ulong(void) {
96 ul= strtoul(getarg_string(),&ep,0);
101 void *buf_append(struct buffer *buf, size_t amount) {
104 p= buf->start + buf->size;
109 void *buf_prepend(struct buffer *buf, size_t amount) {
111 return buf->start -= amount;
114 void *buf_unappend(struct buffer *buf, size_t amount) {
115 if (buf->size < amount) return 0;
116 return buf->start + (buf->size -= amount);
119 void *buf_unprepend(struct buffer *buf, size_t amount) {
123 buf->start += amount;