Mercurial > hg-old > index.cgi
annotate lwlink/util.c @ 265:68fbca173508 2.6
Added generated files for release
author | lost |
---|---|
date | Tue, 22 Dec 2009 05:31:23 +0000 |
parents | bae1e3ecdce1 |
children |
rev | line source |
---|---|
114
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
1 /* |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
2 util.c |
118 | 3 Copyright © 2009 William Astle |
114
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
4 |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
5 This file is part of LWLINK. |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
6 |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
7 LWLINK is free software: you can redistribute it and/or modify it under the |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
8 terms of the GNU General Public License as published by the Free Software |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
9 Foundation, either version 3 of the License, or (at your option) any later |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
10 version. |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
11 |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
12 This program is distributed in the hope that it will be useful, but WITHOUT |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
15 more details. |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
16 |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License along with |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
18 this program. If not, see <http://www.gnu.org/licenses/>. |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
19 */ |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
20 |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
21 /* |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
22 Utility functions |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
23 */ |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
24 |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
25 #define __util_c_seen__ |
212 | 26 #include <config.h> |
114
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
27 |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
28 #include <malloc.h> |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
29 #include <stdio.h> |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
30 #include <stdlib.h> |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
31 #include <string.h> |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
32 |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
33 #include "util.h" |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
34 |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
35 void *lw_malloc(int size) |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
36 { |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
37 void *ptr; |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
38 |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
39 ptr = malloc(size); |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
40 if (!ptr) |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
41 { |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
42 // bail out; memory allocation error |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
43 fprintf(stderr, "lw_malloc(): Memory allocation error\n"); |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
44 exit(1); |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
45 } |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
46 return ptr; |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
47 } |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
48 |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
49 void *lw_realloc(void *optr, int size) |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
50 { |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
51 void *ptr; |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
52 |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
53 if (size == 0) |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
54 { |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
55 lw_free(optr); |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
56 return; |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
57 } |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
58 |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
59 ptr = realloc(optr, size); |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
60 if (!ptr) |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
61 { |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
62 fprintf(stderr, "lw_realloc(): memory allocation error\n"); |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
63 exit(1); |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
64 } |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
65 } |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
66 |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
67 void lw_free(void *ptr) |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
68 { |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
69 if (ptr) |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
70 free(ptr); |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
71 } |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
72 |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
73 char *lw_strdup(const char *s) |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
74 { |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
75 char *d; |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
76 |
116 | 77 if (!s) |
78 return NULL; | |
79 | |
114
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
80 d = strdup(s); |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
81 if (!d) |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
82 { |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
83 fprintf(stderr, "lw_strdup(): memory allocation error\n"); |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
84 exit(1); |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
85 } |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
86 |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
87 return d; |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
diff
changeset
|
88 } |