aboutsummaryrefslogtreecommitdiffstats
path: root/sdk/std/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'sdk/std/string.c')
-rw-r--r--sdk/std/string.c110
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
+