diff options
-rw-r--r-- | tools/xenstore/utils.c | 69 | ||||
-rw-r--r-- | tools/xenstore/utils.h | 27 |
2 files changed, 0 insertions, 96 deletions
diff --git a/tools/xenstore/utils.c b/tools/xenstore/utils.c index 16f87cdc05..45e71efd14 100644 --- a/tools/xenstore/utils.c +++ b/tools/xenstore/utils.c @@ -61,72 +61,3 @@ void barf_perror(const char *fmt, ...) } exit(1); } - -void *_realloc_array(void *ptr, size_t size, size_t num) -{ - if (num >= SIZE_MAX/size) - return NULL; - return realloc_nofail(ptr, size * num); -} - -void *realloc_nofail(void *ptr, size_t size) -{ - ptr = realloc(ptr, size); - if (ptr) - return ptr; - barf("realloc of %zu failed", size); -} - -void *malloc_nofail(size_t size) -{ - void *ptr = malloc(size); - if (ptr) - return ptr; - barf("malloc of %zu failed", size); -} - -/* This version adds one byte (for nul term) */ -void *grab_file(const char *filename, unsigned long *size) -{ - unsigned int max = 16384; - int ret, fd; - void *buffer; - - if (streq(filename, "-")) - fd = dup(STDIN_FILENO); - else - fd = open(filename, O_RDONLY, 0); - - if (fd == -1) - return NULL; - - buffer = malloc(max+1); - if (!buffer) - goto error; - *size = 0; - while ((ret = read(fd, buffer + *size, max - *size)) > 0) { - *size += ret; - if (*size == max) { - void *nbuffer; - max *= 2; - nbuffer = realloc(buffer, max + 1); - if (!nbuffer) - goto error; - buffer = nbuffer; - } - } - if (ret < 0) - goto error; - ((char *)buffer)[*size] = '\0'; - close(fd); - return buffer; -error: - free(buffer); - close(fd); - return NULL; -} - -void release_file(void *data, unsigned long size __attribute__((unused))) -{ - free(data); -} diff --git a/tools/xenstore/utils.h b/tools/xenstore/utils.h index df82c1c5ef..ce14f3a408 100644 --- a/tools/xenstore/utils.h +++ b/tools/xenstore/utils.h @@ -21,39 +21,12 @@ static inline bool strends(const char *a, const char *b) #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) -#define ___stringify(x) #x -#define __stringify(x) ___stringify(x) - -/* Convenient wrappers for malloc and realloc. Use them. */ -#define new(type) ((type *)malloc_nofail(sizeof(type))) -#define new_array(type, num) realloc_array((type *)0, (num)) -#define realloc_array(ptr, num) ((__typeof__(ptr))_realloc_array((ptr), sizeof((*ptr)), (num))) - -void *malloc_nofail(size_t size); -void *realloc_nofail(void *ptr, size_t size); -void *_realloc_array(void *ptr, size_t size, size_t num); - void barf(const char *fmt, ...) __attribute__((noreturn)); void barf_perror(const char *fmt, ...) __attribute__((noreturn)); -/* This version adds one byte (for nul term) */ -void *grab_file(const char *filename, unsigned long *size); -void release_file(void *data, unsigned long size); - -/* Signal handling: returns fd to listen on. */ -int signal_to_fd(int signal); -void close_signal(int fd); - void xprintf(const char *fmt, ...); #define eprintf(_fmt, _args...) xprintf("[ERR] %s" _fmt, __FUNCTION__, ##_args) -#define iprintf(_fmt, _args...) xprintf("[INF] %s" _fmt, __FUNCTION__, ##_args) - -#ifdef DEBUG -#define dprintf(_fmt, _args...) xprintf("[DBG] %s" _fmt, __FUNCTION__, ##_args) -#else -#define dprintf(_fmt, _args...) ((void)0) -#endif /* * Mux errno values onto returned pointers. |