From 1a170a10473b1b72223fae27879fa19a31785ed1 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 9 Sep 2003 22:22:46 +0000 Subject: [PATCH] Remove K&R cruft. --- lib/memchr.c | 52 ++++++++++++++++++---------------------------------- lib/memcmp.c | 31 ++++--------------------------- lib/memcoll.c | 4 +--- lib/memcpy.c | 13 ++++++++----- lib/memmove.c | 12 ++++++------ lib/memrchr.c | 49 ++++++++++++++++++------------------------------- lib/memset.c | 8 +++++--- m4/memchr.m4 | 5 ++--- m4/memcmp.m4 | 8 +++----- m4/memcoll.m4 | 5 ++--- m4/memrchr.m4 | 8 +++----- 11 files changed, 70 insertions(+), 125 deletions(-) diff --git a/lib/memchr.c b/lib/memchr.c index 4b28e481f..ae232ae34 100644 --- 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 @@ USA. */ # include #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 #if defined _LIBC -# include # include #else # define reg_char char #endif -#if HAVE_STDLIB_H || defined _LIBC -# include -#endif - -#if HAVE_LIMITS_H || defined _LIBC -# include -#endif +#include +#include #define LONG_MAX_32_BITS 2147483647 -#ifndef LONG_MAX -# define LONG_MAX LONG_MAX_32_BITS -#endif - #include #if HAVE_BP_SYM_H || defined _LIBC # include @@ -66,11 +53,8 @@ USA. */ #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 @@ __memchr (s, c_in, n) & (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 @@ __memchr (s, c_in, n) 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 @@ __memchr (s, c_in, n) while (n-- > 0) { if (*char_ptr == c) - return (__ptr_t) char_ptr; + return (void *) char_ptr; else ++char_ptr; } diff --git a/lib/memcmp.c b/lib/memcmp.c index 5756bc0a4..1d2947e66 100644 --- 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 -#endif +#include #undef memcmp @@ -103,8 +86,6 @@ typedef unsigned char byte; 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 @@ memcmp_bytes (long unsigned int a, long unsigned int b) } #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 @@ memcmp_common_alignment (long int srcp1, long int srcp2, size_t len) 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*. */ diff --git a/lib/memcoll.c b/lib/memcoll.c index 38d2bdfbd..34ae767db 100644 --- a/lib/memcoll.c +++ b/lib/memcoll.c @@ -28,9 +28,7 @@ extern int errno; #endif -#if HAVE_STRING_H -# include -#endif +#include /* 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 diff --git a/lib/memcpy.c b/lib/memcpy.c index 2ccd71875..fdca8de2c 100644 --- 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 #endif +#include + /* 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; } diff --git a/lib/memmove.c b/lib/memmove.c index ea38e8df5..79cc78273 100644 --- a/lib/memmove.c +++ b/lib/memmove.c @@ -7,13 +7,13 @@ # include #endif +#include + 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 @@ memmove (dest, source, length) for (; length; --length) *dest++ = *source++; } - return (void *) d0; + return dest0; } diff --git a/lib/memrchr.c b/lib/memrchr.c index 9f29900f8..7d702f35e 100644 --- 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 - -#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 #if defined (_LIBC) -# include # include #else # define reg_char char #endif -#if defined (HAVE_LIMITS_H) || defined (_LIBC) -# include -#endif +#include #define LONG_MAX_32_BITS 2147483647 -#ifndef LONG_MAX -# define LONG_MAX LONG_MAX_32_BITS -#endif - #include #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 @@ __memrchr (s, c_in, n) & (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 @@ __memrchr (s, c_in, n) #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 @@ __memrchr (s, c_in, n) while (n-- > 0) { if (*--char_ptr == c) - return (__ptr_t) char_ptr; + return (void *) char_ptr; } return 0; diff --git a/lib/memset.c b/lib/memset.c index 5744bcbf7..d7321b200 100644 --- 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 + +void * +memset (void *str, int c, size_t len) { register char *st = str; diff --git a/m4/memchr.m4 b/m4/memchr.m4 index 7b6cfc43d..60a06c271 100644 --- 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 @@ AC_DEFUN([gl_FUNC_MEMCHR], # Prerequisites of lib/memchr.c. AC_DEFUN([jm_PREREQ_MEMCHR], [ - AC_CHECK_HEADERS_ONCE(limits.h stdlib.h) AC_CHECK_HEADERS(bp-sym.h) ]) diff --git a/m4/memcmp.m4 b/m4/memcmp.m4 index 4442e47b6..90d8bb30f 100644 --- 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 @@ AC_DEFUN([jm_FUNC_MEMCMP], ]) # Prerequisites of lib/memcmp.c. -AC_DEFUN([gl_PREREQ_MEMCMP], [ - AC_CHECK_HEADERS_ONCE(string.h) -]) +AC_DEFUN([gl_PREREQ_MEMCMP], [:]) diff --git a/m4/memcoll.m4 b/m4/memcoll.m4 index 23f56af17..131841a40 100644 --- 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 @@ AC_DEFUN([gl_MEMCOLL], [ dnl Prerequisites of lib/memcoll.c. AC_REQUIRE([AC_FUNC_MEMCMP]) - AC_CHECK_HEADERS_ONCE(string.h) AC_FUNC_STRCOLL ]) diff --git a/m4/memrchr.m4 b/m4/memrchr.m4 index c489ec3d3..dfb0583ac 100644 --- 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 @@ AC_DEFUN([gl_FUNC_MEMRCHR], ]) # Prerequisites of lib/memrchr.c. -AC_DEFUN([gl_PREREQ_MEMRCHR], [ - AC_CHECK_HEADERS_ONCE(limits.h) -]) +AC_DEFUN([gl_PREREQ_MEMRCHR], [:]) -- 2.11.0