diff options
author | cl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk> | 2005-06-07 12:43:58 +0000 |
---|---|---|
committer | cl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk> | 2005-06-07 12:43:58 +0000 |
commit | 29c9e570b1eddfd6df789e08da65cf4ddec5f6fe (patch) | |
tree | bf79ad3040d05ee9e05a60df3b8a364fcfa236dc /tools/xenstore/utils.h | |
parent | 636a81e9701d001f4c9108f722014f48f59eabbd (diff) | |
download | xen-29c9e570b1eddfd6df789e08da65cf4ddec5f6fe.tar.gz xen-29c9e570b1eddfd6df789e08da65cf4ddec5f6fe.tar.bz2 xen-29c9e570b1eddfd6df789e08da65cf4ddec5f6fe.zip |
bitkeeper revision 1.1662.1.15 (42a5968eiZE_DjdIFPjxvzLw6ACvCQ)
Add xenstore daemon and library.
Makefile:
Add xenstore subdirectory.
Remove xs_stress on clean.
Many files:
new file
ignore:
Update ignore list for xenstore.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (authored)
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Diffstat (limited to 'tools/xenstore/utils.h')
-rw-r--r-- | tools/xenstore/utils.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/xenstore/utils.h b/tools/xenstore/utils.h new file mode 100644 index 0000000000..a84f19a22a --- /dev/null +++ b/tools/xenstore/utils.h @@ -0,0 +1,61 @@ +#ifndef _UTILS_H +#define _UTILS_H +#include <stdbool.h> +#include <string.h> +#include <stdint.h> + +/* Is A == B ? */ +#define streq(a,b) (strcmp((a),(b)) == 0) + +/* Does A start with B ? */ +#define strstarts(a,b) (strncmp((a),(b),strlen(b)) == 0) + +/* Does A end in B ? */ +static inline bool strends(const char *a, const char *b) +{ + if (strlen(a) < strlen(b)) + return false; + + return streq(a + strlen(a) - strlen(b), 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); + +/* For writing daemons, based on Stevens. */ +void daemonize(void); + +/* 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 + +#endif /* _UTILS_H */ |