debuggers.hg
annotate tools/xenstore/utils.h @ 22848:6341fe0f4e5a
Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author | Keir Fraser <keir@xen.org> |
---|---|
date | Tue Jan 25 14:06:55 2011 +0000 (2011-01-25) |
parents | f343d3c16dcc |
children |
rev | line source |
---|---|
cl349@5395 | 1 #ifndef _UTILS_H |
cl349@5395 | 2 #define _UTILS_H |
cl349@5395 | 3 #include <stdbool.h> |
cl349@5395 | 4 #include <string.h> |
cl349@5395 | 5 #include <stdint.h> |
cl349@5395 | 6 |
cl349@5395 | 7 /* Is A == B ? */ |
cl349@5395 | 8 #define streq(a,b) (strcmp((a),(b)) == 0) |
cl349@5395 | 9 |
cl349@5395 | 10 /* Does A start with B ? */ |
cl349@5395 | 11 #define strstarts(a,b) (strncmp((a),(b),strlen(b)) == 0) |
cl349@5395 | 12 |
cl349@5395 | 13 /* Does A end in B ? */ |
cl349@5395 | 14 static inline bool strends(const char *a, const char *b) |
cl349@5395 | 15 { |
cl349@5395 | 16 if (strlen(a) < strlen(b)) |
cl349@5395 | 17 return false; |
cl349@5395 | 18 |
cl349@5395 | 19 return streq(a + strlen(a) - strlen(b), b); |
cl349@5395 | 20 } |
cl349@5395 | 21 |
cl349@5395 | 22 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
cl349@5395 | 23 |
cl349@5395 | 24 void barf(const char *fmt, ...) __attribute__((noreturn)); |
cl349@5395 | 25 void barf_perror(const char *fmt, ...) __attribute__((noreturn)); |
cl349@5395 | 26 |
kfraser@15711 | 27 void (*xprintf)(const char *fmt, ...); |
cl349@5395 | 28 |
cl349@5395 | 29 #define eprintf(_fmt, _args...) xprintf("[ERR] %s" _fmt, __FUNCTION__, ##_args) |
cl349@5395 | 30 |
kaf24@7323 | 31 /* |
kaf24@7323 | 32 * Mux errno values onto returned pointers. |
kaf24@7323 | 33 */ |
kaf24@7323 | 34 |
kaf24@7323 | 35 static inline void *ERR_PTR(long error) |
kaf24@7323 | 36 { |
kaf24@7323 | 37 return (void *)error; |
kaf24@7323 | 38 } |
kaf24@7323 | 39 |
kaf24@7323 | 40 static inline long PTR_ERR(const void *ptr) |
kaf24@7323 | 41 { |
kaf24@7323 | 42 return (long)ptr; |
kaf24@7323 | 43 } |
kaf24@7323 | 44 |
kaf24@7323 | 45 static inline long IS_ERR(const void *ptr) |
kaf24@7323 | 46 { |
kaf24@7323 | 47 return ((unsigned long)ptr > (unsigned long)-1000L); |
kaf24@7323 | 48 } |
kaf24@7323 | 49 |
kaf24@7323 | 50 |
cl349@5395 | 51 #endif /* _UTILS_H */ |
kaf24@7323 | 52 |
kaf24@7323 | 53 /* |
kaf24@7323 | 54 * Local variables: |
kaf24@7323 | 55 * c-file-style: "linux" |
kaf24@7323 | 56 * indent-tabs-mode: t |
kaf24@7323 | 57 * c-indent-level: 8 |
kaf24@7323 | 58 * c-basic-offset: 8 |
kaf24@7323 | 59 * tab-width: 8 |
kaf24@7323 | 60 * End: |
kaf24@7323 | 61 */ |