aboutsummaryrefslogtreecommitdiff
path: root/lib_generic
diff options
context:
space:
mode:
Diffstat (limited to 'lib_generic')
-rw-r--r--lib_generic/string.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib_generic/string.c b/lib_generic/string.c
index d06a64501..5ba8d7cb5 100644
--- a/lib_generic/string.c
+++ b/lib_generic/string.c
@@ -364,6 +364,33 @@ char * strsep(char **s, const char *ct)
}
#endif
+#ifndef __HAVE_ARCH_STRSWAB
+/**
+ * strswab - swap adjacent even and odd bytes in %NUL-terminated string
+ * s: address of the string
+ *
+ * returns the address of the swapped string or NULL on error. If
+ * string length is odd, last byte is untouched.
+ */
+char *strswab(const char *s)
+{
+ char *p;
+
+ if ((NULL == s) || ('\0' == *s)) {
+ return (NULL);
+ }
+
+ for (p = ((char *)s + 1); '\0' != *p; p += 2) {
+ char tmp;
+ tmp = *(p-1);
+ *(p-1) = *p;
+ *p = tmp;
+ }
+
+ return (char *) s;
+}
+#endif
+
#ifndef __HAVE_ARCH_MEMSET
/**
* memset - Fill a region of memory with the given value