[BACK]Return to xmalloc.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Annotation of src/usr.bin/ssh/xmalloc.c, Revision 1.2

1.1       deraadt     1: /*
                      2:
                      3: xmalloc.c
                      4:
                      5: Author: Tatu Ylonen <ylo@cs.hut.fi>
                      6:
                      7: Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
                      8:                    All rights reserved
                      9:
                     10: Created: Mon Mar 20 21:23:10 1995 ylo
                     11:
                     12: Versions of malloc and friends that check their results, and never return
                     13: failure (they call fatal if they encounter an error).
                     14:
                     15: */
                     16:
                     17: #include "includes.h"
1.2     ! deraadt    18: RCSID("$Id: xmalloc.c,v 1.1 1999/09/26 20:53:38 deraadt Exp $");
1.1       deraadt    19:
                     20: #include "ssh.h"
                     21:
                     22: #if 0
                     23: void *malloc(size_t size);
                     24: void *realloc(void *ptr, size_t size);
                     25: void free(void *ptr);
                     26: #endif
                     27:
                     28: void *xmalloc(size_t size)
                     29: {
                     30:   void *ptr = malloc(size);
                     31:   if (ptr == NULL)
                     32:     fatal("xmalloc: out of memory (allocating %d bytes)", (int)size);
                     33:   return ptr;
                     34: }
                     35:
                     36: void *xrealloc(void *ptr, size_t new_size)
                     37: {
                     38:   void *new_ptr;
                     39:
                     40:   if (ptr == NULL)
                     41:     fatal("xrealloc: NULL pointer given as argument");
                     42:   new_ptr = realloc(ptr, new_size);
                     43:   if (new_ptr == NULL)
                     44:     fatal("xrealloc: out of memory (new_size %d bytes)", (int)new_size);
                     45:   return new_ptr;
                     46: }
                     47:
                     48: void xfree(void *ptr)
                     49: {
                     50:   if (ptr == NULL)
                     51:     fatal("xfree: NULL pointer given as argument");
                     52:   free(ptr);
                     53: }
                     54:
                     55: char *xstrdup(const char *str)
                     56: {
1.2     ! deraadt    57:   int len = strlen(str) + 1;
        !            58:
        !            59:   char *cp = xmalloc(len);
        !            60:   strlcpy(cp, str, len);
1.1       deraadt    61:   return cp;
                     62: }