Mercurial > ~dholland > hg > tradcpp > index.cgi
comparison utils.c @ 39:337110e7240a
Pass the size to free; it makes debug checking easier.
author | David A. Holland |
---|---|
date | Sat, 30 Mar 2013 21:17:47 -0400 |
parents | b156910b59b2 |
children | ef8bedab8a4b |
comparison
equal
deleted
inserted
replaced
38:b156910b59b2 | 39:337110e7240a |
---|---|
55 } | 55 } |
56 return ret; | 56 return ret; |
57 } | 57 } |
58 | 58 |
59 void * | 59 void * |
60 dorealloc(void *ptr, size_t len) | 60 dorealloc(void *ptr, size_t oldlen, size_t newlen) |
61 { | 61 { |
62 void *ret; | 62 void *ret; |
63 | 63 |
64 ret = realloc(ptr, len); | 64 (void)oldlen; |
65 ret = realloc(ptr, newlen); | |
65 if (ret == NULL) { | 66 if (ret == NULL) { |
66 warnx("Out of memory"); | 67 warnx("Out of memory"); |
67 die(); | 68 die(); |
68 } | 69 } |
69 return ret; | 70 return ret; |
70 } | 71 } |
71 | 72 |
72 void | 73 void |
73 dofree(void *ptr) | 74 dofree(void *ptr, size_t len) |
74 { | 75 { |
76 (void)len; | |
75 free(ptr); | 77 free(ptr); |
76 } | 78 } |
77 | 79 |
78 char * | 80 char * |
79 dostrdup(const char *s) | 81 dostrdup(const char *s) |
123 memcpy(ret, s, len); | 125 memcpy(ret, s, len); |
124 ret[len] = '\0'; | 126 ret[len] = '\0'; |
125 return ret; | 127 return ret; |
126 } | 128 } |
127 | 129 |
130 void | |
131 dostrfree(char *s) | |
132 { | |
133 dofree(s, strlen(s)+1); | |
134 } | |
135 | |
128 size_t | 136 size_t |
129 notrailingws(char *buf, size_t len) | 137 notrailingws(char *buf, size_t len) |
130 { | 138 { |
131 while (len > 0 && strchr(ws, buf[len-1])) { | 139 while (len > 0 && strchr(ws, buf[len-1])) { |
132 buf[--len] = '\0'; | 140 buf[--len] = '\0'; |