aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

ealloc.c (1255B)


      1 /* see LICENSE file for copyright and license details */
      2 #include <stdlib.h>
      3 #include <string.h>
      4 
      5 #include "../util.h"
      6 
      7 void *
      8 ecalloc(size_t nmemb, size_t size)
      9 {
     10   return encalloc(1, nmemb, size);
     11 }
     12 
     13 void *
     14 emalloc(size_t size)
     15 {
     16   return enmalloc(1, size);
     17 }
     18 
     19 void *
     20 erealloc(void *p, size_t size)
     21 {
     22   return enrealloc(1, p, size);
     23 }
     24 
     25 char *
     26 estrdup(const char *s)
     27 {
     28   return enstrdup(1, s);
     29 }
     30 
     31 char *
     32 estrndup(const char *s, size_t n)
     33 {
     34   return enstrndup(1, s, n);
     35 }
     36 
     37 void *
     38 encalloc(int status, size_t nmemb, size_t size)
     39 {
     40   void *p;
     41 
     42   p = calloc(nmemb, size);
     43   if (!p)
     44     enprintf(status, "calloc: out of memory\n");
     45   return p;
     46 }
     47 
     48 void *
     49 enmalloc(int status, size_t size)
     50 {
     51   void *p;
     52 
     53   p = malloc(size);
     54   if (!p)
     55     enprintf(status, "malloc: out of memory\n");
     56   return p;
     57 }
     58 
     59 void *
     60 enrealloc(int status, void *p, size_t size)
     61 {
     62   p = realloc(p, size);
     63   if (!p)
     64     enprintf(status, "realloc: out of memory\n");
     65   return p;
     66 }
     67 
     68 char *
     69 enstrdup(int status, const char *s)
     70 {
     71   char *p;
     72 
     73   p = strdup(s);
     74   if (!p)
     75     enprintf(status, "strdup: out of memory\n");
     76   return p;
     77 }
     78 
     79 char *
     80 enstrndup(int status, const char *s, size_t n)
     81 {
     82   char *p;
     83 
     84   p = strndup(s, n);
     85   if (!p)
     86     enprintf(status, "strndup: out of memory\n");
     87   return p;
     88 }