about summary refs log tree commit diff
path: root/REORG.TODO/string/bits
diff options
context:
space:
mode:
Diffstat (limited to 'REORG.TODO/string/bits')
-rw-r--r--REORG.TODO/string/bits/string2.h119
-rw-r--r--REORG.TODO/string/bits/string3.h156
-rw-r--r--REORG.TODO/string/bits/strings_fortified.h34
3 files changed, 309 insertions, 0 deletions
diff --git a/REORG.TODO/string/bits/string2.h b/REORG.TODO/string/bits/string2.h
new file mode 100644
index 0000000000..6a26e2bc68
--- /dev/null
+++ b/REORG.TODO/string/bits/string2.h
@@ -0,0 +1,119 @@
+/* Machine-independant string function optimizations.
+   Copyright (C) 1997-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _STRING_H
+# error "Never use <bits/string2.h> directly; include <string.h> instead."
+#endif
+
+#ifndef __NO_STRING_INLINES
+
+/* Unlike the definitions in the header <bits/string.h> the
+   definitions contained here are not optimized down to assembler
+   level.  Those optimizations are not always a good idea since this
+   means the code size increases a lot.  Instead the definitions here
+   optimize some functions in a way which do not dramatically
+   increase the code size and which do not use assembler.  The main
+   trick is to use GCC's `__builtin_constant_p' function.
+
+   Every function XXX which has a defined version in
+   <bits/string.h> must be accompanied by a symbol _HAVE_STRING_ARCH_XXX
+   to make sure we don't get redefinitions.
+
+   We must use here macros instead of inline functions since the
+   trick won't work with the latter.  */
+
+#ifndef __STRING_INLINE
+# ifdef __cplusplus
+#  define __STRING_INLINE inline
+# else
+#  define __STRING_INLINE __extern_inline
+# endif
+#endif
+
+/* Dereferencing a pointer arg to run sizeof on it fails for the void
+   pointer case, so we use this instead.
+   Note that __x is evaluated twice. */
+#define __string2_1bptr_p(__x) \
+  ((size_t)(const void *)((__x) + 1) - (size_t)(const void *)(__x) == 1)
+
+/* Set N bytes of S to 0.  */
+#if !defined _HAVE_STRING_ARCH_memset
+# define __bzero(s, n) __builtin_memset (s, '\0', n)
+#endif
+
+
+/* Copy SRC to DEST, returning pointer to final NUL byte.  */
+#ifdef __USE_GNU
+# ifndef _HAVE_STRING_ARCH_stpcpy
+#  define __stpcpy(dest, src) __builtin_stpcpy (dest, src)
+/* In glibc we use this function frequently but for namespace reasons
+   we have to use the name `__stpcpy'.  */
+#  define stpcpy(dest, src) __stpcpy (dest, src)
+# endif
+#endif
+
+
+/* Copy no more than N characters of SRC to DEST.  */
+#ifndef _HAVE_STRING_ARCH_strncpy
+# define strncpy(dest, src, n) __builtin_strncpy (dest, src, n)
+#endif
+
+
+/* Append no more than N characters from SRC onto DEST.  */
+#ifndef _HAVE_STRING_ARCH_strncat
+# ifdef _USE_STRING_ARCH_strchr
+#  define strncat(dest, src, n) \
+  (__extension__ ({ char *__dest = (dest);				      \
+		    __builtin_constant_p (src) && __builtin_constant_p (n)    \
+		    ? (strlen (src) < ((size_t) (n))			      \
+		       ? strcat (__dest, src)				      \
+		       : (*((char *) __mempcpy (strchr (__dest, '\0'),	      \
+						src, n)) = '\0', __dest))     \
+		    : strncat (dest, src, n); }))
+# else
+#  define strncat(dest, src, n) __builtin_strncat (dest, src, n)
+# endif
+#endif
+
+
+/* Return the length of the initial segment of S which
+   consists entirely of characters not in REJECT.  */
+#ifndef _HAVE_STRING_ARCH_strcspn
+# define strcspn(s, reject) __builtin_strcspn (s, reject)
+#endif
+
+
+/* Return the length of the initial segment of S which
+   consists entirely of characters in ACCEPT.  */
+#ifndef _HAVE_STRING_ARCH_strspn
+# define strspn(s, accept) __builtin_strspn (s, accept)
+#endif
+
+
+/* Find the first occurrence in S of any character in ACCEPT.  */
+#ifndef _HAVE_STRING_ARCH_strpbrk
+# define strpbrk(s, accept) __builtin_strpbrk (s, accept)
+#endif
+
+
+#ifndef _FORCE_INLINES
+# undef __STRING_INLINE
+#endif
+
+#endif /* No string inlines.  */
diff --git a/REORG.TODO/string/bits/string3.h b/REORG.TODO/string/bits/string3.h
new file mode 100644
index 0000000000..738226d49b
--- /dev/null
+++ b/REORG.TODO/string/bits/string3.h
@@ -0,0 +1,156 @@
+/* Copyright (C) 2004-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _STRING_H
+# error "Never use <bits/string3.h> directly; include <string.h> instead."
+#endif
+
+#if !__GNUC_PREREQ (5,0)
+__warndecl (__warn_memset_zero_len,
+	    "memset used with constant zero length parameter; this could be due to transposed parameters");
+#endif
+
+#ifndef __cplusplus
+/* XXX This is temporarily.  We should not redefine any of the symbols
+   and instead integrate the error checking into the original
+   definitions.  */
+# undef memcpy
+# undef memmove
+# undef memset
+# undef strcat
+# undef strcpy
+# undef strncat
+# undef strncpy
+# ifdef __USE_GNU
+#  undef mempcpy
+#  undef stpcpy
+# endif
+# ifdef __USE_MISC
+#  undef bcopy
+#  undef bzero
+# endif
+#endif
+
+
+__fortify_function void *
+__NTH (memcpy (void *__restrict __dest, const void *__restrict __src,
+	       size_t __len))
+{
+  return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
+}
+
+__fortify_function void *
+__NTH (memmove (void *__dest, const void *__src, size_t __len))
+{
+  return __builtin___memmove_chk (__dest, __src, __len, __bos0 (__dest));
+}
+
+#ifdef __USE_GNU
+__fortify_function void *
+__NTH (mempcpy (void *__restrict __dest, const void *__restrict __src,
+		size_t __len))
+{
+  return __builtin___mempcpy_chk (__dest, __src, __len, __bos0 (__dest));
+}
+#endif
+
+
+/* The first two tests here help to catch a somewhat common problem
+   where the second and third parameter are transposed.  This is
+   especially problematic if the intended fill value is zero.  In this
+   case no work is done at all.  We detect these problems by referring
+   non-existing functions.  */
+__fortify_function void *
+__NTH (memset (void *__dest, int __ch, size_t __len))
+{
+  /* GCC-5.0 and newer implements these checks in the compiler, so we don't
+     need them here.  */
+#if !__GNUC_PREREQ (5,0)
+  if (__builtin_constant_p (__len) && __len == 0
+      && (!__builtin_constant_p (__ch) || __ch != 0))
+    {
+      __warn_memset_zero_len ();
+      return __dest;
+    }
+#endif
+  return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
+}
+
+#ifdef __USE_MISC
+# include <bits/strings_fortified.h>
+
+void __explicit_bzero_chk (void *__dest, size_t __len, size_t __destlen)
+  __THROW __nonnull ((1));
+
+__fortify_function void
+__NTH (explicit_bzero (void *__dest, size_t __len))
+{
+  __explicit_bzero_chk (__dest, __len, __bos0 (__dest));
+}
+#endif
+
+__fortify_function char *
+__NTH (strcpy (char *__restrict __dest, const char *__restrict __src))
+{
+  return __builtin___strcpy_chk (__dest, __src, __bos (__dest));
+}
+
+#ifdef __USE_GNU
+__fortify_function char *
+__NTH (stpcpy (char *__restrict __dest, const char *__restrict __src))
+{
+  return __builtin___stpcpy_chk (__dest, __src, __bos (__dest));
+}
+#endif
+
+
+__fortify_function char *
+__NTH (strncpy (char *__restrict __dest, const char *__restrict __src,
+		size_t __len))
+{
+  return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
+}
+
+/* XXX We have no corresponding builtin yet.  */
+extern char *__stpncpy_chk (char *__dest, const char *__src, size_t __n,
+			    size_t __destlen) __THROW;
+extern char *__REDIRECT_NTH (__stpncpy_alias, (char *__dest, const char *__src,
+					       size_t __n), stpncpy);
+
+__fortify_function char *
+__NTH (stpncpy (char *__dest, const char *__src, size_t __n))
+{
+  if (__bos (__dest) != (size_t) -1
+      && (!__builtin_constant_p (__n) || __n > __bos (__dest)))
+    return __stpncpy_chk (__dest, __src, __n, __bos (__dest));
+  return __stpncpy_alias (__dest, __src, __n);
+}
+
+
+__fortify_function char *
+__NTH (strcat (char *__restrict __dest, const char *__restrict __src))
+{
+  return __builtin___strcat_chk (__dest, __src, __bos (__dest));
+}
+
+
+__fortify_function char *
+__NTH (strncat (char *__restrict __dest, const char *__restrict __src,
+		size_t __len))
+{
+  return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));
+}
diff --git a/REORG.TODO/string/bits/strings_fortified.h b/REORG.TODO/string/bits/strings_fortified.h
new file mode 100644
index 0000000000..411e7863d6
--- /dev/null
+++ b/REORG.TODO/string/bits/strings_fortified.h
@@ -0,0 +1,34 @@
+/* Fortify macros for strings.h functions.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef __STRINGS_FORTIFIED
+# define __STRINGS_FORTIFIED 1
+
+__fortify_function void
+__NTH (bcopy (const void *__src, void *__dest, size_t __len))
+{
+  (void) __builtin___memmove_chk (__dest, __src, __len, __bos0 (__dest));
+}
+
+__fortify_function void
+__NTH (bzero (void *__dest, size_t __len))
+{
+  (void) __builtin___memset_chk (__dest, '\0', __len, __bos0 (__dest));
+}
+
+#endif