source: trunk/third/ssh/xmalloc.c @ 12646

Revision 12646, 1.5 KB checked in by danw, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r12645, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2
3xmalloc.c
4
5Author: Tatu Ylonen <ylo@cs.hut.fi>
6
7Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8                   All rights reserved
9
10Created: Mon Mar 20 21:23:10 1995 ylo
11
12Versions of malloc and friends that check their results, and never return
13failure (they call fatal if they encounter an error).
14
15*/
16
17/*
18 * $Id: xmalloc.c,v 1.1.1.2 1999-03-08 17:43:14 danw Exp $
19 * $Log: not supported by cvs2svn $
20 * Revision 1.1.1.1  1996/02/18  21:38:11  ylo
21 *      Imported ssh-1.2.13.
22 *
23 * Revision 1.3  1995/08/29  22:36:39  ylo
24 *      Commented out malloc prototypes.
25 *
26 * Revision 1.2  1995/07/13  01:41:33  ylo
27 *      Removed "Last modified" header.
28 *      Added cvs log.
29 *
30 * $Endlog$
31 */
32
33#include "includes.h"
34#include "ssh.h"
35
36#if 0
37void *malloc(size_t size);
38void *realloc(void *ptr, size_t size);
39void free(void *ptr);
40#endif
41
42void *xmalloc(size_t size)
43{
44  void *ptr = malloc(size);
45  if (ptr == NULL)
46    fatal("xmalloc: out of memory (allocating %d bytes)", (int)size);
47  return ptr;
48}
49
50void *xrealloc(void *ptr, size_t new_size)
51{
52  void *new_ptr;
53
54  if (ptr == NULL)
55    fatal("xrealloc: NULL pointer given as argument");
56  new_ptr = realloc(ptr, new_size);
57  if (new_ptr == NULL)
58    fatal("xrealloc: out of memory (new_size %d bytes)", (int)new_size);
59  return new_ptr;
60}
61
62void xfree(void *ptr)
63{
64  if (ptr == NULL)
65    fatal("xfree: NULL pointer given as argument");
66  free(ptr);
67}
68
69char *xstrdup(const char *str)
70{
71  char *cp = xmalloc(strlen(str) + 1);
72  strcpy(cp, str);
73  return cp;
74}
Note: See TracBrowser for help on using the repository browser.