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 | |
parent | af5525f6342c6ceda5913d2f6675d72ea8501ef3 (diff) |
inline rc_xmalloc, rc_xrealloc and rc_xstrdup so that the library doesn't expose them.
-rw-r--r-- | src/librc-misc.c | 38 | ||||
-rw-r--r-- | src/rc-misc.h | 39 | ||||
-rw-r--r-- | src/rc.h | 21 | ||||
-rw-r--r-- | src/rc.map | 3 |
4 files changed, 39 insertions, 62 deletions
diff --git a/src/librc-misc.c b/src/librc-misc.c index 936fc730..f255f706 100644 --- a/src/librc-misc.c +++ b/src/librc-misc.c @@ -6,7 +6,6 @@ #include "librc.h" -#define ERRX fprintf (stderr, "out of memory\n"); exit (1) #define PROFILE_ENV "/etc/profile.env" #define SYS_WHITELIST RC_LIBDIR "/conf.d/env_whitelist" @@ -15,43 +14,6 @@ #define PATH_PREFIX RC_LIBDIR "/bin:/bin:/sbin:/usr/bin:/usr/sbin" -void *rc_xmalloc (size_t size) -{ - void *value = malloc (size); - - if (value) - return (value); - - ERRX; -} -librc_hidden_def(rc_xmalloc) - -void *rc_xrealloc (void *ptr, size_t size) -{ - void *value = realloc (ptr, size); - - if (value) - return (value); - - ERRX; -} -librc_hidden_def(rc_xrealloc) - -char *rc_xstrdup (const char *str) -{ - char *value; - - if (! str) - return (NULL); - - value = strdup (str); - - if (value) - return (value); - - ERRX; -} -librc_hidden_def(rc_xstrdup) bool rc_env_bool (const char *var) { 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; @@ -419,27 +419,6 @@ void rc_strlist_reverse (char **list); * @param list to free */ void rc_strlist_free (char **list); -/*! @name Memory Allocation - * Ensure that if we cannot allocate the memory then we exit */ -/*@{*/ - -/*! Allocate a block of memory - * @param size of memory to allocate - * @return pointer to memory */ -void *rc_xmalloc (size_t size); - -/*! Re-size a block of memory - * @param ptr to the block of memory to re-size - * @param size memory should be - * @return pointer to memory block */ -void *rc_xrealloc (void *ptr, size_t size); - -/*! Duplicate a NULL terminated string - * @param str to duplicate - * @return pointer to the new string */ -char *rc_xstrdup (const char *str); -/*@}*/ - /*! @name Utility * Although not RC specific functions, they are used by the supporting * applications */ @@ -57,9 +57,6 @@ global: rc_strlist_join; rc_strlist_reverse; rc_waitpid; - rc_xmalloc; - rc_xrealloc; - rc_xstrdup; local: *; |