diff options
author | William Harrington <kb0iic@berzerkula.org> | 2025-01-14 16:06:02 -0600 |
---|---|---|
committer | William Harrington <kb0iic@berzerkula.org> | 2025-01-14 16:06:02 -0600 |
commit | 0cc9b20c15460213e488bf5e70963b941482f628 (patch) | |
tree | bb0143245583ec846630f39bfa2258dba640ccd7 /sdk/std/string.c | |
parent | 0e084ade5069756d487b5c948c48b777e37c00c9 (diff) |
Add source.
Diffstat (limited to 'sdk/std/string.c')
-rw-r--r-- | sdk/std/string.c | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/sdk/std/string.c b/sdk/std/string.c new file mode 100644 index 0000000..6f9649e --- /dev/null +++ b/sdk/std/string.c @@ -0,0 +1,110 @@ +/* + * Define constants used by other string services and case insensitive + * compare and conversion functions missing in some libc distributions. + * $Id$ + * Copyright (c) 1997 by Tycho Softworks. + * For conditions of distribution and reuse see product license. + */ + +#include <std/string.h> + +#ifdef STRLWR_F_MISSING + +char *strlwr(char *s) +{ + char *old; + + if(!s) + return NULL; + + old=s; + while(*s = (char)tolower(*s)) + ++s; + + return old; +} + +char *strupr(char *s) +{ + char *old; + + if(!s) + return NULL; + + old=s; + while(*s = (char)toupper(*s)) + ++s; + return old; +} + +#endif + +#ifdef STRDUP_F_MISSING + +char *strdup(str) +char *str; +{ + char *new = (char *)malloc(strlen(str) + 1); + if(!new) + return NULL; + + return strcpy(new, str); +} + +#endif + +#ifdef STRICMP_F_MISSING + +int stricmp(const char *s1, const char *s2) +{ + int t; + + while(*s1 && *s2) + { + if (t=tolower(*s1)-tolower(*s2)) + return t; + + ++s1; + ++s2; + } + return tolower(*s1)-tolower(*s2); +} + +int strnicmp(const char *s1,const char *s2, size_t n) +{ + int t; + + while (n--) + { + if (t=tolower(*s1)-tolower(*s2)) + return t; + + if (!*s1) + return 0; + + ++s1; + ++s2; + } + return 0; +} + +#endif + +#ifdef STRISTR_F_MISSING + +char *stristr(char *s1, const char *s2) +{ + int len = strlen(s2); + int count = strlen(s1) - len + 1; + + while(count--) + { + if(!strnicmp(s1, s2, len)) + return s1; + ++s1; + } + return NULL; +} + +#endif + |