comparison srf2fastq/io_lib-1.12.2/io_lib/xalloc.c @ 0:d901c9f41a6a default tip

Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
author dawe
date Tue, 07 Jun 2011 17:48:05 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d901c9f41a6a
1 /*
2 * Copyright (c) Medical Research Council 1994. All rights reserved.
3 *
4 * Permission to use, copy, modify and distribute this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * this copyright and notice appears in all copies.
7 *
8 * This file was written by James Bonfield, Simon Dear, Rodger Staden,
9 * as part of the Staden Package at the MRC Laboratory of Molecular
10 * Biology, Hills Road, Cambridge, CB2 2QH, United Kingdom.
11 *
12 * MRC disclaims all warranties with regard to this software.
13 */
14
15 /*
16 * Our own memory alloc routines that output error messages as appropriate
17 * for us. Could also be done as macros, but hopefully there are no tight
18 * using malloc many times so efficiency shouldn't be a problem.
19 *
20 * This also allows for dropping in a debugging malloc as we're intercepting
21 * all alloc & free commands.
22 */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <errno.h>
27 #include "io_lib/error.h"
28
29 void *xmalloc(size_t size) {
30 void *c = malloc(size);
31
32 if (NULL == c) {
33 errout("Not enough memory.\n");
34 return NULL;
35 }
36
37 return c;
38 }
39
40 void *xrealloc(void *ptr, size_t size) {
41 void *c;
42
43 /*
44 * realloc _should_ allocate memory for us when ptr is NULL.
45 * Unfortunately this is not the case with the non-ANSI conformant
46 * C library provided with SunOS4.1
47 */
48 if (ptr)
49 c = realloc(ptr, size);
50 else
51 c = malloc(size);
52
53 if (NULL == c) {
54 errout("Not enough memory.\n");
55 return NULL;
56 }
57
58 return c;
59 }
60
61 void *xcalloc(size_t num, size_t size) {
62 void *c = calloc(num, size);
63
64 if (NULL == c) {
65 errout("Not enough memory.\n");
66 return NULL;
67 }
68
69 return c;
70 }
71
72 void xfree(void *ptr) {
73 free(ptr);
74 }