bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnulib] strnlen patch to assume C89 or better


From: Paul Eggert
Subject: Re: [Bug-gnulib] strnlen patch to assume C89 or better
Date: 12 Sep 2003 12:24:10 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Bruno Haible <address@hidden> writes:

> Since this file now assumes ANSI C, wouldn't it be logical to also rename
> extra_args_spec_iso to extra_args_spec?

Yes, thanks.  I installed this patch:

        * strftime.c (HAVE_LIMITS_H, STDC_HEADERS) [defined _LIBC]: Remove.
        (HAVE_MEMCPY) [defined emacs && !defined HAVE_BCOPY]: Remove.
        Include <limits.h>, <stddef.h>, <stdlib.h>, <string.h> unconditionally.
        (memcpy): Remove macro.
        (MEMCPY) [!defined COMPILE_WIDE]: Define to memcpy unconditionally.
        (__P): Remove.  All uses removed.
        (PTR): Remove.  All uses changed to void *.
        (CHAR_BIT, NULL): Remove.
        (spaces, zeros, memset_space, memset_zero)
        [!defined memset && !defined HAVE_MEMSET && !defined _LIBC]:
        Remove.
        (LOCALE_PARAM, LOCALE_PARAM_DECL): Remove.
        (memcpy_lowcase, memcpy_uppcase, tm_diff, iso_week_days):
        Define with prototype.
        Remove now-unnecessary prototype decl.
        (extra_args_spec): Assume ANSI C.  All uses changed.
        (extra_args_spec_iso): Remove.
        (my_strftime, emacs_strftimeu): Define via prototype.
        * strftime.m4 (_jm_STRFTIME_PREREQS): Don't check for limits.h,
        memcpy, memset.
        (jm_FUNC_GNU_STRFTIME): Don't require standard C headers.

Index: lib/strftime.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/strftime.c,v
retrieving revision 1.72
diff -p -u -r1.72 strftime.c
--- lib/strftime.c      6 Sep 2003 21:34:07 -0000       1.72
+++ lib/strftime.c      12 Sep 2003 19:20:45 -0000
@@ -22,7 +22,6 @@
 #endif
 
 #ifdef _LIBC
-# define HAVE_LIMITS_H 1
 # define HAVE_MBLEN 1
 # define HAVE_MBRLEN 1
 # define HAVE_STRUCT_ERA_ENTRY 1
@@ -31,14 +30,9 @@
 # define HAVE_TZNAME 1
 # define HAVE_TZSET 1
 # define MULTIBYTE_IS_FORMAT_SAFE 1
-# define STDC_HEADERS 1
 # include "../locale/localeinfo.h"
 #endif
 
-#if defined emacs && !defined HAVE_BCOPY
-# define HAVE_MEMCPY 1
-#endif
-
 #include <ctype.h>
 #include <sys/types.h>         /* Some systems define `time_t' here.  */
 
@@ -76,19 +70,10 @@ extern char *tzname[];
   static const mbstate_t mbstate_zero;
 #endif
 
-#if HAVE_LIMITS_H
-# include <limits.h>
-#endif
-
-#if STDC_HEADERS
-# include <stddef.h>
-# include <stdlib.h>
-# include <string.h>
-#else
-# ifndef HAVE_MEMCPY
-#  define memcpy(d, s, n) bcopy ((s), (d), (n))
-# endif
-#endif
+#include <limits.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
 
 #ifdef COMPILE_WIDE
 # include <endian.h>
@@ -106,11 +91,7 @@ extern char *tzname[];
 # define L_(Str) Str
 # define NLW(Sym) Sym
 
-# if !defined STDC_HEADERS && !defined HAVE_MEMCPY
-#  define MEMCPY(d, s, n) bcopy ((s), (d), (n))
-# else
-#  define MEMCPY(d, s, n) memcpy ((d), (s), (n))
-# endif
+# define MEMCPY(d, s, n) memcpy (d, s, n)
 # define STRLEN(s) strlen (s)
 
 # ifdef _LIBC
@@ -122,30 +103,6 @@ extern char *tzname[];
 # endif
 #endif
 
-#ifndef __P
-# if defined __GNUC__ || (defined __STDC__ && __STDC__)
-#  define __P(args) args
-# else
-#  define __P(args) ()
-# endif  /* GCC.  */
-#endif  /* Not __P.  */
-
-#ifndef PTR
-# ifdef __STDC__
-#  define PTR void *
-# else
-#  define PTR char *
-# endif
-#endif
-
-#ifndef CHAR_BIT
-# define CHAR_BIT 8
-#endif
-
-#ifndef NULL
-# define NULL 0
-#endif
-
 #define TYPE_SIGNED(t) ((t) -1 < 0)
 
 /* Bound on length of the string representing an integer value of type t.
@@ -184,55 +141,12 @@ extern char *tzname[];
 #endif
 
 
-#if !defined memset && !defined HAVE_MEMSET && !defined _LIBC
-/* Some systems lack the `memset' function and we don't want to
-   introduce additional dependencies.  */
-/* The SGI compiler reportedly barfs on the trailing null
-   if we use a string constant as the initializer.  28 June 1997, rms.  */
-static const CHAR_T spaces[16] = /* "                " */
-{
-  L_(' '),L_(' '),L_(' '),L_(' '),L_(' '),L_(' '),L_(' '),L_(' '),
-  L_(' '),L_(' '),L_(' '),L_(' '),L_(' '),L_(' '),L_(' '),L_(' ')
-};
-static const CHAR_T zeroes[16] = /* "0000000000000000" */
-{
-  L_('0'),L_('0'),L_('0'),L_('0'),L_('0'),L_('0'),L_('0'),L_('0'),
-  L_('0'),L_('0'),L_('0'),L_('0'),L_('0'),L_('0'),L_('0'),L_('0')
-};
-
-# define memset_space(P, Len) \
-  do {                                                                       \
-    int _len = (Len);                                                        \
-                                                                             \
-    do                                                                       \
-      {                                                                        
      \
-       int _this = _len > 16 ? 16 : _len;                                    \
-       (P) = MEMPCPY ((P), spaces, _this * sizeof (CHAR_T));                 \
-       _len -= _this;                                                        \
-      }                                                                        
      \
-    while (_len > 0);                                                        \
-  } while (0)
-
-# define memset_zero(P, Len) \
-  do {                                                                       \
-    int _len = (Len);                                                        \
-                                                                             \
-    do                                                                       \
-      {                                                                        
      \
-       int _this = _len > 16 ? 16 : _len;                                    \
-       (P) = MEMPCPY ((P), zeroes, _this * sizeof (CHAR_T));                 \
-       _len -= _this;                                                        \
-      }                                                                        
      \
-    while (_len > 0);                                                        \
-  } while (0)
+#ifdef COMPILE_WIDE
+# define memset_space(P, Len) (wmemset (P, L' ', Len), (P) += (Len))
+# define memset_zero(P, Len) (wmemset (P, L'0', Len), (P) += (Len))
 #else
-# ifdef COMPILE_WIDE
-#  define memset_space(P, Len) (wmemset ((P), L' ', (Len)), (P) += (Len))
-#  define memset_zero(P, Len) (wmemset ((P), L'0', (Len)), (P) += (Len))
-# else
-#  define memset_space(P, Len) (memset ((P), ' ', (Len)), (P) += (Len))
-#  define memset_zero(P, Len) (memset ((P), '0', (Len)), (P) += (Len))
-# endif
+# define memset_space(P, Len) (memset (P, ' ', Len), (P) += (Len))
+# define memset_zero(P, Len) (memset (P, '0', Len), (P) += (Len))
 #endif
 
 #define add(n, f)                                                            \
@@ -265,7 +179,7 @@ static const CHAR_T zeroes[16] = /* "000
         else if (to_uppcase)                                                 \
           memcpy_uppcase (p, (s), _n LOCALE_ARG);                            \
         else                                                                 \
-          MEMCPY ((PTR) p, (const PTR) (s), _n))
+          MEMCPY ((void *) p, (void const *) (s), _n))
 
 #ifdef COMPILE_WIDE
 # ifndef USE_IN_EXTENDED_LOCALE_MODEL
@@ -294,16 +208,12 @@ static const CHAR_T zeroes[16] = /* "000
 # undef _NL_CURRENT
 # define _NL_CURRENT(category, item) \
   (current->values[_NL_ITEM_INDEX (item)].string)
-# define LOCALE_PARAM , loc
 # define LOCALE_ARG , loc
-# define LOCALE_PARAM_DECL  __locale_t loc;
 # define LOCALE_PARAM_PROTO , __locale_t loc
 # define HELPER_LOCALE_ARG  , current
 #else
-# define LOCALE_PARAM
 # define LOCALE_PARAM_PROTO
 # define LOCALE_ARG
-# define LOCALE_PARAM_DECL
 # ifdef _LIBC
 #  define HELPER_LOCALE_ARG , _NL_CURRENT_DATA (LC_TIME)
 # else
@@ -339,30 +249,18 @@ static const CHAR_T zeroes[16] = /* "000
    more reliable way to accept other sets of digits.  */
 #define ISDIGIT(Ch) ((unsigned int) (Ch) - L_('0') <= 9)
 
-static CHAR_T *memcpy_lowcase __P ((CHAR_T *dest, const CHAR_T *src,
-                                   size_t len LOCALE_PARAM_PROTO));
-
 static CHAR_T *
-memcpy_lowcase (dest, src, len LOCALE_PARAM)
-     CHAR_T *dest;
-     const CHAR_T *src;
-     size_t len;
-     LOCALE_PARAM_DECL
+memcpy_lowcase (CHAR_T *dest, const CHAR_T *src,
+               size_t len LOCALE_PARAM_PROTO)
 {
   while (len-- > 0)
     dest[len] = TOLOWER ((UCHAR_T) src[len], loc);
   return dest;
 }
 
-static CHAR_T *memcpy_uppcase __P ((CHAR_T *dest, const CHAR_T *src,
-                                   size_t len LOCALE_PARAM_PROTO));
-
 static CHAR_T *
-memcpy_uppcase (dest, src, len LOCALE_PARAM)
-     CHAR_T *dest;
-     const CHAR_T *src;
-     size_t len;
-     LOCALE_PARAM_DECL
+memcpy_uppcase (CHAR_T *dest, const CHAR_T *src,
+               size_t len LOCALE_PARAM_PROTO)
 {
   while (len-- > 0)
     dest[len] = TOUPPER ((UCHAR_T) src[len], loc);
@@ -374,11 +272,8 @@ memcpy_uppcase (dest, src, len LOCALE_PA
 /* Yield the difference between *A and *B,
    measured in seconds, ignoring leap seconds.  */
 # define tm_diff ftime_tm_diff
-static int tm_diff __P ((const struct tm *, const struct tm *));
 static int
-tm_diff (a, b)
-     const struct tm *a;
-     const struct tm *b;
+tm_diff (const struct tm *, const struct tm *)
 {
   /* Compute intervening leap days correctly even if year is negative.
      Take care to avoid int overflow in leap day calculations,
@@ -408,14 +303,11 @@ tm_diff (a, b)
 #define ISO_WEEK_START_WDAY 1 /* Monday */
 #define ISO_WEEK1_WDAY 4 /* Thursday */
 #define YDAY_MINIMUM (-366)
-static int iso_week_days __P ((int, int));
 #ifdef __GNUC__
 __inline__
 #endif
 static int
-iso_week_days (yday, wday)
-     int yday;
-     int wday;
+iso_week_days (int yday, int wday)
 {
   /* Add enough to the first operand of % to make it nonnegative.  */
   int big_enough_multiple_of_7 = (-YDAY_MINIMUM / 7 + 2) * 7;
@@ -451,8 +343,7 @@ static CHAR_T const month_name[][10] =
 
 #ifdef my_strftime
 # define extra_args , ut, ns
-# define extra_args_spec int ut; int ns;
-# define extra_args_spec_iso , int ut, int ns
+# define extra_args_spec , int ut, int ns
 #else
 # ifdef COMPILE_WIDE
 #  define my_strftime wcsftime
@@ -463,7 +354,6 @@ static CHAR_T const month_name[][10] =
 # endif
 # define extra_args
 # define extra_args_spec
-# define extra_args_spec_iso
 /* We don't have this information in general.  */
 # define ut 0
 # define ns 0
@@ -484,13 +374,8 @@ static CHAR_T const month_name[][10] =
    anywhere, so to determine how many characters would be
    written, use NULL for S and (size_t) UINT_MAX for MAXSIZE.  */
 size_t
-my_strftime (s, maxsize, format, tp extra_args LOCALE_PARAM)
-      CHAR_T *s;
-      size_t maxsize;
-      const CHAR_T *format;
-      const struct tm *tp;
-      extra_args_spec
-      LOCALE_PARAM_DECL
+my_strftime (CHAR_T *s, size_t maxsize, const CHAR_T *format,
+            const struct tm *tp extra_args_spec LOCALE_PARAM_PROTO)
 {
 #if defined _LIBC && defined USE_IN_EXTENDED_LOCALE_MODEL
   struct locale_data *const current = loc->__locales[LC_TIME];
@@ -1437,12 +1322,8 @@ libc_hidden_def (my_strftime)
 /* For Emacs we have a separate interface which corresponds to the normal
    strftime function plus the ut argument, but without the ns argument.  */
 size_t
-emacs_strftimeu (s, maxsize, format, tp, ut)
-      char *s;
-      size_t maxsize;
-      const char *format;
-      const struct tm *tp;
-      int ut;
+emacs_strftimeu (char *s, size_t maxsize, const char *format,
+                const struct tm *tp, int ut)
 {
   return my_strftime (s, maxsize, format, tp, ut, 0);
 }
Index: m4/strftime.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/strftime.m4,v
retrieving revision 1.28
diff -p -u -r1.28 strftime.m4
--- m4/strftime.m4      16 Aug 2003 05:38:25 -0000      1.28
+++ m4/strftime.m4      12 Sep 2003 19:20:45 -0000
@@ -1,4 +1,4 @@
-#serial 20
+#serial 21
 
 dnl This macro is intended to be used solely in this file.
 dnl These are the prerequisite macros for GNU's strftime.c replacement.
@@ -7,9 +7,8 @@ AC_DEFUN([_jm_STRFTIME_PREREQS],
  dnl strftime.c uses the underyling system strftime if it exists.
  AC_FUNC_STRFTIME
 
- AC_CHECK_HEADERS_ONCE(limits.h)
- AC_CHECK_FUNCS_ONCE(memcpy mempcpy)
- AC_CHECK_FUNCS(tzset memset)
+ AC_CHECK_FUNCS_ONCE(mempcpy)
+ AC_CHECK_FUNCS(tzset)
 
  # This defines (or not) HAVE_TZNAME and HAVE_TM_ZONE.
  AC_STRUCT_TIMEZONE
@@ -29,7 +28,6 @@ AC_DEFUN([jm_FUNC_GNU_STRFTIME],
  _jm_STRFTIME_PREREQS
 
  AC_REQUIRE([AC_C_CONST])dnl
- AC_REQUIRE([AC_HEADER_STDC])dnl
  AC_CHECK_HEADERS_ONCE(sys/time.h)
  AC_DEFINE([my_strftime], [nstrftime],
    [Define to the name of the strftime replacement function.])




reply via email to

[Prev in Thread] Current Thread [Next in Thread]