summaryrefslogtreecommitdiff
path: root/libgcompat/string.c
diff options
context:
space:
mode:
authorA. Wilcox <awilcox@wilcox-tech.com>2018-07-08 23:02:01 +0000
committerA. Wilcox <awilcox@wilcox-tech.com>2018-07-08 23:02:01 +0000
commit938c8095e7456fbcdf4ce261bdb6dfa3a8e41b80 (patch)
treef6e276f6f7fe732d106aa080f7a764e8c16fa3ab /libgcompat/string.c
parentb01b4ec70f3e4d4a4648207e414a8f9eef8073e9 (diff)
parent14db632212189df4fb3081d1c7345ca70bd1f6a5 (diff)
downloadgcompat-938c8095e7456fbcdf4ce261bdb6dfa3a8e41b80.tar.gz
gcompat-938c8095e7456fbcdf4ce261bdb6dfa3a8e41b80.tar.bz2
gcompat-938c8095e7456fbcdf4ce261bdb6dfa3a8e41b80.tar.xz
gcompat-938c8095e7456fbcdf4ce261bdb6dfa3a8e41b80.zip
Merge branch 'master' into 'master'
string: add memfrob and strfry This adds two missing glibc string functions. See merge request !2
Diffstat (limited to 'libgcompat/string.c')
-rw-r--r--libgcompat/string.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/libgcompat/string.c b/libgcompat/string.c
index 5a1e558..9f1704b 100644
--- a/libgcompat/string.c
+++ b/libgcompat/string.c
@@ -3,6 +3,9 @@
#include <stddef.h> /* NULL, size_t */
#include <stdint.h> /* SIZE_MAX */
#include <string.h> /* memcpy, strcpy, strncat, strndup */
+#include <stdlib.h> /* rand_r */
+#include <unistd.h> /* getpid */
+#include <time.h> /* time */
#include "alias.h" /* weak_alias */
@@ -262,3 +265,34 @@ char *__strtok_r(char *s, const char *delim, char **save_ptr)
{
return strtok_r(s, delim, save_ptr);
}
+
+void *memfrob(void *s, size_t n)
+{
+ unsigned char *c = s;
+
+ while (n--)
+ *c++ ^= 42;
+
+ return s;
+}
+
+char *strfry(char *s)
+{
+ static unsigned int seed;
+ size_t len = strlen(s), i, j;
+ char t;
+
+ if (!len)
+ return s;
+
+ seed += time(NULL) ^ getpid() ^ (uintptr_t)s;
+
+ for (i = 0; i < len - 1; ++i) {
+ j = rand_r(&seed) % (len - i) + i;
+ t = s[i];
+ s[i] = s[j];
+ s[j] = t;
+ }
+
+ return s;
+}