At some point in the beginning of OSv the musl sources were copied to libc/ folder and then gradually removed in favor of the original copies in musl/src/ folder.
This patch removes another 15 files from libc/string/ which only differred by "__restrict" vs "restrict" keyword. The original musl sources have "restrict" keyword and their corresponding copies have "__restrict" keyword even though per this commit log 5cd0168fc566e5f7263b04948b4df6695d8ae721 they seem to have been copied "as is" from musl. Based on what I have researched the __restrict keyword is a GCC extension and predates "restrict" and it happens to have same effect on pointer optimization as the latter one. We also compile all C source files with "-std=gnu99" option which adds GCC extensions to c99. So all in all I think we can drop the difference and simply point to the original musl sources. This patch further eliminates unnecessary files in libc/ folder. Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com> --- Makefile | 30 ++++++------ libc/string/strcat.c | 7 --- libc/string/strcpy.c | 16 ------- libc/string/strncat.c | 10 ---- libc/string/strncpy.c | 9 ---- libc/string/strtok.c | 13 ----- libc/string/swab.c | 13 ----- libc/string/wcpcpy.c | 6 --- libc/string/wcpncpy.c | 6 --- libc/string/wcscat.c | 7 --- libc/string/wcscpy.c | 8 ---- libc/string/wcsncat.c | 10 ---- libc/string/wcsncpy.c | 9 ---- libc/string/wcsstr.c | 108 ------------------------------------------ libc/string/wcstok.c | 12 ----- libc/string/wmemcpy.c | 9 ---- 16 files changed, 15 insertions(+), 258 deletions(-) delete mode 100644 libc/string/strcat.c delete mode 100644 libc/string/strcpy.c delete mode 100644 libc/string/strncat.c delete mode 100644 libc/string/strncpy.c delete mode 100644 libc/string/strtok.c delete mode 100644 libc/string/swab.c delete mode 100644 libc/string/wcpcpy.c delete mode 100644 libc/string/wcpncpy.c delete mode 100644 libc/string/wcscat.c delete mode 100644 libc/string/wcscpy.c delete mode 100644 libc/string/wcsncat.c delete mode 100644 libc/string/wcsncpy.c delete mode 100644 libc/string/wcsstr.c delete mode 100644 libc/string/wcstok.c delete mode 100644 libc/string/wmemcpy.c diff --git a/Makefile b/Makefile index 28f4f575..7c7c0489 100644 --- a/Makefile +++ b/Makefile @@ -1574,12 +1574,12 @@ libc += string/__stpcpy_chk.o libc += string/stpncpy.o musl += string/strcasecmp.o musl += string/strcasestr.o -libc += string/strcat.o +musl += string/strcat.o libc += string/__strcat_chk.o musl += string/strchr.o libc += string/strchrnul.o musl += string/strcmp.o -libc += string/strcpy.o +musl += string/strcpy.o libc += string/__strcpy_chk.o musl += string/strcspn.o musl += string/strdup.o @@ -1588,10 +1588,10 @@ libc += string/strlcat.o libc += string/strlcpy.o libc += string/strlen.o musl += string/strncasecmp.o -libc += string/strncat.o +musl += string/strncat.o libc += string/__strncat_chk.o musl += string/strncmp.o -libc += string/strncpy.o +musl += string/strncpy.o libc += string/__strncpy_chk.o libc += string/__strndup.o musl += string/strndup.o @@ -1603,37 +1603,37 @@ libc += string/stresep.o libc += string/strsignal.o musl += string/strspn.o musl += string/strstr.o -libc += string/strtok.o +musl += string/strtok.o libc += string/strtok_r.o musl += string/strverscmp.o -libc += string/swab.o -libc += string/wcpcpy.o -libc += string/wcpncpy.o +musl += string/swab.o +musl += string/wcpcpy.o +musl += string/wcpncpy.o musl += string/wcscasecmp.o musl += string/wcscasecmp_l.o -libc += string/wcscat.o +musl += string/wcscat.o musl += string/wcschr.o musl += string/wcscmp.o -libc += string/wcscpy.o +musl += string/wcscpy.o libc += string/__wcscpy_chk.o musl += string/wcscspn.o musl += string/wcsdup.o musl += string/wcslen.o musl += string/wcsncasecmp.o musl += string/wcsncasecmp_l.o -libc += string/wcsncat.o +musl += string/wcsncat.o musl += string/wcsncmp.o -libc += string/wcsncpy.o +musl += string/wcsncpy.o musl += string/wcsnlen.o musl += string/wcspbrk.o musl += string/wcsrchr.o musl += string/wcsspn.o -libc += string/wcsstr.o -libc += string/wcstok.o +musl += string/wcsstr.o +musl += string/wcstok.o musl += string/wcswcs.o musl += string/wmemchr.o musl += string/wmemcmp.o -libc += string/wmemcpy.o +musl += string/wmemcpy.o musl += string/wmemmove.o musl += string/wmemset.o diff --git a/libc/string/strcat.c b/libc/string/strcat.c deleted file mode 100644 index 43b7e254..00000000 --- a/libc/string/strcat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <string.h> - -char *strcat(char *__restrict dest, const char *__restrict src) -{ - strcpy(dest + strlen(dest), src); - return dest; -} diff --git a/libc/string/strcpy.c b/libc/string/strcpy.c deleted file mode 100644 index 8488f6ee..00000000 --- a/libc/string/strcpy.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <string.h> - -char *__stpcpy(char *, const char *); - -char *strcpy(char *__restrict dest, const char *__restrict src) -{ -#if 1 - __stpcpy(dest, src); - return dest; -#else - const unsigned char *s = src; - unsigned char *d = dest; - while ((*d++ = *s++)); - return dest; -#endif -} diff --git a/libc/string/strncat.c b/libc/string/strncat.c deleted file mode 100644 index 6f8d8da8..00000000 --- a/libc/string/strncat.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <string.h> - -char *strncat(char *__restrict d, const char *__restrict s, size_t n) -{ - char *a = d; - d += strlen(d); - while (n && *s) n--, *d++ = *s++; - *d++ = 0; - return a; -} diff --git a/libc/string/strncpy.c b/libc/string/strncpy.c deleted file mode 100644 index f43d4d73..00000000 --- a/libc/string/strncpy.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <string.h> - -char *__stpncpy(char *, const char *, size_t); - -char *strncpy(char *__restrict d, const char *__restrict s, size_t n) -{ - __stpncpy(d, s, n); - return d; -} diff --git a/libc/string/strtok.c b/libc/string/strtok.c deleted file mode 100644 index e2205c09..00000000 --- a/libc/string/strtok.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <string.h> - -char *strtok(char *__restrict s, const char *__restrict sep) -{ - static char *p; - if (!s && !(s = p)) return NULL; - s += strspn(s, sep); - if (!*s) return p = 0; - p = s + strcspn(s, sep); - if (*p) *p++ = 0; - else p = 0; - return s; -} diff --git a/libc/string/swab.c b/libc/string/swab.c deleted file mode 100644 index a4c9286d..00000000 --- a/libc/string/swab.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <unistd.h> - -void swab(const void *__restrict _src, void *__restrict _dest, ssize_t n) -{ - const char *src = _src; - char *dest = _dest; - for (; n>0; n-=2) { - dest[0] = src[1]; - dest[1] = src[0]; - dest += 2; - src += 2; - } -} diff --git a/libc/string/wcpcpy.c b/libc/string/wcpcpy.c deleted file mode 100644 index b1c20284..00000000 --- a/libc/string/wcpcpy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <wchar.h> - -wchar_t *wcpcpy(wchar_t *__restrict d, const wchar_t *__restrict s) -{ - return wcscpy(d, s) + wcslen(s); -} diff --git a/libc/string/wcpncpy.c b/libc/string/wcpncpy.c deleted file mode 100644 index f6d0add0..00000000 --- a/libc/string/wcpncpy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <wchar.h> - -wchar_t *wcpncpy(wchar_t *__restrict d, const wchar_t *__restrict s, size_t n) -{ - return wcsncpy(d, s, n) + wcsnlen(s, n); -} diff --git a/libc/string/wcscat.c b/libc/string/wcscat.c deleted file mode 100644 index 1c907db4..00000000 --- a/libc/string/wcscat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <wchar.h> - -wchar_t *wcscat(wchar_t *__restrict dest, const wchar_t *__restrict src) -{ - wcscpy(dest + wcslen(dest), src); - return dest; -} diff --git a/libc/string/wcscpy.c b/libc/string/wcscpy.c deleted file mode 100644 index b09443a2..00000000 --- a/libc/string/wcscpy.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <wchar.h> - -wchar_t *wcscpy(wchar_t *__restrict d, const wchar_t *__restrict s) -{ - wchar_t *a = d; - while ((*d++ = *s++)); - return a; -} diff --git a/libc/string/wcsncat.c b/libc/string/wcsncat.c deleted file mode 100644 index 1ca0288d..00000000 --- a/libc/string/wcsncat.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <wchar.h> - -wchar_t *wcsncat(wchar_t *__restrict d, const wchar_t *__restrict s, size_t n) -{ - wchar_t *a = d; - d += wcslen(d); - while (n && *s) n--, *d++ = *s++; - *d++ = 0; - return a; -} diff --git a/libc/string/wcsncpy.c b/libc/string/wcsncpy.c deleted file mode 100644 index 55903637..00000000 --- a/libc/string/wcsncpy.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <wchar.h> - -wchar_t *wcsncpy(wchar_t *__restrict d, const wchar_t *__restrict s, size_t n) -{ - wchar_t *a = d; - while (n && *s) n--, *d++ = *s++; - wmemset(d, 0, n); - return a; -} diff --git a/libc/string/wcsstr.c b/libc/string/wcsstr.c deleted file mode 100644 index e0e8dffb..00000000 --- a/libc/string/wcsstr.c +++ /dev/null @@ -1,108 +0,0 @@ -#include <wchar.h> -#include <string.h> -#include <stdlib.h> -#include <stdint.h> - -#define MAX(a,b) ((a)>(b)?(a):(b)) -#define MIN(a,b) ((a)<(b)?(a):(b)) - -static wchar_t *twoway_wcsstr(const wchar_t *h, const wchar_t *n) -{ - const wchar_t *z; - size_t l, ip, jp, k, p, ms, p0, mem, mem0; - - /* Computing length of needle */ - for (l=0; n[l] && h[l]; l++); - if (n[l]) return 0; /* hit the end of h */ - - /* Compute maximal suffix */ - ip = -1; jp = 0; k = p = 1; - while (jp+k<l) { - if (n[ip+k] == n[jp+k]) { - if (k == p) { - jp += p; - k = 1; - } else k++; - } else if (n[ip+k] > n[jp+k]) { - jp += k; - k = 1; - p = jp - ip; - } else { - ip = jp++; - k = p = 1; - } - } - ms = ip; - p0 = p; - - /* And with the opposite comparison */ - ip = -1; jp = 0; k = p = 1; - while (jp+k<l) { - if (n[ip+k] == n[jp+k]) { - if (k == p) { - jp += p; - k = 1; - } else k++; - } else if (n[ip+k] < n[jp+k]) { - jp += k; - k = 1; - p = jp - ip; - } else { - ip = jp++; - k = p = 1; - } - } - if (ip+1 > ms+1) ms = ip; - else p = p0; - - /* Periodic needle? */ - if (wmemcmp(n, n+p, ms+1)) { - mem0 = 0; - p = MAX(ms, l-ms-1) + 1; - } else mem0 = l-p; - mem = 0; - - /* Initialize incremental end-of-haystack pointer */ - z = h; - - /* Search loop */ - for (;;) { - /* Update incremental end-of-haystack pointer */ - if (z-h < l) { - /* Fast estimate for MIN(l,63) */ - size_t grow = l | 63; - const wchar_t *z2 = wmemchr(z, 0, grow); - if (z2) { - z = z2; - if (z-h < l) return 0; - } else z += grow; - } - - /* Compare right half */ - for (k=MAX(ms+1,mem); n[k] && n[k] == h[k]; k++); - if (n[k]) { - h += k-ms; - mem = 0; - continue; - } - /* Compare left half */ - for (k=ms+1; k>mem && n[k-1] == h[k-1]; k--); - if (k == mem) return (wchar_t *)h; - h += p; - mem = mem0; - } -} - -wchar_t *wcsstr(const wchar_t *__restrict h, const wchar_t *__restrict n) -{ - /* Return immediately on empty needle or haystack */ - if (!n[0]) return (wchar_t *)h; - if (!h[0]) return 0; - - /* Use faster algorithms for short needles */ - h = wcschr(h, *n); - if (!h || !n[1]) return (wchar_t *)h; - if (!h[1]) return 0; - - return twoway_wcsstr(h, n); -} diff --git a/libc/string/wcstok.c b/libc/string/wcstok.c deleted file mode 100644 index 15b07cd2..00000000 --- a/libc/string/wcstok.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <wchar.h> - -wchar_t *wcstok(wchar_t *__restrict s, const wchar_t *__restrict sep, wchar_t **__restrict p) -{ - if (!s && !(s = *p)) return NULL; - s += wcsspn(s, sep); - if (!*s) return *p = 0; - *p = s + wcscspn(s, sep); - if (**p) *(*p)++ = 0; - else *p = 0; - return s; -} diff --git a/libc/string/wmemcpy.c b/libc/string/wmemcpy.c deleted file mode 100644 index 79606cb8..00000000 --- a/libc/string/wmemcpy.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <string.h> -#include <wchar.h> - -wchar_t *wmemcpy(wchar_t *__restrict d, const wchar_t *__restrict s, size_t n) -{ - wchar_t *a = d; - while (n--) *d++ = *s++; - return 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 osv-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/20200727164827.10746-1-jwkozaczuk%40gmail.com.