This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Generate string.h and time.h if nonexistent; kill POSIX


On Tue, May 08, 2001 at 11:31:26AM -0400, Kaveh R. Ghazi wrote:
>  > From: "Zack Weinberg" <zackw@Stanford.EDU>
>  > 
>  > On Tue, May 01, 2001 at 11:50:11AM -0400, Kaveh R. Ghazi wrote:
>  > > 
>  > > IIRC, some platform's sys/time.h required including sys/types.h
>  > > beforehand.
...
>  > I'm nervous about this.  This header will be used by tsystem.h
>  > which already includes sys/types.h.  What if it's not safe to
>  > include sys/types.h twice?  I don't think fixincludes/fixproto try
>  > to add MI guards to headers that lack them.
> 
> Well, I can offer examples where we include it twice and have not seen
> any problems in practice.  E.g. system.h + cpplib.h both include
> sys/types.h, so IMHO its safe.

That's good enough for me.  Revised patch for fixproto appended.

> Do you have access to any system that is actually missing time.h where
> this would come up?  We might be wasting time over a moot point. :-)

Unless Stanford's got a cluster of old machines that I don't know
about, I have no access to any machine with a pre-C89 library.  Maybe
John Anglin can shed some light?

-- 
zw       One can't, of course, perform Kaspar Hauser experiments on the
         offspring of one's conspecifics.
         	-- Jerry Fodor, _The Mind Doesn't Work That Way_


===================================================================
Index: fixproto
--- fixproto	2001/01/27 21:07:57	1.11
+++ fixproto	2001/05/11 17:23:52
@@ -133,13 +133,6 @@ if [ `echo $* | wc -w` != 0 ] ; then
   done
 fi
 
-required_stdlib_h="abort abs atexit atof atoi atol bsearch calloc exit free getenv labs malloc putenv qsort rand realloc srand strtod strtol strtoul system"
-# "div ldiv", - ignored because these depend on div_t, ldiv_t
-# ignore these: "mblen mbstowcs mbstowc wcstombs wctomb"
-# Left out getgroups, because SunOS4 has incompatible BSD and SVR4 versions.
-# Should perhaps also add NULL
-required_unistd_h="_exit access alarm chdir chown close ctermid cuserid dup dup2 execl execle execlp execv execve execvp fork fpathconf getcwd getegid geteuid getgid getlogin getopt getpgrp getpid getppid getuid isatty link lseek pathconf pause pipe read rmdir setgid setpgid setsid setuid sleep sysconf tcgetpgrp tcsetpgrp ttyname unlink write"
-
 done_dirs=""
 subdirs_made=""
 echo "" >fixproto.list
@@ -283,27 +276,61 @@ done
 
 # This might be more cleanly moved into the main loop, by adding
 # a <dummy> source directory at the end.  FIXME!
-for rel_source_file in unistd.h stdlib.h
+# All the headers we create define size_t and NULL.
+for rel_source_file in unistd.h stdlib.h string.h time.h
 do
-  if grep "$rel_source_file" fixproto.list >/dev/null
-  then true
+  if grep "^$rel_source_file\$" fixproto.list >/dev/null
+  then : Nothing to do
   else
     echo Adding missing $rel_source_file
     rel_source_ident=`echo $rel_source_file | tr ./ __`
-    required_list=`eval echo '${required_'${rel_source_ident}'-}'`
     cat >tmp.h <<EOF
+/* Fake ${rel_source_file}, created by GCC.
+   The functions declared in this file do not necessarily exist in
+   your C library.  */
 #ifndef __${rel_source_ident}
 #define __${rel_source_ident}
-EOF
-    if test $rel_source_file = stdlib.h
-    then
-      # Make sure it contains a definition of size_t.
-      cat >>tmp.h <<EOF
 
+#define __need_NULL
 #define __need_size_t
 #include <stddef.h>
+EOF
+    case $rel_source_file in
+	stdlib.h)
+	# If we have to create this file, the wide functions don't exist,
+	# so there is no point defining wchar_t.
+	# We make no attempt to define div_t or ldiv_t, which are only useful
+	# with more functions that don't exist.
+	cat >>tmp.h <<EOF
+
+#define EXIT_FAILURE 1
+#define EXIT_SUCCESS 0
+#define RAND_MAX (~0)	/* best guess */
 EOF
-    fi
+	;;
+	time.h)
+	# If time.h doesn't exist, find out if sys/time.h does.
+	if test -f $src_dir_std/sys/time.h \
+	   || grep "sys/time.h" fixproto.list >/dev/null
+	then
+	# It does, so include it and hope it has the appropriate
+	# type declarations.  Some versions require sys/types.h.
+	echo '#include <sys/types.h>' >>tmp.h
+	echo '#include <sys/time.h>' >>tmp.h
+	else
+	# We're up a creek.  Make some plausible definitions for
+	# time_t and clock_t.  Forward-declare struct tm and hope
+	# no one tries to use it (odds are the system doesn't have
+	# localtime/gmtime/mktime either, so it's not so bad).
+	cat >>tmp.h <<EOF
+
+typedef long time_t;
+typedef long clock_t;
+struct tm;
+EOF
+	fi;;
+    esac
+
     cat >>tmp.h <<EOF
 
 #endif /* __${rel_source_ident} */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]