/* Functions copied from nbase needed to support nbase_addrset.c. */ #include #include #include #include static void fatal(char *fmt, ...) __attribute__ ((format (printf, 1, 2))); static void fatal(char *fmt, ...) { va_list ap; va_start(ap, fmt); fflush(stdout); vfprintf(stderr, fmt, ap); fprintf(stderr, "\nQUITTING!\n"); va_end(ap); exit(1); } void *safe_malloc(size_t size) { void *mymem; if ((int) size < 0) /* Catch caller errors */ fatal("Tried to malloc negative amount of memory!!!"); mymem = malloc(size); if (mymem == NULL) fatal("Malloc Failed! Probably out of space."); return mymem; } /* This is like strtol or atoi, but it allows digits only. No whitespace, sign, or radix prefix. */ long parse_long(const char *s, char **tail) { if (!isdigit((int) (unsigned char) *s)) { *tail = (char *) s; return 0; } return strtol(s, (char **) tail, 10); } /* This is like strtol or atoi, but it allows hex-digits only. No whitespace, sign, or radix prefix. */ long parse_long_hex(const char *s, char **tail) { if (!isxdigit((int) (unsigned char) *s)) { *tail = (char *) s; return 0; } return strtol(s, (char **) tail, 16); }