summaryrefslogtreecommitdiff
path: root/common/compat.c
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2004-07-08 18:27:54 +0000
committerStef Walter <stef@memberwebs.com>2004-07-08 18:27:54 +0000
commitac7e532095160a85ca03476aa707ef80a8a8ce5b (patch)
tree4e331300e5f11192869e66b9f08e58c4cf13cce3 /common/compat.c
parent17e2bbdacafb2c969d26a89ede3b57b60dc19bc1 (diff)
Initial import
Diffstat (limited to 'common/compat.c')
-rw-r--r--common/compat.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/common/compat.c b/common/compat.c
new file mode 100644
index 0000000..baf1e34
--- /dev/null
+++ b/common/compat.c
@@ -0,0 +1,77 @@
+
+#include "usuals.h"
+#include "compat.h"
+
+#ifndef HAVE_REALLOCF
+
+void* reallocf(void* ptr, size_t size)
+{
+ void* ret = realloc(ptr, size);
+
+ if(!ret && size)
+ free(ptr);
+
+ return ret;
+}
+
+#endif
+
+#ifndef HAVE_STRLWR
+char* strlwr(char* s)
+{
+ char* t = s;
+ while(*t)
+ {
+ *t = tolower(*t);
+ t++;
+ }
+ return s;
+}
+#endif
+
+#ifndef HAVE_STRUPR
+char* strupr(char* s)
+{
+ char* t = s;
+ while(*t)
+ {
+ *t = toupper(*t);
+ t++;
+ }
+ return s;
+}
+#endif
+
+#ifndef HAVE_STRLCPY
+
+#ifndef HAVE_STRNCPY
+#error neither strncpy or strlcpy found
+#endif
+
+void strlcpy(char* dest, const char* src, size_t count)
+{
+ if(count > 0)
+ {
+ strncpy(dest, src, count);
+ dest[count - 1] = 0;
+ }
+}
+#endif
+
+#ifndef HAVE_STRLCAT
+
+#ifndef HAVE_STRNCAT
+#error neither strncat or strlcat found
+#endif
+
+void strlcat(char* dest, const char* src, size_t count)
+{
+ if(count > 0)
+ {
+ strncat(dest, src, count);
+ dest[count - 1] = 0;
+ }
+}
+#endif
+
+