91 |
|
mapping_t *map_end_ptr; |
92 |
|
|
93 |
|
if (mapping == NULL){ |
94 |
< |
mapping = malloc(sizeof(mapping_t)); |
94 |
> |
mapping = sg_malloc(sizeof(mapping_t)); |
95 |
|
if (mapping == NULL) return; |
96 |
|
map_ptr = mapping; |
97 |
|
}else{ |
106 |
|
/* We've reached end of list and not found the entry.. So we need to malloc |
107 |
|
* new mapping_t |
108 |
|
*/ |
109 |
< |
map_end_ptr->next = malloc(sizeof(mapping_t)); |
109 |
> |
map_end_ptr->next = sg_malloc(sizeof(mapping_t)); |
110 |
|
if (map_end_ptr->next == NULL) return; |
111 |
|
map_ptr = map_end_ptr->next; |
112 |
|
} |
155 |
|
file_name[x] = '\0'; |
156 |
|
if (strcmp(file_name, temp_name) == 0) { |
157 |
|
if (sg_update_string(&svr_name, |
158 |
< |
dp->d_name) < 0) { |
158 |
> |
dp->d_name) < 0) { |
159 |
|
return NULL; |
160 |
|
} |
161 |
|
closedir(dirp); |
283 |
|
|
284 |
|
char *sg_get_string_match(char *line, regmatch_t *match){ |
285 |
|
int len=match->rm_eo - match->rm_so; |
286 |
< |
char *match_string=malloc(len+1); |
286 |
> |
char *match_string=sg_malloc(len+1); |
287 |
|
|
288 |
|
match_string=strncpy(match_string, line+match->rm_so, len); |
289 |
|
match_string[len]='\0'; |
337 |
|
* Returns strlen(src); if retval >= siz, truncation occurred. |
338 |
|
*/ |
339 |
|
size_t sg_strlcpy(char *dst, const char *src, size_t siz){ |
340 |
< |
register char *d = dst; |
341 |
< |
register const char *s = src; |
342 |
< |
register size_t n = siz; |
340 |
> |
register char *d = dst; |
341 |
> |
register const char *s = src; |
342 |
> |
register size_t n = siz; |
343 |
|
|
344 |
< |
/* Copy as many bytes as will fit */ |
345 |
< |
if (n != 0 && --n != 0) { |
346 |
< |
do { |
347 |
< |
if ((*d++ = *s++) == 0) |
348 |
< |
break; |
349 |
< |
} while (--n != 0); |
350 |
< |
} |
344 |
> |
/* Copy as many bytes as will fit */ |
345 |
> |
if (n != 0 && --n != 0) { |
346 |
> |
do { |
347 |
> |
if ((*d++ = *s++) == 0) |
348 |
> |
break; |
349 |
> |
} while (--n != 0); |
350 |
> |
} |
351 |
|
|
352 |
< |
/* Not enough room in dst, add NUL and traverse rest of src */ |
353 |
< |
if (n == 0) { |
354 |
< |
if (siz != 0) |
355 |
< |
*d = '\0'; /* NUL-terminate dst */ |
356 |
< |
while (*s++) |
357 |
< |
; |
358 |
< |
} |
352 |
> |
/* Not enough room in dst, add NUL and traverse rest of src */ |
353 |
> |
if (n == 0) { |
354 |
> |
if (siz != 0) |
355 |
> |
*d = '\0'; /* NUL-terminate dst */ |
356 |
> |
while (*s++) |
357 |
> |
; |
358 |
> |
} |
359 |
|
|
360 |
< |
return(s - src - 1); /* count does not include NUL */ |
360 |
> |
return(s - src - 1); /* count does not include NUL */ |
361 |
|
} |
362 |
|
|
363 |
|
/* $OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $ */ |
386 |
|
* If retval >= siz, truncation occurred. |
387 |
|
*/ |
388 |
|
size_t sg_strlcat(char *dst, const char *src, size_t siz){ |
389 |
< |
register char *d = dst; |
390 |
< |
register const char *s = src; |
391 |
< |
register size_t n = siz; |
392 |
< |
size_t dlen; |
389 |
> |
register char *d = dst; |
390 |
> |
register const char *s = src; |
391 |
> |
register size_t n = siz; |
392 |
> |
size_t dlen; |
393 |
|
|
394 |
< |
/* Find the end of dst and adjust bytes left but don't go past end */ |
395 |
< |
while (n-- != 0 && *d != '\0') |
396 |
< |
d++; |
397 |
< |
dlen = d - dst; |
398 |
< |
n = siz - dlen; |
394 |
> |
/* Find the end of dst and adjust bytes left but don't go past end */ |
395 |
> |
while (n-- != 0 && *d != '\0') |
396 |
> |
d++; |
397 |
> |
dlen = d - dst; |
398 |
> |
n = siz - dlen; |
399 |
|
|
400 |
< |
if (n == 0) |
401 |
< |
return(dlen + strlen(s)); |
402 |
< |
while (*s != '\0') { |
403 |
< |
if (n != 1) { |
404 |
< |
*d++ = *s; |
405 |
< |
n--; |
406 |
< |
} |
407 |
< |
s++; |
408 |
< |
} |
409 |
< |
*d = '\0'; |
400 |
> |
if (n == 0) |
401 |
> |
return(dlen + strlen(s)); |
402 |
> |
while (*s != '\0') { |
403 |
> |
if (n != 1) { |
404 |
> |
*d++ = *s; |
405 |
> |
n--; |
406 |
> |
} |
407 |
> |
s++; |
408 |
> |
} |
409 |
> |
*d = '\0'; |
410 |
|
|
411 |
< |
return(dlen + (s - src)); /* count does not include NUL */ |
411 |
> |
return(dlen + (s - src)); /* count does not include NUL */ |
412 |
|
} |
413 |
|
|
414 |
|
int sg_update_string(char **dest, const char *src) { |
421 |
|
return 0; |
422 |
|
} |
423 |
|
|
424 |
< |
new = realloc(*dest, strlen(src) + 1); |
424 |
> |
new = sg_realloc(*dest, strlen(src) + 1); |
425 |
|
if (new == NULL) { |
426 |
|
return -1; |
427 |
|
} |