changeset 4664:42147e1c0cee

Remove K&R cruft.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 09 Sep 2003 22:22:46 +0000
parents f3ad8f03546c
children dc6d827f3011
files lib/memchr.c lib/memcmp.c lib/memcoll.c lib/memcpy.c lib/memmove.c lib/memrchr.c lib/memset.c m4/memchr.m4 m4/memcmp.m4 m4/memcoll.m4 m4/memrchr.m4
diffstat 11 files changed, 70 insertions(+), 125 deletions(-) [+]
line wrap: on
line diff
--- a/lib/memchr.c
+++ b/lib/memchr.c
@@ -1,4 +1,6 @@
-/* Copyright (C) 1991,93,96,97,99,2000 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003 Free
+   Software Foundation, Inc.
+
    Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
    with help from Dan Sahlin (dan@sics.se) and
    commentary by Jim Blandy (jimb@ai.mit.edu);
@@ -27,34 +29,19 @@
 # include <config.h>
 #endif
 
-#undef __ptr_t
-#if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
-# define __ptr_t void *
-#else /* Not C++ or ANSI C.  */
-# define __ptr_t char *
-#endif /* C++ or ANSI C.  */
+#include <string.h>
 
 #if defined _LIBC
-# include <string.h>
 # include <memcopy.h>
 #else
 # define reg_char char
 #endif
 
-#if HAVE_STDLIB_H || defined _LIBC
-# include <stdlib.h>
-#endif
-
-#if HAVE_LIMITS_H || defined _LIBC
-# include <limits.h>
-#endif
+#include <limits.h>
+#include <stdlib.h>
 
 #define LONG_MAX_32_BITS 2147483647
 
-#ifndef LONG_MAX
-# define LONG_MAX LONG_MAX_32_BITS
-#endif
-
 #include <sys/types.h>
 #if HAVE_BP_SYM_H || defined _LIBC
 # include <bp-sym.h>
@@ -66,11 +53,8 @@
 #undef __memchr
 
 /* Search no more than N bytes of S for C.  */
-__ptr_t
-__memchr (s, c_in, n)
-     const __ptr_t s;
-     int c_in;
-     size_t n;
+void *
+__memchr (void const *s, int c_in, size_t n)
 {
   const unsigned char *char_ptr;
   const unsigned long int *longword_ptr;
@@ -86,7 +70,7 @@
 		 & (sizeof (longword) - 1)) != 0;
        --n, ++char_ptr)
     if (*char_ptr == c)
-      return (__ptr_t) char_ptr;
+      return (void *) char_ptr;
 
   /* All these elucidatory comments refer to 4-byte longwords,
      but the theory applies equally well to 8-byte longwords.  */
@@ -177,22 +161,22 @@
 	  const unsigned char *cp = (const unsigned char *) (longword_ptr - 1);
 
 	  if (cp[0] == c)
-	    return (__ptr_t) cp;
+	    return (void *) cp;
 	  if (cp[1] == c)
-	    return (__ptr_t) &cp[1];
+	    return (void *) &cp[1];
 	  if (cp[2] == c)
-	    return (__ptr_t) &cp[2];
+	    return (void *) &cp[2];
 	  if (cp[3] == c)
-	    return (__ptr_t) &cp[3];
+	    return (void *) &cp[3];
 #if LONG_MAX > 2147483647
 	  if (cp[4] == c)
-	    return (__ptr_t) &cp[4];
+	    return (void *) &cp[4];
 	  if (cp[5] == c)
-	    return (__ptr_t) &cp[5];
+	    return (void *) &cp[5];
 	  if (cp[6] == c)
-	    return (__ptr_t) &cp[6];
+	    return (void *) &cp[6];
 	  if (cp[7] == c)
-	    return (__ptr_t) &cp[7];
+	    return (void *) &cp[7];
 #endif
 	}
 
@@ -204,7 +188,7 @@
   while (n-- > 0)
     {
       if (*char_ptr == c)
-	return (__ptr_t) char_ptr;
+	return (void *) char_ptr;
       else
 	++char_ptr;
     }
--- a/lib/memcmp.c
+++ b/lib/memcmp.c
@@ -1,4 +1,6 @@
-/* Copyright (C) 1991, 1993, 1995, 1997, 1998 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1993, 1995, 1997, 1998, 2003 Free Software
+   Foundation, Inc.
+
    Contributed by Torbjorn Granlund (tege@sics.se).
 
    NOTE: The canonical source of this file is maintained with the GNU C Library.
@@ -23,26 +25,7 @@
 # include "config.h"
 #endif
 
-#undef	__ptr_t
-#if defined __cplusplus || (defined __STDC__ && __STDC__)
-# define __ptr_t	void *
-#else /* Not C++ or ANSI C.  */
-# undef	const
-# define const
-# define __ptr_t	char *
-#endif /* C++ or ANSI C.  */
-
-#ifndef __P
-# if defined __GNUC__ || (defined __STDC__ && __STDC__)
-#  define __P(args) args
-# else
-#  define __P(args) ()
-# endif  /* GCC.  */
-#endif  /* Not __P.  */
-
-#if defined HAVE_STRING_H || defined _LIBC
-# include <string.h>
-#endif
+#include <string.h>
 
 #undef memcmp
 
@@ -103,8 +86,6 @@
    A and B are known to be different.
    This is needed only on little-endian machines.  */
 
-static int memcmp_bytes __P((op_t, op_t));
-
 # ifdef  __GNUC__
 __inline
 # endif
@@ -127,8 +108,6 @@
 }
 #endif
 
-static int memcmp_common_alignment __P((long, long, size_t));
-
 /* memcmp_common_alignment -- Compare blocks at SRCP1 and SRCP2 with LEN `op_t'
    objects (not LEN bytes!).  Both SRCP1 and SRCP2 should be aligned for
    memory operations on `op_t's.  */
@@ -214,8 +193,6 @@
   return 0;
 }
 
-static int memcmp_not_common_alignment __P((long, long, size_t));
-
 /* memcmp_not_common_alignment -- Compare blocks at SRCP1 and SRCP2 with LEN
    `op_t' objects (not LEN bytes!).  SRCP2 should be aligned for memory
    operations on `op_t', but SRCP1 *should be unaligned*.  */
--- a/lib/memcoll.c
+++ b/lib/memcoll.c
@@ -28,9 +28,7 @@
 extern int errno;
 #endif
 
-#if HAVE_STRING_H
-# include <string.h>
-#endif
+#include <string.h>
 
 /* Compare S1 (with length S1LEN) and S2 (with length S2LEN) according
    to the LC_COLLATE locale.  S1 and S2 do not overlap, and are not
--- a/lib/memcpy.c
+++ b/lib/memcpy.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995, 1997, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 1997, 2000, 2003 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -20,16 +20,19 @@
 # include <config.h>
 #endif
 
+#include <stddef.h>
+
 /* Copy LEN bytes starting at SRCADDR to DESTADDR.  Result undefined
    if the source overlaps with the destination.
    Return DESTADDR. */
 
-char *
-memcpy (char *destaddr, const char *srcaddr, int len)
+void *
+memcpy (void *destaddr, void const *srcaddr, size_t len)
 {
   char *dest = destaddr;
+  char const *src = srcaddr;
 
   while (len-- > 0)
-    *destaddr++ = *srcaddr++;
-  return dest;
+    *dest++ = *src++;
+  return destaddr;
 }
--- a/lib/memmove.c
+++ b/lib/memmove.c
@@ -7,13 +7,13 @@
 # include <config.h>
 #endif
 
+#include <stddef.h>
+
 void *
-memmove (dest, source, length)
-     char *dest;
-     const char *source;
-     unsigned length;
+memmove (void *dest0, void const *source0, size_t length)
 {
-  char *d0 = dest;
+  char *dest = dest0;
+  char const *source = source0;
   if (source < dest)
     /* Moving from low mem to hi mem; start at end.  */
     for (source += length, dest += length; length; --length)
@@ -24,5 +24,5 @@
       for (; length; --length)
 	*dest++ = *source++;
     }
-  return (void *) d0;
+  return dest0;
 }
--- a/lib/memrchr.c
+++ b/lib/memrchr.c
@@ -1,5 +1,8 @@
 /* memrchr -- find the last occurrence of a byte in a memory block
-   Copyright (C) 1991, 93, 96, 97, 99, 2000 Free Software Foundation, Inc.
+
+   Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003 Free
+   Software Foundation, Inc.
+
    Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
    with help from Dan Sahlin (dan@sics.se) and
    commentary by Jim Blandy (jimb@ai.mit.edu);
@@ -25,31 +28,18 @@
 #endif
 
 #include <stdlib.h>
-
-#undef __ptr_t
-#if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
-# define __ptr_t void *
-#else /* Not C++ or ANSI C.  */
-# define __ptr_t char *
-#endif /* C++ or ANSI C.  */
+#include <string.h>
 
 #if defined (_LIBC)
-# include <string.h>
 # include <memcopy.h>
 #else
 # define reg_char char
 #endif
 
-#if defined (HAVE_LIMITS_H) || defined (_LIBC)
-# include <limits.h>
-#endif
+#include <limits.h>
 
 #define LONG_MAX_32_BITS 2147483647
 
-#ifndef LONG_MAX
-# define LONG_MAX LONG_MAX_32_BITS
-#endif
-
 #include <sys/types.h>
 
 #undef __memrchr
@@ -60,11 +50,8 @@
 #endif
 
 /* Search no more than N bytes of S for C.  */
-__ptr_t
-__memrchr (s, c_in, n)
-     const __ptr_t s;
-     int c_in;
-     size_t n;
+void *
+__memrchr (void const *s, int c_in, size_t n)
 {
   const unsigned char *char_ptr;
   const unsigned long int *longword_ptr;
@@ -80,7 +67,7 @@
 		 & (sizeof (longword) - 1)) != 0;
        --n)
     if (*--char_ptr == c)
-      return (__ptr_t) char_ptr;
+      return (void *) char_ptr;
 
   /* All these elucidatory comments refer to 4-byte longwords,
      but the theory applies equally well to 8-byte longwords.  */
@@ -172,22 +159,22 @@
 
 #if LONG_MAX > 2147483647
 	  if (cp[7] == c)
-	    return (__ptr_t) &cp[7];
+	    return (void *) &cp[7];
 	  if (cp[6] == c)
-	    return (__ptr_t) &cp[6];
+	    return (void *) &cp[6];
 	  if (cp[5] == c)
-	    return (__ptr_t) &cp[5];
+	    return (void *) &cp[5];
 	  if (cp[4] == c)
-	    return (__ptr_t) &cp[4];
+	    return (void *) &cp[4];
 #endif
 	  if (cp[3] == c)
-	    return (__ptr_t) &cp[3];
+	    return (void *) &cp[3];
 	  if (cp[2] == c)
-	    return (__ptr_t) &cp[2];
+	    return (void *) &cp[2];
 	  if (cp[1] == c)
-	    return (__ptr_t) &cp[1];
+	    return (void *) &cp[1];
 	  if (cp[0] == c)
-	    return (__ptr_t) cp;
+	    return (void *) cp;
 	}
 
       n -= sizeof (longword);
@@ -198,7 +185,7 @@
   while (n-- > 0)
     {
       if (*--char_ptr == c)
-	return (__ptr_t) char_ptr;
+	return (void *) char_ptr;
     }
 
   return 0;
--- a/lib/memset.c
+++ b/lib/memset.c
@@ -1,5 +1,5 @@
 /* memset.c -- set an area of memory to a given value
-   Copyright (C) 1991 Free Software Foundation, Inc.
+   Copyright (C) 1991, 2003 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -15,8 +15,10 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
-char *
-memset (char *str, int c, unsigned int len)
+#include <stddef.h>
+
+void *
+memset (void *str, int c, size_t len)
 {
   register char *st = str;
 
--- a/m4/memchr.m4
+++ b/m4/memchr.m4
@@ -1,5 +1,5 @@
-# memchr.m4 serial 1
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# memchr.m4 serial 2
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
@@ -16,6 +16,5 @@
 
 # Prerequisites of lib/memchr.c.
 AC_DEFUN([jm_PREREQ_MEMCHR], [
-  AC_CHECK_HEADERS_ONCE(limits.h stdlib.h)
   AC_CHECK_HEADERS(bp-sym.h)
 ])
--- a/m4/memcmp.m4
+++ b/m4/memcmp.m4
@@ -1,5 +1,5 @@
-# memcmp.m4 serial 8
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# memcmp.m4 serial 9
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
@@ -17,6 +17,4 @@
 ])
 
 # Prerequisites of lib/memcmp.c.
-AC_DEFUN([gl_PREREQ_MEMCMP], [
-  AC_CHECK_HEADERS_ONCE(string.h)
-])
+AC_DEFUN([gl_PREREQ_MEMCMP], [:])
--- a/m4/memcoll.m4
+++ b/m4/memcoll.m4
@@ -1,5 +1,5 @@
-# memcoll.m4 serial 2
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# memcoll.m4 serial 3
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
@@ -10,6 +10,5 @@
 [
   dnl Prerequisites of lib/memcoll.c.
   AC_REQUIRE([AC_FUNC_MEMCMP])
-  AC_CHECK_HEADERS_ONCE(string.h)
   AC_FUNC_STRCOLL
 ])
--- a/m4/memrchr.m4
+++ b/m4/memrchr.m4
@@ -1,5 +1,5 @@
-# memrchr.m4 serial 1
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# memrchr.m4 serial 2
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
@@ -18,6 +18,4 @@
 ])
 
 # Prerequisites of lib/memrchr.c.
-AC_DEFUN([gl_PREREQ_MEMRCHR], [
-  AC_CHECK_HEADERS_ONCE(limits.h)
-])
+AC_DEFUN([gl_PREREQ_MEMRCHR], [:])