inline rc_xmalloc, rc_xrealloc and rc_xstrdup so that the library doesn't expose them.
This commit is contained in:
parent
af5525f634
commit
a6f2713002
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
21
src/rc.h
21
src/rc.h
@ -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:
|
||||
*;
|
||||
|
Loading…
Reference in New Issue
Block a user