Mercurial > hg > batmud > maputils
changeset 60:de4a41a61e8c
Updated th-libs
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 15 Dec 2006 04:33:53 +0000 |
parents | f04f72724bb3 |
children | 4efae5dae2e3 |
files | th_string.c th_types.h |
diffstat | 2 files changed, 17 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/th_string.c Fri Dec 15 01:20:16 2006 +0000 +++ b/th_string.c Fri Dec 15 04:33:53 2006 +0000 @@ -13,14 +13,14 @@ /* Allocate memory for a string with given length */ -char_t *th_stralloc(size_t l) +char_t *th_stralloc(const size_t l) { assert(l > 0); return th_malloc(sizeof(char_t) * l); } -char_t *th_strrealloc(char_t * s, size_t l) +char_t *th_strrealloc(char_t * s, const size_t l) { assert(l > 0); return th_realloc(s, sizeof(char_t) * l); @@ -33,6 +33,7 @@ { size_t l = 0; char_t *s = pStr; + assert(pStr); while (*s) { s++; @@ -48,8 +49,9 @@ char_t *th_strdup(char_t * pStr) { char_t *pResult, *s, *d; - assert(pStr); + if (!pStr) return NULL; + /* Allocate memory for destination */ pResult = th_stralloc(th_strlen(pStr) + 1); if (!pResult) @@ -72,17 +74,15 @@ char_t *th_strcat(char_t * pDest, char_t * pSource) { char_t *s, *d; - - /* Check the string pointers */ - if (!pSource || !pDest) - return pDest; + assert(pSource); + assert(pDest); /* Copy to the destination */ s = pSource; d = pDest; - while (*d) - d++; + while (*d) d++; + while (*s) { *(d++) = *(s++); } @@ -97,10 +97,8 @@ char_t *th_strcpy(char_t * pDest, char_t * pSource) { char_t *s, *d; - - /* Check the string pointers */ - if (!pSource || !pDest) - return pDest; + assert(pSource); + assert(pDest); /* Copy to the destination */ s = pSource; @@ -119,10 +117,8 @@ { char_t *s, *d; size_t i; - - /* Check the string pointers */ - if (!pSource || !pDest) - return pDest; + assert(pSource); + assert(pDest); /* Copy to the destination */ i = n; @@ -285,6 +281,7 @@ /* Find possible start of 'needle' */ while (*h && (*h != *n)) h++; + if (*h == *n) { /* Found, check rest */ s = h; @@ -292,7 +289,8 @@ while (*h) { if (!*n) return s; - else if (*h != *n) + else + if (*h != *n) break; n++; h++;