summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2006-01-28 00:14:29 +0000
committerStef Walter <stef@memberwebs.com>2006-01-28 00:14:29 +0000
commitae2e52d578ca1dd78e31beed4c63a9b17ce3bb60 (patch)
tree44d35afcaf247ed6df2b1a7203aaf6bf9277261c /common
parent987a76bee76417887bd8d09f743691dbd3872f7d (diff)
First stage of standardizing string functions.
Diffstat (limited to 'common')
-rw-r--r--common/stringx.c54
-rw-r--r--common/stringx.h33
2 files changed, 66 insertions, 21 deletions
diff --git a/common/stringx.c b/common/stringx.c
index 37a3df9..3705cb9 100644
--- a/common/stringx.c
+++ b/common/stringx.c
@@ -45,15 +45,17 @@
#include <strings.h>
#include "usuals.h"
-#include "stringx.h"
+#include "compat.h"
+
+#ifndef HAVE_STRCLN
void
-remove_cr(char* data)
+strcln(char* data, char ch)
{
char* p;
for(p = data; *data; data++, p++)
{
- while(*data == '\r')
+ while(*data == ch)
data++;
*p = *data;
}
@@ -62,16 +64,24 @@ remove_cr(char* data)
*p = 0;
}
+#endif /* HAVE_STRCLN */
+
+#ifndef HAVE_STRBTRIM
+
char*
-trim_start(const char* data)
+strbtrim(const char* data)
{
while(*data && isspace(*data))
++data;
return (char*)data;
}
+#endif /* HAVE_STRBTRIM */
+
+#ifndef HAVE_STRETRIM
+
void
-trim_end(char* data)
+stretrim(char* data)
{
char* t = data + strlen(data);
while(t > data && isspace(*(t - 1)))
@@ -81,16 +91,24 @@ trim_end(char* data)
}
}
+#endif /* HAVE_STRETRIM */
+
+#ifndef HAVE_STRTRIM
+
char*
-trim_space(char* data)
+strtrim(char* data)
{
data = (char*)trim_start(data);
trim_end(data);
return data;
}
-/* String to bool helper function */
-int strtob(const char* str)
+#endif /* HAVE_STRTRIM */
+
+#ifndef HAVE_STRTOB
+
+int
+strtob(const char* str)
{
if(strcasecmp(str, "0") == 0 ||
strcasecmp(str, "no") == 0 ||
@@ -109,6 +127,11 @@ int strtob(const char* str)
return -1;
}
+#endif /* HAVE_STRTOB */
+
+
+#ifndef HAVE_STRLCPY
+
size_t
strlcpy(char *dst, const char *src, size_t len)
{
@@ -123,19 +146,22 @@ strlcpy(char *dst, const char *src, size_t len)
return (ret);
}
-size_t strlcat(char* dst, const char* src, size_t siz)
+#endif /* HAVE_STRLCPY */
+
+#ifndef HAVE_STRLCAT
+
+size_t
+strlcat(char* dst, const char* src, size_t siz)
{
char* d = dst;
const char* s = src;
size_t n = siz;
size_t dlen;
- /* Find the end of dst and adjust bytes left but don't go past end */
while(n-- != 0 && *d != '\0')
- d++;
+ d++;
dlen = d - dst;
n = siz - dlen;
-
if(n == 0)
return dlen + strlen(s);
while(*s != '\0')
@@ -148,8 +174,8 @@ size_t strlcat(char* dst, const char* src, size_t siz)
s++;
}
-
*d = '\0';
-
return dlen + (s - src); /* count does not include NUL */
}
+
+#endif /* HAVE_STRLCAT */
diff --git a/common/stringx.h b/common/stringx.h
index 042cf2d..3949d70 100644
--- a/common/stringx.h
+++ b/common/stringx.h
@@ -36,18 +36,37 @@
*
*/
-#ifndef __STRINGX_H__
-#define __STRINGX_H__
+#ifndef __COMPAT_H__
+#define __COMPAT_H__
-void remove_cr(char* data);
+#include "config.h"
+#ifndef HAVE_STRLCPY
+size_t strlcpy(char *dst, const char *src, size_t len);
+#endif
+
+#ifndef HAVE_STRLCAT
+size_t strlcat(char* dst, const char* src, size_t siz);
+#endif
+
+#ifndef HAVE_STRCLN
+void strcln(char* data);
+#endif
+
+#ifndef HAVE_STRBTRIM
char* trim_start(const char* data);
+#endif
+
+#ifndef HAVE_STRETRIM
void trim_end(char* data);
+#endif
+
+#ifndef HAVE_STRTRIM
char* trim_space(char* data);
+#endif
+#ifndef HAVE_STRTOB
int strtob(const char* str);
+#endif
-size_t
-strlcpy(char *dst, const char *src, size_t len);
-
-#endif /* __STRINGX_H__ */
+#endif /* __COMPAT_H__ */