This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: A protoype patch for cccp.c (really, strerror patch)
- To: law at cygnus dot com
- Subject: Re: A protoype patch for cccp.c (really, strerror patch)
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Fri, 26 Jun 1998 10:49:21 -0400 (EDT)
- Cc: egcs-patches at cygnus dot com
> From: Jeffrey A Law <law@hurl.cygnus.com>
>
> In message <199806220055.UAA27556@caip.rutgers.edu>you write:
> > > From: hjl@lucon.org (H.J. Lu)
> > > Here is another patch.
> > > ---
> > > Sat Jun 20 09:08:15 1998 H.J. Lu (hjl@gnu.org)
> > >
> > > * cccp.c (strerror): Add prototype.
> >
> > Should this code consolidate and move to system.h? Also,
> > should we check GCC_NEED_DECLARATION(strerror)? (Is one of the headers
> > checked by that autoconf macro the "standard" home for the strerror decl?)
>
> I think it would be a good idea. Right now we've got a strerror
> decl as well as a my_strerror function in the following files:
>
> cccp.c
> collect2.c
> cpplib.c
> gcc.c
> protoize.c
>
> Some of the various my_strerror definitions are slightly different --
> some have VMS conditionals, others do not. It's somewhat of a mess.
> jeff
Here a patch to check if strerror, getcwd and getwd need
declarations. I also moved extern decls for sys_nerr/sys_errlist to
system.h. In the process, I nuked VMS's special strerror decl hoping
that it already has one in string.h or the no-argument one will serve.
(VMS guys, let me know if this breaks anything.)
I left the my_strerror function definitions untouched, one day
libiberty will be used instead.
I explicitly decided NOT to put a getpwd decl in system.h.
Getpwd is not a system OS thing, nor is it autoconf based. Its a part
of gcc, and comes from getpwd.c. Therefore IMHO it should be declared
as it is now in each file, or to be really clean and thorough, in a
new file getpwd.h.
--Kaveh
Wed Jun 24 10:35:13 1998 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* configure.in (GCC_NEED_DECLARATIONS): Add strerror, getcwd and
getwd.
* acconfig.m4: Add stubs for NEED_DECLARATION_STRERROR,
NEED_DECLARATION_GETCWD and NEED_DECLARATION_GETWD.
* cccp.c: Remove strerror()/sys_nerr/sys_errlist decls.
(my_strerror): Add prototype and make it static.
* collect2.c: Likewise.
* cpplib.c: Likewise.
* gcc.c: Likewise, but keep `my_strerror' extern.
* protoize.c: Likewise.
* pexecute.c (my_strerror): Add argument to prototype.
* system.h: Add prototypes for getcwd, getwd and strerror. Add
extern decls for sys_nerr and sys_errlist. Make abort decl
explicitly extern.
* getpwd.c: Remove decls for getwd and getcwd.
diff -rup orig/egcs-CVS19980623/gcc/configure.in egcs-CVS19980623/gcc/configure.in
--- orig/egcs-CVS19980623/gcc/configure.in Tue Jun 23 09:56:09 1998
+++ egcs-CVS19980623/gcc/configure.in Tue Jun 23 13:13:55 1998
@@ -200,7 +200,7 @@ GCC_FUNC_VFPRINTF_DOPRNT
GCC_FUNC_PRINTF_PTR
GCC_NEED_DECLARATIONS(malloc realloc calloc free bcopy bzero bcmp \
- index rindex getenv atol sbrk abort atof)
+ index rindex getenv atol sbrk abort atof strerror getcwd getwd)
AC_DECL_SYS_SIGLIST
diff -rup orig/egcs-CVS19980623/gcc/acconfig.h egcs-CVS19980623/gcc/acconfig.h
--- orig/egcs-CVS19980623/gcc/acconfig.h Wed Jun 24 12:09:08 1998
+++ egcs-CVS19980623/gcc/acconfig.h Wed Jun 24 12:10:18 1998
@@ -55,4 +55,13 @@
/* Whether abort must be declared even if <stdlib.h> is included. */
#undef NEED_DECLARATION_ABORT
+
+/* Whether strerror must be declared even if <string.h> is included. */
+#undef NEED_DECLARATION_STRERROR
+
+/* Whether getcwd must be declared even if <unistd.h> is included. */
+#undef NEED_DECLARATION_GETCWD
+
+/* Whether getwd must be declared even if <unistd.h> is included. */
+#undef NEED_DECLARATION_GETWD
@TOP@
diff -rup orig/egcs-CVS19980623/gcc/cccp.c egcs-CVS19980623/gcc/cccp.c
--- orig/egcs-CVS19980623/gcc/cccp.c Tue Jun 23 09:56:05 1998
+++ egcs-CVS19980623/gcc/cccp.c Tue Jun 23 13:02:05 1998
@@ -138,16 +138,6 @@ static int hack_vms_include_specificatio
extern char *version_string;
extern char *update_path PROTO((char *, char *));
-#ifndef VMS
-#ifndef HAVE_STRERROR
-extern int sys_nerr;
-extern char *sys_errlist[];
-#else /* HAVE_STRERROR */
-char *strerror ();
-#endif
-#else /* VMS */
-char *strerror (int,...);
-#endif
HOST_WIDE_INT parse_escape PROTO((char **, HOST_WIDE_INT));
HOST_WIDE_INT parse_c_expression PROTO((char *, int));
@@ -1003,7 +993,7 @@ static int discard_comments PROTO((U_CHA
static int change_newlines PROTO((U_CHAR *, int));
-char *my_strerror PROTO((int));
+static char *my_strerror PROTO((int));
void error PRINTF_PROTO_1((char *, ...));
static void verror PROTO((char *, va_list));
static void error_from_errno PROTO((char *));
@@ -8873,7 +8863,7 @@ change_newlines (start, length)
/* my_strerror - return the descriptive text associated with an
`errno' code. */
-char *
+static char *
my_strerror (errnum)
int errnum;
{
diff -rup orig/egcs-CVS19980623/gcc/collect2.c egcs-CVS19980623/gcc/collect2.c
--- orig/egcs-CVS19980623/gcc/collect2.c Tue Jun 23 09:56:06 1998
+++ egcs-CVS19980623/gcc/collect2.c Tue Jun 23 13:09:12 1998
@@ -39,13 +39,6 @@ Boston, MA 02111-1307, USA. */
#include <process.h>
#endif
-#ifndef HAVE_STRERROR
-extern char *sys_errlist[];
-extern int sys_nerr;
-#else
-char *strerror();
-#endif
-
/* Obstack allocation and deallocation routines. */
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
@@ -278,6 +271,7 @@ static struct path_prefix *libpaths[3] =
static char *libexts[3] = {"a", "so", NULL}; /* possible library extentions */
#endif
+static char *my_strerror PROTO((int));
static void handler PROTO((int));
static int is_ctor_dtor PROTO((char *));
static char *find_a_file PROTO((struct path_prefix *, char *));
@@ -336,7 +330,7 @@ dup2 (oldfd, newfd)
}
#endif
-char *
+static char *
my_strerror (e)
int e;
{
diff -rup orig/egcs-CVS19980623/gcc/cpplib.c egcs-CVS19980623/gcc/cpplib.c
--- orig/egcs-CVS19980623/gcc/cpplib.c Tue Jun 23 09:56:12 1998
+++ egcs-CVS19980623/gcc/cpplib.c Tue Jun 23 13:03:30 1998
@@ -203,6 +203,7 @@ struct cpp_pending {
char *xmalloc ();
extern void cpp_hash_cleanup PARAMS ((cpp_reader *));
+static char *my_strerror PROTO ((int));
static void add_import PROTO ((cpp_reader *, int, char *));
static void append_include_chain PROTO ((cpp_reader *,
struct file_name_list *,
@@ -7599,21 +7600,10 @@ cpp_pedwarn_with_file_and_line VPROTO ((
va_end(ap);
}
-#ifndef VMS
-#ifndef HAVE_STRERROR
-extern int sys_nerr;
-extern char *sys_errlist[];
-#else /* HAVE_STRERROR */
-char *strerror ();
-#endif
-#else /* VMS */
-char *strerror (int,...);
-#endif
-
/* my_strerror - return the descriptive text associated with an
`errno' code. */
-char *
+static char *
my_strerror (errnum)
int errnum;
{
diff -rup orig/egcs-CVS19980623/gcc/gcc.c egcs-CVS19980623/gcc/gcc.c
--- orig/egcs-CVS19980623/gcc/gcc.c Tue Jun 23 09:56:23 1998
+++ egcs-CVS19980623/gcc/gcc.c Tue Jun 23 13:05:12 1998
@@ -122,13 +122,7 @@ static char dir_separator_str[] = {DIR_S
#endif
extern char *choose_temp_base PROTO((void));
-
-#ifndef HAVE_STRERROR
-extern int sys_nerr;
-extern char *sys_errlist[];
-#else
-extern char *strerror();
-#endif
+extern char *my_strerror PROTO((int));
#ifndef HAVE_KILL
#define kill(p,s) raise(s)
diff -rup orig/egcs-CVS19980623/gcc/protoize.c egcs-CVS19980623/gcc/protoize.c
--- orig/egcs-CVS19980623/gcc/protoize.c Tue Jun 23 09:57:01 1998
+++ egcs-CVS19980623/gcc/protoize.c Tue Jun 23 13:06:51 1998
@@ -93,13 +93,6 @@ Boston, MA 02111-1307, USA. */
#include "getopt.h"
#undef getopt
-#ifndef HAVE_STRERROR
-extern int sys_nerr;
-extern char *sys_errlist[];
-#else
-extern char *strerror();
-#endif
-
extern char *version_string;
/* Systems which are compatible only with POSIX 1003.1-1988 (but *not*
@@ -123,6 +116,7 @@ extern char *version_string;
extern char *getpwd ();
extern char *choose_temp_base PROTO ((void));
+extern char * my_strerror PROTO ((int));
extern int pexecute PROTO ((const char *, char * const *, const char *,
const char *, char **, char **, int));
diff -rup orig/egcs-CVS19980623/gcc/pexecute.c egcs-CVS19980623/gcc/pexecute.c
--- orig/egcs-CVS19980623/gcc/pexecute.c Tue Jun 23 09:57:00 1998
+++ egcs-CVS19980623/gcc/pexecute.c Tue Jun 23 13:00:00 1998
@@ -637,7 +637,7 @@ pfinish ()
extern int execv ();
extern int execvp ();
#ifdef IN_GCC
-extern char * my_strerror();
+extern char * my_strerror PROTO ((int));
#endif
int
diff -rup orig/egcs-CVS19980623/gcc/system.h egcs-CVS19980623/gcc/system.h
--- orig/egcs-CVS19980623/gcc/system.h Tue Jun 23 09:57:08 1998
+++ egcs-CVS19980623/gcc/system.h Tue Jun 23 13:15:45 1998
@@ -202,14 +202,33 @@ extern long atol();
extern void free ();
#endif
+#ifdef NEED_DECLARATION_GETCWD
+extern char *getcwd ();
+#endif
+
#ifdef NEED_DECLARATION_GETENV
extern char *getenv ();
#endif
+#ifdef NEED_DECLARATION_GETWD
+extern char *getwd ();
+#endif
+
#ifdef NEED_DECLARATION_SBRK
extern char *sbrk ();
#endif
+#ifdef HAVE_STRERROR
+# ifdef NEED_DECLARATION_STRERROR
+# ifndef strerror
+extern char *strerror ();
+# endif
+# endif
+#else /* ! HAVE_STRERROR */
+extern int sys_nerr;
+extern char *sys_errlist[];
+#endif /* HAVE_STRERROR */
+
/* HAVE_VOLATILE only refers to the stage1 compiler. We also check
__STDC__ and assume gcc sets it and has volatile in stage >=2. */
#if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
@@ -229,7 +248,7 @@ extern char *sbrk ();
#ifdef USE_SYSTEM_ABORT
# ifdef NEED_DECLARATION_ABORT
-void abort ();
+extern void abort ();
# endif
#else
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
diff -rup orig/egcs-CVS19980623/gcc/getpwd.c egcs-CVS19980623/gcc/getpwd.c
--- orig/egcs-CVS19980623/gcc/getpwd.c Tue Jun 23 09:56:50 1998
+++ egcs-CVS19980623/gcc/getpwd.c Tue Jun 23 13:16:40 1998
@@ -9,7 +9,6 @@
the few exceptions to the general rule here. */
#if !(defined (POSIX) || defined (USG) || defined (VMS)) || defined (HAVE_GETWD)
-extern char *getwd ();
#define getcwd(buf,len) getwd(buf)
#ifdef MAXPATHLEN
#define GUESSPATHLEN (MAXPATHLEN + 1)
@@ -17,7 +16,6 @@ extern char *getwd ();
#define GUESSPATHLEN 100
#endif
#else /* (defined (USG) || defined (VMS)) */
-extern char *getcwd ();
/* We actually use this as a starting point, not a limit. */
#define GUESSPATHLEN 100
#endif /* (defined (USG) || defined (VMS)) */
diff -rup orig/egcs-CVS19980623/gcc/config.in egcs-CVS19980623/gcc/config.in
--- orig/egcs-CVS19980623/gcc/config.in Wed Jun 24 12:05:42 1998
+++ egcs-CVS19980623/gcc/config.in Wed Jun 24 12:10:51 1998
@@ -57,6 +57,15 @@
/* Whether abort must be declared even if <stdlib.h> is included. */
#undef NEED_DECLARATION_ABORT
+/* Whether strerror must be declared even if <string.h> is included. */
+#undef NEED_DECLARATION_STRERROR
+
+/* Whether getcwd must be declared even if <unistd.h> is included. */
+#undef NEED_DECLARATION_GETCWD
+
+/* Whether getwd must be declared even if <unistd.h> is included. */
+#undef NEED_DECLARATION_GETWD
+
/* Define if you don't have vprintf but do have _doprnt. */
#undef HAVE_DOPRNT
diff -rup orig/egcs-CVS19980623/gcc/configure egcs-CVS19980623/gcc/configure
--- orig/egcs-CVS19980623/gcc/configure Wed Jun 24 12:05:42 1998
+++ egcs-CVS19980623/gcc/configure Wed Jun 24 12:10:35 1998
@@ -1948,7 +1948,7 @@ fi
for ac_func in malloc realloc calloc free bcopy bzero bcmp \
- index rindex getenv atol sbrk abort atof
+ index rindex getenv atol sbrk abort atof strerror getcwd getwd
do
echo $ac_n "checking whether $ac_func must be declared""... $ac_c" 1>&6
echo "configure:1955: checking whether $ac_func must be declared" >&5