Mercurial > hg > index.cgi
comparison lwlink/util.c @ 0:2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
author | lost@l-w.ca |
---|---|
date | Wed, 19 Jan 2011 22:27:17 -0700 |
parents | |
children | 7317fbe024af |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2c24602be78f |
---|---|
1 /* | |
2 util.c | |
3 Copyright © 2009 William Astle | |
4 | |
5 This file is part of LWLINK. | |
6 | |
7 LWLINK is free software: you can redistribute it and/or modify it under the | |
8 terms of the GNU General Public License as published by the Free Software | |
9 Foundation, either version 3 of the License, or (at your option) any later | |
10 version. | |
11 | |
12 This program is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 more details. | |
16 | |
17 You should have received a copy of the GNU General Public License along with | |
18 this program. If not, see <http://www.gnu.org/licenses/>. | |
19 */ | |
20 | |
21 /* | |
22 Utility functions | |
23 */ | |
24 | |
25 #define __util_c_seen__ | |
26 #include <malloc.h> | |
27 #include <stdio.h> | |
28 #include <stdlib.h> | |
29 #include <string.h> | |
30 | |
31 #include "util.h" | |
32 | |
33 void *lw_malloc(int size) | |
34 { | |
35 void *ptr; | |
36 | |
37 ptr = malloc(size); | |
38 if (!ptr) | |
39 { | |
40 // bail out; memory allocation error | |
41 fprintf(stderr, "lw_malloc(): Memory allocation error\n"); | |
42 exit(1); | |
43 } | |
44 return ptr; | |
45 } | |
46 | |
47 void *lw_realloc(void *optr, int size) | |
48 { | |
49 void *ptr; | |
50 | |
51 if (size == 0) | |
52 { | |
53 lw_free(optr); | |
54 return; | |
55 } | |
56 | |
57 ptr = realloc(optr, size); | |
58 if (!ptr) | |
59 { | |
60 fprintf(stderr, "lw_realloc(): memory allocation error\n"); | |
61 exit(1); | |
62 } | |
63 } | |
64 | |
65 void lw_free(void *ptr) | |
66 { | |
67 if (ptr) | |
68 free(ptr); | |
69 } | |
70 | |
71 char *lw_strdup(const char *s) | |
72 { | |
73 char *d; | |
74 | |
75 if (!s) | |
76 return NULL; | |
77 | |
78 d = strdup(s); | |
79 if (!d) | |
80 { | |
81 fprintf(stderr, "lw_strdup(): memory allocation error\n"); | |
82 exit(1); | |
83 } | |
84 | |
85 return d; | |
86 } |