Apparently some of the network and string functions are implemented
using macros in glibc and it seems that OSv used to depend on
the glibc headers (maybe) and the commit 
0ac3dd155ac0a8f4606fcb9abf3c7785da395214 by Avi Kivity
modified those files to #undef those functions.

It looks like we do not have to do it anymore so this patch
simply removes those files from libc/ folder and changes
Makefile to point back to the musl equivalent ones.

Signed-off-by: Waldemar Kozaczuk <[email protected]>
---
 Makefile              | 26 +++++++++++++-------------
 libc/network/htonl.c  |  9 ---------
 libc/network/htons.c  |  9 ---------
 libc/network/ntohl.c  |  9 ---------
 libc/network/ntohs.c  |  9 ---------
 libc/string/strchr.c  | 10 ----------
 libc/string/strcmp.c  |  8 --------
 libc/string/strcspn.c | 20 --------------------
 libc/string/strdup.c  | 14 --------------
 libc/string/strncmp.c | 10 ----------
 libc/string/strpbrk.c |  8 --------
 libc/string/strsep.c  | 14 --------------
 libc/string/strspn.c  | 21 ---------------------
 13 files changed, 13 insertions(+), 154 deletions(-)
 delete mode 100644 libc/network/htonl.c
 delete mode 100644 libc/network/htons.c
 delete mode 100644 libc/network/ntohl.c
 delete mode 100644 libc/network/ntohs.c
 delete mode 100644 libc/string/strchr.c
 delete mode 100644 libc/string/strcmp.c
 delete mode 100644 libc/string/strcspn.c
 delete mode 100644 libc/string/strdup.c
 delete mode 100644 libc/string/strncmp.c
 delete mode 100644 libc/string/strpbrk.c
 delete mode 100644 libc/string/strsep.c
 delete mode 100644 libc/string/strspn.c

diff --git a/Makefile b/Makefile
index 0c0f665b..28f4f575 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# OSv makefile
+# O./libc/string/strdup.cSv makefile
 #
 # Copyright (C) 2015 Cloudius Systems, Ltd.
 # This work is open source software, licensed under the terms of the
@@ -1344,10 +1344,10 @@ musl += multibyte/wctomb.o
 
 $(out)/libc/multibyte/mbsrtowcs.o: CFLAGS += -Imusl/src/multibyte
 
-libc += network/htonl.o
-libc += network/htons.o
-libc += network/ntohl.o
-libc += network/ntohs.o
+musl += network/htonl.o
+musl += network/htons.o
+musl += network/ntohl.o
+musl += network/ntohs.o
 libc += network/gethostbyname_r.o
 musl += network/gethostbyname2_r.o
 musl += network/gethostbyaddr_r.o
@@ -1576,13 +1576,13 @@ musl += string/strcasecmp.o
 musl += string/strcasestr.o
 libc += string/strcat.o
 libc += string/__strcat_chk.o
-libc += string/strchr.o
+musl += string/strchr.o
 libc += string/strchrnul.o
-libc += string/strcmp.o
+musl += string/strcmp.o
 libc += string/strcpy.o
 libc += string/__strcpy_chk.o
-libc += string/strcspn.o
-libc += string/strdup.o
+musl += string/strcspn.o
+musl += string/strdup.o
 libc += string/strerror_r.o
 libc += string/strlcat.o
 libc += string/strlcpy.o
@@ -1590,18 +1590,18 @@ libc += string/strlen.o
 musl += string/strncasecmp.o
 libc += string/strncat.o
 libc += string/__strncat_chk.o
-libc += string/strncmp.o
+musl += string/strncmp.o
 libc += string/strncpy.o
 libc += string/__strncpy_chk.o
 libc += string/__strndup.o
 musl += string/strndup.o
 musl += string/strnlen.o
-libc += string/strpbrk.o
+musl += string/strpbrk.o
 musl += string/strrchr.o
-libc += string/strsep.o
+musl += string/strsep.o
 libc += string/stresep.o
 libc += string/strsignal.o
-libc += string/strspn.o
+musl += string/strspn.o
 musl += string/strstr.o
 libc += string/strtok.o
 libc += string/strtok_r.o
diff --git a/libc/network/htonl.c b/libc/network/htonl.c
deleted file mode 100644
index cd8fb684..00000000
--- a/libc/network/htonl.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <netinet/in.h>
-#include <byteswap.h>
-
-#undef htonl
-uint32_t htonl(uint32_t n)
-{
-       union { int i; char c; } u = { 1 };
-       return u.c ? bswap_32(n) : n;
-}
diff --git a/libc/network/htons.c b/libc/network/htons.c
deleted file mode 100644
index 99a064b0..00000000
--- a/libc/network/htons.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <netinet/in.h>
-#include <byteswap.h>
-
-#undef htons
-uint16_t htons(uint16_t n)
-{
-       union { int i; char c; } u = { 1 };
-       return u.c ? bswap_16(n) : n;
-}
diff --git a/libc/network/ntohl.c b/libc/network/ntohl.c
deleted file mode 100644
index 0e5b4ea8..00000000
--- a/libc/network/ntohl.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <netinet/in.h>
-#include <byteswap.h>
-
-#undef ntohl
-uint32_t ntohl(uint32_t n)
-{
-       union { int i; char c; } u = { 1 };
-       return u.c ? bswap_32(n) : n;
-}
diff --git a/libc/network/ntohs.c b/libc/network/ntohs.c
deleted file mode 100644
index 745fe737..00000000
--- a/libc/network/ntohs.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <netinet/in.h>
-#include <byteswap.h>
-
-#undef ntohs
-uint16_t ntohs(uint16_t n)
-{
-       union { int i; char c; } u = { 1 };
-       return u.c ? bswap_16(n) : n;
-}
diff --git a/libc/string/strchr.c b/libc/string/strchr.c
deleted file mode 100644
index fde21673..00000000
--- a/libc/string/strchr.c
+++ /dev/null
@@ -1,10 +0,0 @@
-#include <string.h>
-
-char *__strchrnul(const char *, int);
-
-#undef strchr
-char *strchr(const char *s, int c)
-{
-       char *r = __strchrnul(s, c);
-       return *(unsigned char *)r == (unsigned char)c ? r : 0;
-}
diff --git a/libc/string/strcmp.c b/libc/string/strcmp.c
deleted file mode 100644
index a4a4b623..00000000
--- a/libc/string/strcmp.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <string.h>
-
-#undef strcmp
-int strcmp(const char *l, const char *r)
-{
-       for (; *l==*r && *l && *r; l++, r++);
-       return *(unsigned char *)l - *(unsigned char *)r;
-}
diff --git a/libc/string/strcspn.c b/libc/string/strcspn.c
deleted file mode 100644
index bcb9dc77..00000000
--- a/libc/string/strcspn.c
+++ /dev/null
@@ -1,20 +0,0 @@
-#include <string.h>
-
-#define BITOP(a,b,op) \
- ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a))))
-
-char *__strchrnul(const char *, int);
-
-#undef strcspn
-size_t strcspn(const char *s, const char *c)
-{
-       const char *a = s;
-       size_t byteset[32/sizeof(size_t)];
-
-       if (!c[0] || !c[1]) return __strchrnul(s, *c)-a;
-
-       memset(byteset, 0, sizeof byteset);
-       for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++);
-       for (; *s && !BITOP(byteset, *(unsigned char *)s, &); s++);
-       return s-a;
-}
diff --git a/libc/string/strdup.c b/libc/string/strdup.c
deleted file mode 100644
index ca6a36c7..00000000
--- a/libc/string/strdup.c
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include "libc.h"
-
-#undef __strdup
-char *__strdup(const char *s)
-{
-       size_t l = strlen(s);
-       char *d = malloc(l+1);
-       if (!d) return NULL;
-       return memcpy(d, s, l+1);
-}
-
-weak_alias(__strdup, strdup);
diff --git a/libc/string/strncmp.c b/libc/string/strncmp.c
deleted file mode 100644
index f1de1539..00000000
--- a/libc/string/strncmp.c
+++ /dev/null
@@ -1,10 +0,0 @@
-#include <string.h>
-
-#undef strncmp
-int strncmp(const char *_l, const char *_r, size_t n)
-{
-       const unsigned char *l=(void *)_l, *r=(void *)_r;
-       if (!n--) return 0;
-       for (; *l && *r && n && *l == *r ; l++, r++, n--);
-       return *l - *r;
-}
diff --git a/libc/string/strpbrk.c b/libc/string/strpbrk.c
deleted file mode 100644
index b194ff1d..00000000
--- a/libc/string/strpbrk.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <string.h>
-
-#undef strpbrk
-char *strpbrk(const char *s, const char *b)
-{
-       s += strcspn(s, b);
-       return *s ? (char *)s : 0;
-}
diff --git a/libc/string/strsep.c b/libc/string/strsep.c
deleted file mode 100644
index b64557c4..00000000
--- a/libc/string/strsep.c
+++ /dev/null
@@ -1,14 +0,0 @@
-#define _GNU_SOURCE
-#include <string.h>
-
-#undef strsep
-char *strsep(char **str, const char *sep)
-{
-       char *s = *str, *end;
-       if (!s) return NULL;
-       end = s + strcspn(s, sep);
-       if (*end) *end++ = 0;
-       else end = 0;
-       *str = end;
-       return s;
-}
diff --git a/libc/string/strspn.c b/libc/string/strspn.c
deleted file mode 100644
index 10d2c9f0..00000000
--- a/libc/string/strspn.c
+++ /dev/null
@@ -1,21 +0,0 @@
-#include <string.h>
-
-#define BITOP(a,b,op) \
- ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a))))
-
-#undef strspn
-size_t strspn(const char *s, const char *c)
-{
-       const char *a = s;
-       size_t byteset[32/sizeof(size_t)] = { 0 };
-
-       if (!c[0]) return 0;
-       if (!c[1]) {
-               for (; *s == *c; s++);
-               return s-a;
-       }
-
-       for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++);
-       for (; *s && BITOP(byteset, *(unsigned char *)s, &); s++);
-       return s-a;
-}
-- 
2.25.1

-- 
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/20200727164350.10609-1-jwkozaczuk%40gmail.com.

Reply via email to