diff options
author | Roy Marples <roy@marples.name> | 2007-10-04 17:26:57 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2007-10-04 17:26:57 +0000 |
commit | a6f2713002db20cd65618c1140ed7d3fbbbb9292 (patch) | |
tree | 09e8ad5903ba7472f5f01e410550e2e9c79367db /src/rc-misc.h | |
parent | af5525f6342c6ceda5913d2f6675d72ea8501ef3 (diff) |
inline rc_xmalloc, rc_xrealloc and rc_xstrdup so that the library doesn't expose them.
Diffstat (limited to 'src/rc-misc.h')
-rw-r--r-- | src/rc-misc.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/rc-misc.h b/src/rc-misc.h index 40228b70..609447f7 100644 --- a/src/rc-misc.h +++ b/src/rc-misc.h @@ -41,6 +41,45 @@ /* Good defaults just incase user has none set */ #define RC_NET_FS_LIST_DEFAULT "afs cifs coda davfs fuse gfs ncpfs nfs nfs4 ocfs2 shfs smbfs" +#define ERRX fprintf (stderr, "out of memory\n"); exit (1) + +static inline void *rc_xmalloc (size_t size) +{ + void *value = malloc (size); + + if (value) + return (value); + + ERRX; +} + +static inline void *rc_xrealloc (void *ptr, size_t size) +{ + void *value = realloc (ptr, size); + + if (value) + return (value); + + ERRX; +} + +static inline char *rc_xstrdup (const char *str) +{ + char *value; + + if (! str) + return (NULL); + + value = strdup (str); + + if (value) + return (value); + + ERRX; +} + +#undef ERRX + static inline bool rc_exists (const char *pathname) { struct stat buf; |