GNU.WIKI: The GNU/Linux Knowledge Base

  [HOME] [PHP Manual] [HowTo] [ABS] [MAN1] [MAN2] [MAN3] [MAN4] [MAN5] [MAN6] [MAN7] [MAN8] [MAN9]

  [0-9] [Aa] [Bb] [Cc] [Dd] [Ee] [Ff] [Gg] [Hh] [Ii] [Jj] [Kk] [Ll] [Mm] [Nn] [Oo] [Pp] [Qq] [Rr] [Ss] [Tt] [Uu] [Vv] [Ww] [Xx] [Yy] [Zz]


       xmalloc,  xrealloc, xfree, xstrdup, xmemdup, memdup - memory allocation
       functions for Publib


       #include <publib.h>

       void *xmalloc(size_t bytes);
       void *xrealloc(void *ptr, size_t bytes);
       void xfree(void *ptr);
       char *xstrdup(const char *string);
       void *memdup(const void *mem, size_t bytes);
       void *xmemdup(const void *mem, size_t bytes);


       These functions are utility functions for memory  allocation  from  the
       publib  library.   xmalloc,  xrealloc,  and  xfree  are  error checking
       versions of the standard library routines malloc,  realloc,  and  free,
       respectively.   They are guaranteed to never return unless there was no
       problem: if, for example, xmalloc is unable to allocate  the  requested
       amount  of  memory,  it  prints  an  error  message  and terminates the
       program.  Hence, the caller does not need to check for  a  NULL  return
       value,  and  the  code that calls these functions is simpler due to the
       lack of error checks.

       Similarly, xstrdup is an error checking version of the  common  (though
       not  standard) strdup routine, which creates a duplicate of a string by
       allocating memory for the copy with malloc.   (For  systems  that  lack
       strdup,  publib  provides  one  in its portability module; it is always
       declared in <publib.h>.)

       memdup is similar to strdup, it creates a copy of an  arbitrary  memory
       area (the arguments are a pointer to the beginning of the area, and its
       size) by allocating memory for the copy with malloc.   xmemdup  is  its
       error checking version.


       xmalloc  and xrealloc treat a request to allocate a block of 0 bytes as
       an error.  xrealloc will allow its first argument to be NULL.


       publib(3), malloc(3), strdup(3)


       Lars Wirzenius (

  All copyrights belong to their respective owners. Other content (c) 2014-2018, GNU.WIKI. Please report site errors to
Page load time: 0.295 seconds. Last modified: November 04 2018 12:49:43.