bug-bash
[Top][All Lists]
Advanced

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

[PATCH 4/4] Assume __STDC__ if it merely assumes C89 or later


From: Paul Eggert
Subject: [PATCH 4/4] Assume __STDC__ if it merely assumes C89 or later
Date: Sun, 26 Mar 2023 16:50:07 -0700

There's no longer any point to worrying about K&R compilers
as the code won't work with them anyway.  Simplify the code
by omitting __STDC__ tests when that merely is checking for
C89 or later, as we assume C89 prototypes now.
---
 aclocal.m4                | 15 ---------------
 builtins/enable.def       |  4 ----
 builtins/gen-helpfiles.c  |  4 ----
 builtins/help.def         |  9 +--------
 builtins/printf.def       |  5 -----
 general.h                 |  9 ---------
 hashlib.h                 | 14 +-------------
 include/ansi_stdlib.h     |  8 +-------
 include/ocache.h          |  8 +-------
 include/stdc.h            | 12 ------------
 lib/doc-support/getopt.c  |  4 ----
 lib/doc-support/getopt.h  |  4 ----
 lib/doc-support/getopt1.c |  4 ----
 lib/glob/collsyms.h       |  4 ----
 lib/glob/glob.c           |  8 --------
 lib/intl/explodename.c    |  9 ---------
 lib/readline/history.h    |  4 ----
 lib/readline/xmalloc.h    |  8 +-------
 lib/sh/strtrans.c         | 11 -----------
 lib/sh/vprint.c           |  8 --------
 lib/tilde/tilde.c         |  8 --------
 mksyntax.c                |  5 -----
 support/endian.c          |  4 ----
 xmalloc.c                 |  6 +-----
 xmalloc.h                 |  8 +-------
 25 files changed, 7 insertions(+), 176 deletions(-)

diff --git a/aclocal.m4 b/aclocal.m4
index b8f67e75..5a0fa1fb 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -556,11 +556,6 @@ AC_CACHE_VAL(bash_cv_getenv_redef,
 #  include <unistd.h>
 #endif
 #include <stdlib.h>
-#ifndef __STDC__
-#  ifndef const
-#    define const
-#  endif
-#endif
 char *
 getenv (const char *name)
 {
@@ -600,11 +595,6 @@ AC_CACHE_CHECK([for standard-conformant putenv 
declaration], bash_cv_std_putenv,
 #if HAVE_STDDEF_H
 #include <stddef.h>
 #endif
-#ifndef __STDC__
-#  ifndef const
-#    define const
-#  endif
-#endif
 extern int putenv (char *);
 ]], [[return (putenv == 0);]] )],
 [bash_cv_std_putenv=yes], [bash_cv_std_putenv=no]
@@ -625,11 +615,6 @@ AC_CACHE_CHECK([for standard-conformant unsetenv 
declaration], bash_cv_std_unset
 #if HAVE_STDDEF_H
 #include <stddef.h>
 #endif
-#ifndef __STDC__
-#  ifndef const
-#    define const
-#  endif
-#endif
 extern int unsetenv (const char *);
 ]], [[return (unsetenv == 0);]] )],
 [bash_cv_std_unsetenv=yes], [bash_cv_std_unsetenv=no]
diff --git a/builtins/enable.def b/builtins/enable.def
index e6948bac..f44820b3 100644
--- a/builtins/enable.def
+++ b/builtins/enable.def
@@ -488,11 +488,7 @@ delete_builtin (struct builtin *b)
   struct builtin *new_shell_builtins;
 
   /* XXX - funky pointer arithmetic - XXX */
-#ifdef __STDC__
   ind = b - shell_builtins;
-#else
-  ind = ((int)b - (int)shell_builtins) / sizeof (struct builtin);
-#endif
   size = num_shell_builtins * sizeof (struct builtin);
   new_shell_builtins = (struct builtin *)xmalloc (size);
 
diff --git a/builtins/gen-helpfiles.c b/builtins/gen-helpfiles.c
index 76f7c06b..771e1e45 100644
--- a/builtins/gen-helpfiles.c
+++ b/builtins/gen-helpfiles.c
@@ -72,10 +72,6 @@
 extern int errno;
 #endif
 
-#if !defined (__STDC__) && !defined (strcpy)
-extern char *strcpy ();
-#endif /* !__STDC__ && !strcpy */
-
 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
 
 /* Flag values that builtins can have. */
diff --git a/builtins/help.def b/builtins/help.def
index 293f23de..3b248cdd 100644
--- a/builtins/help.def
+++ b/builtins/help.def
@@ -193,19 +193,12 @@ void
 builtin_help (void)
 {
   int ind;
-  ptrdiff_t d;
 
   current_builtin = builtin_address_internal (this_command_name, 0);
   if (current_builtin == 0)
     return;
 
-  d = current_builtin - shell_builtins;
-
-#if defined (__STDC__)
-  ind = (int)d;
-#else
-  ind = (int)d / sizeof (struct builtin);
-#endif
+  ind = current_builtin - shell_builtins;
 
   printf ("%s: %s\n", this_command_name, _(shell_builtins[ind].short_doc));
   show_longdoc (ind);  
diff --git a/builtins/printf.def b/builtins/printf.def
index 2a6e2658..cbf09039 100644
--- a/builtins/printf.def
+++ b/builtins/printf.def
@@ -1034,12 +1034,7 @@ tescape (char *estart, char *cp, int *lenp, int *sawc)
 
   switch (c = *p++)
     {
-#if defined (__STDC__)
       case 'a': *cp = '\a'; break;
-#else
-      case 'a': *cp = '\007'; break;
-#endif
-
       case 'b': *cp = '\b'; break;
 
       case 'e':
diff --git a/general.h b/general.h
index 2b81f683..f5b1e875 100644
--- a/general.h
+++ b/general.h
@@ -45,15 +45,6 @@
 
 #include "xmalloc.h"
 
-/* NULL pointer type. */
-#if !defined (NULL)
-#  if defined (__STDC__)
-#    define NULL ((void *) 0)
-#  else
-#    define NULL 0x0
-#  endif /* !__STDC__ */
-#endif /* !NULL */
-
 /* Hardly used anymore */
 #define pointer_to_int(x)      (int)((char *)x - (char *)0)
 
diff --git a/hashlib.h b/hashlib.h
index 623ad0aa..0b4126ab 100644
--- a/hashlib.h
+++ b/hashlib.h
@@ -24,11 +24,7 @@
 #include "stdc.h"
 
 #ifndef PTR_T
-#  ifdef __STDC__
-#    define PTR_T void *
-#  else
-#    define PTR_T char *
-#  endif
+# define PTR_T void *
 #endif
 
 typedef struct bucket_contents {
@@ -81,12 +77,4 @@ extern unsigned int hash_string (const char *);
 #define HASH_NOSRCH    0x01
 #define HASH_CREATE    0x02
 
-#if !defined (NULL)
-#  if defined (__STDC__)
-#    define NULL ((void *) 0)
-#  else
-#    define NULL 0x0
-#  endif /* !__STDC__ */
-#endif /* !NULL */
-
 #endif /* _HASHLIB_H */
diff --git a/include/ansi_stdlib.h b/include/ansi_stdlib.h
index 7dc2ee0c..0e5712b9 100644
--- a/include/ansi_stdlib.h
+++ b/include/ansi_stdlib.h
@@ -32,13 +32,7 @@ extern double strtod ();
 /* Memory allocation functions. */
 /* Generic pointer type. */
 #ifndef PTR_T
-
-#if defined (__STDC__)
-#  define PTR_T        void *
-#else
-#  define PTR_T char *
-#endif
-
+# define PTR_T void *
 #endif /* PTR_T */
 
 extern PTR_T malloc ();
diff --git a/include/ocache.h b/include/ocache.h
index c596c272..49a8fdfb 100644
--- a/include/ocache.h
+++ b/include/ocache.h
@@ -22,13 +22,7 @@
 #define        _OCACHE_H_ 1
 
 #ifndef PTR_T
-
-#if defined (__STDC__)
-#  define PTR_T void *
-#else
-#  define PTR_T char *
-#endif
-
+# define PTR_T void *
 #endif /* PTR_T */
 
 #define OC_MEMSET(memp, xch, nbytes)                                   \
diff --git a/include/stdc.h b/include/stdc.h
index 7f6b4b4d..6a82eb7d 100644
--- a/include/stdc.h
+++ b/include/stdc.h
@@ -34,12 +34,6 @@
 #if !defined (__STDC__)
 
 #if defined (__GNUC__)         /* gcc with -traditional */
-#  if !defined (signed)
-#    define signed __signed
-#  endif
-#  if !defined (volatile)
-#    define volatile __volatile
-#  endif
 #  if !defined (restrict)
 #    define restrict __restrict
 #  endif
@@ -47,12 +41,6 @@
 #  if !defined (inline)
 #    define inline
 #  endif
-#  if !defined (signed)
-#    define signed
-#  endif
-#  if !defined (volatile)
-#    define volatile
-#  endif
 #  if !defined (restrict)
 #    define restrict
 #  endif
diff --git a/lib/doc-support/getopt.c b/lib/doc-support/getopt.c
index 802f0e3d..63a16b69 100644
--- a/lib/doc-support/getopt.c
+++ b/lib/doc-support/getopt.c
@@ -42,10 +42,6 @@ char *alloca ();
 #endif /* alloca.h */
 #endif /* not __GNUC__ */
 
-#if !__STDC__ && !defined(const) && IN_GCC
-#define const
-#endif
-
 /* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.  */
 #ifndef _NO_PROTO
 #define _NO_PROTO
diff --git a/lib/doc-support/getopt.h b/lib/doc-support/getopt.h
index 009e1629..1e316328 100644
--- a/lib/doc-support/getopt.h
+++ b/lib/doc-support/getopt.h
@@ -79,11 +79,7 @@ extern int optopt;
 
 struct option
 {
-#if    __STDC__
   const char *name;
-#else
-  char *name;
-#endif
   /* has_arg can't be an enum because some compilers complain about
      type mismatches in all the code that assumes it is an int.  */
   int has_arg;
diff --git a/lib/doc-support/getopt1.c b/lib/doc-support/getopt1.c
index f51e6c00..99ecb364 100644
--- a/lib/doc-support/getopt1.c
+++ b/lib/doc-support/getopt1.c
@@ -24,10 +24,6 @@
 
 #include "getopt.h"
 
-#if !__STDC__ && !defined(const) && IN_GCC
-#define const
-#endif
-
 #include <stdio.h>
 
 /* Comment out all this code if we are using the GNU C Library, and are not
diff --git a/lib/glob/collsyms.h b/lib/glob/collsyms.h
index d56df611..2584750c 100644
--- a/lib/glob/collsyms.h
+++ b/lib/glob/collsyms.h
@@ -38,11 +38,7 @@ static __COLLSYM POSIXCOLL [] =
        {  L("EOT"),                    L('\004') },
        {  L("ENQ"),                    L('\005') },
        {  L("ACK"),                    L('\006') },
-#ifdef __STDC__
        {  L("alert"),                  L('\a') },
-#else
-       {  L("alert"),                  L('\007') },
-#endif
        {  L("BS"),                     L('\010') },
        {  L("backspace"),              L('\b') },
        {  L("HT"),                     L('\011') },
diff --git a/lib/glob/glob.c b/lib/glob/glob.c
index 4f7b746b..0dba65b7 100644
--- a/lib/glob/glob.c
+++ b/lib/glob/glob.c
@@ -60,14 +60,6 @@
 #  define bcopy(s, d, n) ((void) memcpy ((d), (s), (n)))
 #endif /* !HAVE_BCOPY && !bcopy */
 
-#if !defined (NULL)
-#  if defined (__STDC__)
-#    define NULL ((void *) 0)
-#  else
-#    define NULL 0x0
-#  endif /* __STDC__ */
-#endif /* !NULL */
-
 #if !defined (FREE)
 #  define FREE(x)      if (x) free (x)
 #endif
diff --git a/lib/intl/explodename.c b/lib/intl/explodename.c
index adc36402..7e228abd 100644
--- a/lib/intl/explodename.c
+++ b/lib/intl/explodename.c
@@ -29,15 +29,6 @@
 
 #include "loadinfo.h"
 
-/* On some strange systems still no definition of NULL is found.  Sigh!  */
-#ifndef NULL
-# if defined __STDC__ && __STDC__
-#  define NULL ((void *) 0)
-# else
-#  define NULL 0
-# endif
-#endif
-
 /* @@ end of prolog @@ */
 
 char *
diff --git a/lib/readline/history.h b/lib/readline/history.h
index 9c2b0990..49e1bf29 100644
--- a/lib/readline/history.h
+++ b/lib/readline/history.h
@@ -36,11 +36,7 @@ extern "C" {
 #  include <readline/rltypedefs.h>
 #endif
 
-#ifdef __STDC__
 typedef void *histdata_t;
-#else
-typedef char *histdata_t;
-#endif
 
 /* Let's not step on anyone else's define for now, since we don't use this 
yet. */
 #ifndef HS_HISTORY_VERSION
diff --git a/lib/readline/xmalloc.h b/lib/readline/xmalloc.h
index 0fb9df9c..c5cb5602 100644
--- a/lib/readline/xmalloc.h
+++ b/lib/readline/xmalloc.h
@@ -29,13 +29,7 @@
 #endif
 
 #ifndef PTR_T
-
-#ifdef __STDC__
-#  define PTR_T        void *
-#else
-#  define PTR_T        char *
-#endif
-
+# define PTR_T void *
 #endif /* !PTR_T */
 
 extern PTR_T xmalloc (size_t);
diff --git a/lib/sh/strtrans.c b/lib/sh/strtrans.c
index daff6a5f..d3b27f3b 100644
--- a/lib/sh/strtrans.c
+++ b/lib/sh/strtrans.c
@@ -95,13 +95,8 @@ ansicstr (const char *string, size_t len, int flags, int 
*sawc, size_t *rlen)
        {
          switch (c = *s++)
            {
-#if defined (__STDC__)
            case 'a': c = '\a'; break;
            case 'v': c = '\v'; break;
-#else
-           case 'a': c = (int) 0x07; break;
-           case 'v': c = (int) 0x0B; break;
-#endif
            case 'b': c = '\b'; break;
            case 'e': case 'E':         /* ESC -- non-ANSI */
              c = ESC; break;
@@ -257,14 +252,8 @@ ansic_quote (const char *str, int flags, int *rlen)
       switch (c)
        {
        case ESC: c = 'E'; break;
-#ifdef __STDC__
        case '\a': c = 'a'; break;
        case '\v': c = 'v'; break;
-#else
-       case 0x07: c = 'a'; break;
-       case 0x0b: c = 'v'; break;
-#endif
-
        case '\b': c = 'b'; break;
        case '\f': c = 'f'; break;
        case '\n': c = 'n'; break;
diff --git a/lib/sh/vprint.c b/lib/sh/vprint.c
index b4c09e89..6caac0d4 100644
--- a/lib/sh/vprint.c
+++ b/lib/sh/vprint.c
@@ -24,14 +24,6 @@
 
 #include <stdio.h>
 
-#if !defined (NULL)
-#  if defined (__STDC__)
-#    define NULL ((void *)0)
-#  else
-#    define NULL 0x0
-#  endif /* __STDC__ */
-#endif /* !NULL */
-
 /*
  * Beware!  Don't trust the value returned by either of these functions; it
  * seems that pre-4.3-tahoe implementations of _doprnt () return the first
diff --git a/lib/tilde/tilde.c b/lib/tilde/tilde.c
index 84137c00..16e13553 100644
--- a/lib/tilde/tilde.c
+++ b/lib/tilde/tilde.c
@@ -68,14 +68,6 @@ extern struct passwd *getpwnam (const char *);
 #define savestring(x) strcpy ((char *)xmalloc (1 + strlen (x)), (x))
 #endif /* !savestring */
 
-#if !defined (NULL)
-#  if defined (__STDC__)
-#    define NULL ((void *) 0)
-#  else
-#    define NULL 0x0
-#  endif /* !__STDC__ */
-#endif /* !NULL */
-
 /* If being compiled as part of bash, these will be satisfied from
    variables.o.  If being compiled as part of readline, they will
    be satisfied from shell.o. */
diff --git a/mksyntax.c b/mksyntax.c
index effbe7c8..667fbc7c 100644
--- a/mksyntax.c
+++ b/mksyntax.c
@@ -128,13 +128,8 @@ cdesc (int i)
     
   switch (i)
     {
-#ifdef __STDC__
     case '\a': xbuf[1] = 'a'; break;
     case '\v': xbuf[1] = 'v'; break;
-#else
-    case '\007': xbuf[1] = 'a'; break;
-    case 0x0B: xbuf[1] = 'v'; break;
-#endif
     case '\b': xbuf[1] = 'b'; break;
     case '\f': xbuf[1] = 'f'; break;
     case '\n': xbuf[1] = 'n'; break;
diff --git a/support/endian.c b/support/endian.c
index 27f5b125..7fecc57f 100644
--- a/support/endian.c
+++ b/support/endian.c
@@ -42,11 +42,7 @@ char nstring[9];
 int
 main (int argc, char **argv)
 {
-#if defined (__STDC__)
   register size_t i;
-#else
-  register int i;
-#endif /* !__STDC__ */
   FILE *stream = (FILE *)NULL;
   char *stream_name = "stdout";
   union {
diff --git a/xmalloc.c b/xmalloc.c
index aee8a492..3949cf02 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -40,11 +40,7 @@
 #include "bashintl.h"
 
 #if !defined (PTR_T)
-#  if defined (__STDC__)
-#    define PTR_T void *
-#  else
-#    define PTR_T char *
-#  endif /* !__STDC__ */
+# define PTR_T void *
 #endif /* !PTR_T */
 
 #if HAVE_SBRK && !HAVE_DECL_SBRK
diff --git a/xmalloc.h b/xmalloc.h
index 84edcc31..383a9a82 100644
--- a/xmalloc.h
+++ b/xmalloc.h
@@ -26,13 +26,7 @@
 
 /* Generic pointer type. */
 #ifndef PTR_T
-
-#if defined (__STDC__)
-#  define PTR_T        void *
-#else
-#  define PTR_T char *
-#endif
-
+# define PTR_T void *
 #endif /* PTR_T */
 
 /* Allocation functions in xmalloc.c */
-- 
2.39.2




reply via email to

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