egcs patch for including both string.h/strings.h (when safe)

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Sun Aug 30 20:04:00 GMT 1998


	Working on the principle that getting prototypes from system
headers (when they're available) is better than rolling your own, I
wanted to include strings.h for bzero/bcmp/bcopy/index/rindex function
prototypes even if we're getting string.h.

	However since I recall rumors that including both can cause some
platform to choke, I wrote an autoconf macro patterned after
AC_HEADER_TIME to deal with that. 

	The immediate benefit is that most system header prototypes
contain function arguments, whereas the backup prototypes in system.h
don't do so (on purpose.)

	Okay to install?

		--Kaveh

Sun Aug 30 21:28:32 1998  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* aclocal.m4 (GCC_HEADER_STRING): New macro to detect if it is
 	safe to include both string.h and strings.h together.
  	(GCC_NEED_DECLARATION): Test STRING_WITH_STRINGS when deciding
 	which headers to search for function declarations.  Continue to
 	prefer string.h over strings.h when both are not acceptable.

	* acconfig.h (STRING_WITH_STRINGS): Add stub.

	* configure.in: Call GCC_HEADER_STRING.

	* system.h: Test STRING_WITH_STRINGS when deciding which headers
 	to include.  Continue to prefer string.h over strings.h when both
 	are not acceptable.


diff -rup orig/egcs-CVS19980829/gcc/acconfig.h egcs-CVS19980829/gcc/acconfig.h
--- orig/egcs-CVS19980829/gcc/acconfig.h	Sat Aug 29 20:34:23 1998
+++ egcs-CVS19980829/gcc/acconfig.h	Sat Aug 29 22:36:07 1998
@@ -1,3 +1,6 @@
+/* Define if you can safely include both <string.h> and <strings.h>.  */
+#undef STRING_WITH_STRINGS
+
 /* Define if printf supports "%p".  */
 #undef HAVE_PRINTF_PTR
 
diff -rup orig/egcs-CVS19980829/gcc/aclocal.m4 egcs-CVS19980829/gcc/aclocal.m4
--- orig/egcs-CVS19980829/gcc/aclocal.m4	Sat Aug 29 20:34:23 1998
+++ egcs-CVS19980829/gcc/aclocal.m4	Sat Aug 29 22:50:39 1998
@@ -1,3 +1,14 @@
+dnl See whether we can include both string.h and strings.h.
+AC_DEFUN(GCC_HEADER_STRING,
+[AC_CACHE_CHECK([whether string.h and strings.h may both be included],
+  gcc_cv_header_string,
+[AC_TRY_COMPILE([#include <string.h>
+#include <strings.h>], , gcc_cv_header_string=yes, gcc_cv_header_string=no)])
+if test $gcc_cv_header_string = yes; then
+  AC_DEFINE(STRING_WITH_STRINGS)
+fi
+])
+
 dnl See whether we need a declaration for a function.
 dnl GCC_NEED_DECLARATION(FUNCTION [, EXTRA-HEADER-FILES])
 AC_DEFUN(GCC_NEED_DECLARATION,
@@ -5,12 +16,17 @@ AC_DEFUN(GCC_NEED_DECLARATION,
 AC_CACHE_VAL(gcc_cv_decl_needed_$1,
 [AC_TRY_COMPILE([
 #include <stdio.h>
-#ifdef HAVE_STRING_H
-#include <string.h>
+#ifdef STRING_WITH_STRINGS
+# include <string.h>
+# include <strings.h>
 #else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
+# ifdef HAVE_STRING_H
+#  include <string.h>
+# else
+#  ifdef HAVE_STRINGS_H
+#   include <strings.h>
+#  endif
+# endif
 #endif
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
diff -rup orig/egcs-CVS19980829/gcc/configure.in egcs-CVS19980829/gcc/configure.in
--- orig/egcs-CVS19980829/gcc/configure.in	Sat Aug 29 20:34:36 1998
+++ egcs-CVS19980829/gcc/configure.in	Sat Aug 29 22:49:32 1998
@@ -191,6 +191,7 @@ EGCS_PROG_INSTALL
 
 AC_HEADER_STDC
 AC_HEADER_TIME
+GCC_HEADER_STRING
 AC_CHECK_HEADERS(limits.h stddef.h string.h strings.h stdlib.h time.h fcntl.h unistd.h stab.h sys/file.h sys/time.h sys/resource.h sys/param.h sys/times.h wait.h sys/wait.h)
 
 # Check for thread headers.
diff -rup orig/egcs-CVS19980829/gcc/system.h egcs-CVS19980829/gcc/system.h
--- orig/egcs-CVS19980829/gcc/system.h	Sat Aug 29 20:35:46 1998
+++ egcs-CVS19980829/gcc/system.h	Sat Aug 29 22:08:13 1998
@@ -88,11 +88,16 @@
 extern int errno;
 #endif
 
-#ifdef HAVE_STRING_H
+#ifdef STRING_WITH_STRINGS
 # include <string.h>
+# include <strings.h>
 #else
-# ifdef HAVE_STRINGS_H
-#  include <strings.h>
+# ifdef HAVE_STRING_H
+#  include <string.h>
+# else
+#  ifdef HAVE_STRINGS_H
+#   include <strings.h>
+#  endif
 # endif
 #endif
 



More information about the Gcc-patches mailing list