From: Waldemar Kozaczuk <[email protected]>
Committer: Nadav Har'El <[email protected]>
Branch: master

libc: remove more string functions from libc/ in favor of the original musl ones

Just like the last two other libc related patches, this patch
also eliminates 7 more source files from libc/string/
in favor of the equivalent ones in musl/src/string/.

In this case those 7 files differed only like in this example:
```
diff musl/src/string/strchrnul.c libc/string/strchrnul.c
10c10
< #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
Message-Id: <[email protected]>

---
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# O./libc/string/strdup.cSv makefile
+# OSv makefile
 #
 # Copyright (C) 2015 Cloudius Systems, Ltd.
 # This work is open source software, licensed under the terms of the
@@ -1556,8 +1556,8 @@ musl += string/bcmp.o
 musl += string/bcopy.o
 musl += string/bzero.o
 musl += string/index.o
-libc += string/memccpy.o
-libc += string/memchr.o
+musl += string/memccpy.o
+musl += string/memchr.o
 musl += string/memcmp.o
 libc += string/memcpy.o
 musl += string/memmem.o
@@ -1569,24 +1569,24 @@ libc += string/memset.o
 libc += string/__memset_chk.o
 libc += string/rawmemchr.o
 musl += string/rindex.o
-libc += string/stpcpy.o
+musl += string/stpcpy.o
 libc += string/__stpcpy_chk.o
-libc += string/stpncpy.o
+musl += string/stpncpy.o
 musl += string/strcasecmp.o
 musl += string/strcasestr.o
 musl += string/strcat.o
 libc += string/__strcat_chk.o
 musl += string/strchr.o
-libc += string/strchrnul.o
+musl += string/strchrnul.o
 musl += string/strcmp.o
 musl += string/strcpy.o
 libc += string/__strcpy_chk.o
 musl += string/strcspn.o
 musl += string/strdup.o
 libc += string/strerror_r.o
 libc += string/strlcat.o
-libc += string/strlcpy.o
-libc += string/strlen.o
+musl += string/strlcpy.o
+musl += string/strlen.o
 musl += string/strncasecmp.o
 musl += string/strncat.o
 libc += string/__strncat_chk.o
diff --git a/libc/string/memccpy.c b/libc/string/memccpy.c
--- a/libc/string/memccpy.c
+++ b/libc/string/memccpy.c
@@ -1,32 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <limits.h>
-
-#define ALIGN (sizeof(size_t)-1)
-#define ONES ((size_t)-1/UCHAR_MAX)
-#define HIGHS (ONES * (UCHAR_MAX/2+1))
-#define HASZERO(x) (((x)-ONES) & ~(x) & HIGHS)
-
-void *memccpy(void *__restrict dest, const void *__restrict src, int c, size_t 
n)
-{
-       unsigned char *d = dest;
-       const unsigned char *s = src;
-       size_t *wd, k;
-       const size_t *ws;
-
-       c = (unsigned char)c;
-       if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) {
-               for (; ((uintptr_t)s & ALIGN) && n && (*d=*s)!=c; n--, s++, 
d++);
-               if ((uintptr_t)s & ALIGN) goto tail;
-               k = ONES * c;
-               wd=(void *)d; ws=(const void *)s;
-               for (; n>=sizeof(size_t) && !HASZERO(*ws^k);
-                      n-=sizeof(size_t), ws++, wd++) *wd = *ws;
-               d=(void *)wd; s=(const void *)ws;
-       }
-       for (; n && (*d=*s)!=c; n--, s++, d++);
-tail:
-       if (*s==c) return d+1;
-       return 0;
-}
diff --git a/libc/string/memchr.c b/libc/string/memchr.c
--- a/libc/string/memchr.c
+++ b/libc/string/memchr.c
@@ -1,24 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <limits.h>
-
-#define SS (sizeof(size_t))
-#define ALIGN (sizeof(size_t)-1)
-#define ONES ((size_t)-1/UCHAR_MAX)
-#define HIGHS (ONES * (UCHAR_MAX/2+1))
-#define HASZERO(x) (((x)-ONES) & ~(x) & HIGHS)
-
-void *memchr(const void *src, int c, size_t n)
-{
-       const unsigned char *s = src;
-       c = (unsigned char)c;
-       for (; ((uintptr_t)s & ALIGN) && n && *s != c; s++, n--);
-       if (n && *s != c) {
-               const size_t *w;
-               size_t k = ONES * c;
-               for (w = (const void *)s; n>=SS && !HASZERO(*w^k); w++, n-=SS);
-               for (s = (const void *)w; n && *s != c; s++, n--);
-       }
-       return n ? (void *)s : 0;
-}
diff --git a/libc/string/stpcpy.c b/libc/string/stpcpy.c
--- a/libc/string/stpcpy.c
+++ b/libc/string/stpcpy.c
@@ -1,29 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <limits.h>
-#include "libc.h"
-
-#define ALIGN (sizeof(size_t))
-#define ONES ((size_t)-1/UCHAR_MAX)
-#define HIGHS (ONES * (UCHAR_MAX/2+1))
-#define HASZERO(x) (((x)-ONES) & ~(x) & HIGHS)
-
-char *__stpcpy(char *__restrict d, const char *__restrict s)
-{
-       size_t *wd;
-       const size_t *ws;
-
-       if ((uintptr_t)s % ALIGN == (uintptr_t)d % ALIGN) {
-               for (; (uintptr_t)s % ALIGN; s++, d++)
-                       if (!(*d=*s)) return d;
-               wd=(void *)d; ws=(const void *)s;
-               for (; !HASZERO(*ws); *wd++ = *ws++);
-               d=(void *)wd; s=(const void *)ws;
-       }
-       for (; (*d=*s); s++, d++);
-
-       return d;
-}
-
-weak_alias(__stpcpy, stpcpy);
diff --git a/libc/string/stpncpy.c b/libc/string/stpncpy.c
--- a/libc/string/stpncpy.c
+++ b/libc/string/stpncpy.c
@@ -1,32 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <limits.h>
-#include "libc.h"
-
-#define ALIGN (sizeof(size_t)-1)
-#define ONES ((size_t)-1/UCHAR_MAX)
-#define HIGHS (ONES * (UCHAR_MAX/2+1))
-#define HASZERO(x) (((x)-ONES) & ~(x) & HIGHS)
-
-char *__stpncpy(char *__restrict d, const char *__restrict s, size_t n)
-{
-       size_t *wd;
-       const size_t *ws;
-
-       if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) {
-               for (; ((uintptr_t)s & ALIGN) && n && (*d=*s); n--, s++, d++);
-               if (!n || !*s) goto tail;
-               wd=(void *)d; ws=(const void *)s;
-               for (; n>=sizeof(size_t) && !HASZERO(*ws);
-                      n-=sizeof(size_t), ws++, wd++) *wd = *ws;
-               d=(void *)wd; s=(const void *)ws;
-       }
-       for (; n && (*d=*s); n--, s++, d++);
-tail:
-       memset(d, 0, n);
-       return d;
-}
-
-weak_alias(__stpncpy, stpncpy);
-
diff --git a/libc/string/strchrnul.c b/libc/string/strchrnul.c
--- a/libc/string/strchrnul.c
+++ b/libc/string/strchrnul.c
@@ -1,27 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <limits.h>
-#include "libc.h"
-
-#define ALIGN (sizeof(size_t))
-#define ONES ((size_t)-1/UCHAR_MAX)
-#define HIGHS (ONES * (UCHAR_MAX/2+1))
-#define HASZERO(x) (((x)-ONES) & ~(x) & HIGHS)
-
-char *__strchrnul(const char *s, int c)
-{
-       size_t *w, k;
-
-       c = (unsigned char)c;
-       if (!c) return (char *)s + strlen(s);
-
-       for (; (uintptr_t)s % ALIGN; s++)
-               if (!*s || *(unsigned char *)s == c) return (char *)s;
-       k = ONES * c;
-       for (w = (void *)s; !HASZERO(*w) && !HASZERO(*w^k); w++);
-       for (s = (void *)w; *s && *(unsigned char *)s != c; s++);
-       return (char *)s;
-}
-
-weak_alias(__strchrnul, strchrnul);
diff --git a/libc/string/strlcpy.c b/libc/string/strlcpy.c
--- a/libc/string/strlcpy.c
+++ b/libc/string/strlcpy.c
@@ -1,32 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <limits.h>
-#include "libc.h"
-
-#define ALIGN (sizeof(size_t)-1)
-#define ONES ((size_t)-1/UCHAR_MAX)
-#define HIGHS (ONES * (UCHAR_MAX/2+1))
-#define HASZERO(x) (((x)-ONES) & ~(x) & HIGHS)
-
-size_t strlcpy(char *d, const char *s, size_t n)
-{
-       char *d0 = d;
-       size_t *wd;
-       const size_t *ws;
-
-       if (!n--) goto finish;
-       if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) {
-               for (; ((uintptr_t)s & ALIGN) && n && (*d=*s); n--, s++, d++);
-               if (n && *s) {
-                       wd=(void *)d; ws=(const void *)s;
-                       for (; n>=sizeof(size_t) && !HASZERO(*ws);
-                              n-=sizeof(size_t), ws++, wd++) *wd = *ws;
-                       d=(void *)wd; s=(const void *)ws;
-               }
-       }
-       for (; n && (*d=*s); n--, s++, d++);
-       *d = 0;
-finish:
-       return d-d0 + strlen(s);
-}
diff --git a/libc/string/strlen.c b/libc/string/strlen.c
--- a/libc/string/strlen.c
+++ b/libc/string/strlen.c
@@ -1,19 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <limits.h>
-
-#define ALIGN (sizeof(size_t))
-#define ONES ((size_t)-1/UCHAR_MAX)
-#define HIGHS (ONES * (UCHAR_MAX/2+1))
-#define HASZERO(x) (((x)-ONES) & ~(x) & HIGHS)
-
-size_t strlen(const char *s)
-{
-       const char *a = s;
-       const size_t *w;
-       for (; (uintptr_t)s % ALIGN; s++) if (!*s) return s-a;
-       for (w = (const void *)s; !HASZERO(*w); w++);
-       for (s = (const void *)w; *s; s++);
-       return s-a;
-}

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/00000000000045ea3b05ab90ae0d%40google.com.

Reply via email to