ia64/xen-unstable

view tools/xenstore/utils.h @ 6812:26cf3cfd3bed

Switch vcpu hotplugging to use xstransact.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Tue Sep 13 17:31:13 2005 +0000 (2005-09-13)
parents dd668f7527cb
children b2f4823b6ff0 b35215021b32 9af349b055e5 3233e7ecfa9f
line source
1 #ifndef _UTILS_H
2 #define _UTILS_H
3 #include <stdbool.h>
4 #include <string.h>
5 #include <stdint.h>
7 /* Is A == B ? */
8 #define streq(a,b) (strcmp((a),(b)) == 0)
10 /* Does A start with B ? */
11 #define strstarts(a,b) (strncmp((a),(b),strlen(b)) == 0)
13 /* Does A end in B ? */
14 static inline bool strends(const char *a, const char *b)
15 {
16 if (strlen(a) < strlen(b))
17 return false;
19 return streq(a + strlen(a) - strlen(b), b);
20 }
22 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
24 #define ___stringify(x) #x
25 #define __stringify(x) ___stringify(x)
27 /* Convenient wrappers for malloc and realloc. Use them. */
28 #define new(type) ((type *)malloc_nofail(sizeof(type)))
29 #define new_array(type, num) realloc_array((type *)0, (num))
30 #define realloc_array(ptr, num) ((__typeof__(ptr))_realloc_array((ptr), sizeof((*ptr)), (num)))
32 void *malloc_nofail(size_t size);
33 void *realloc_nofail(void *ptr, size_t size);
34 void *_realloc_array(void *ptr, size_t size, size_t num);
36 void barf(const char *fmt, ...) __attribute__((noreturn));
37 void barf_perror(const char *fmt, ...) __attribute__((noreturn));
39 /* This version adds one byte (for nul term) */
40 void *grab_file(const char *filename, unsigned long *size);
41 void release_file(void *data, unsigned long size);
43 /* Signal handling: returns fd to listen on. */
44 int signal_to_fd(int signal);
45 void close_signal(int fd);
47 void xprintf(const char *fmt, ...);
49 #define eprintf(_fmt, _args...) xprintf("[ERR] %s" _fmt, __FUNCTION__, ##_args)
50 #define iprintf(_fmt, _args...) xprintf("[INF] %s" _fmt, __FUNCTION__, ##_args)
52 #ifdef DEBUG
53 #define dprintf(_fmt, _args...) xprintf("[DBG] %s" _fmt, __FUNCTION__, ##_args)
54 #else
55 #define dprintf(_fmt, _args...) ((void)0)
56 #endif
58 #endif /* _UTILS_H */