"Fossies" - the Fresh Open Source Software Archive 
Member "scanssh-2.1/xmalloc.c" (14 Jul 2004, 1638 Bytes) of package /linux/privat/old/scanssh-2.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /*
2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
5 * Versions of malloc and friends that check their results, and never return
6 * failure (they call fatal if they encounter an error).
7 *
8 * As far as I am concerned, the code I have written for this software
9 * can be used freely for any purpose. Any derived versions of this
10 * software must be clearly marked as such, and if the derived work is
11 * incompatible with the protocol description in the RFC file, it must be
12 * called by a name other than "ssh" or "Secure Shell".
13 */
14
15 #include <sys/types.h>
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <err.h>
19 #include <string.h>
20
21 #include "config.h"
22
23 void *
24 xmalloc(size_t size)
25 {
26 void *ptr;
27
28 if (size == 0)
29 err(1,"xmalloc: zero size");
30 ptr = malloc(size);
31 if (ptr == NULL) {
32 fprintf(stderr,
33 "xmalloc: out of memory (allocating %lu bytes)",
34 (u_long) size);
35 abort();
36 }
37 return ptr;
38 }
39
40 void *
41 xrealloc(void *ptr, size_t new_size)
42 {
43 void *new_ptr;
44
45 if (new_size == 0)
46 err(1,"xrealloc: zero size");
47 if (ptr == NULL)
48 err(1,"xrealloc: NULL pointer given as argument");
49 new_ptr = realloc(ptr, new_size);
50 if (new_ptr == NULL)
51 err(1,"xrealloc: out of memory (new_size %lu bytes)", (u_long) new_size);
52 return new_ptr;
53 }
54
55 void
56 xfree(void *ptr)
57 {
58 if (ptr == NULL)
59 err(1,"xfree: NULL pointer given as argument");
60 free(ptr);
61 }
62
63 char *
64 xstrdup(const char *str)
65 {
66 size_t len = strlen(str) + 1;
67 char *cp;
68
69 if (len == 0)
70 err(1,"xstrdup: zero size");
71 cp = xmalloc(len);
72 strlcpy(cp, str, len);
73 return cp;
74 }