changeset 15538:9fd857e43955

Avoid endless recursions if config.h includes some header files. * lib/fopen.c (__need_FILE): Define already before including config.h. * lib/freopen.c (__need_FILE): Likewise. * lib/open.c (__need_system_fcntl_h): Likewise. * lib/stat.c (__need_system_sys_stat_h): Likewise. * lib/lstat.c (__need_system_sys_stat_h): Likewise. Reported by Michael Goffioul <michael.goffioul@gmail.com>.
author Bruno Haible <bruno@clisp.org>
date Tue, 30 Aug 2011 09:57:33 +0200
parents df0449fa9650
children 4a8142321d8c
files ChangeLog lib/fopen.c lib/freopen.c lib/lstat.c lib/open.c lib/stat.c
diffstat 6 files changed, 31 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-08-30  Bruno Haible  <bruno@clisp.org>
+
+	Avoid endless recursions if config.h includes some header files.
+	* lib/fopen.c (__need_FILE): Define already before including config.h.
+	* lib/freopen.c (__need_FILE): Likewise.
+	* lib/open.c (__need_system_fcntl_h): Likewise.
+	* lib/stat.c (__need_system_sys_stat_h): Likewise.
+	* lib/lstat.c (__need_system_sys_stat_h): Likewise.
+	Reported by Michael Goffioul <michael.goffioul@gmail.com>.
+
 2011-08-25  Karl Berry  <karl@gnu.org>
 
 	* config/srclist.txt (ylwrap): new try.
--- a/lib/fopen.c
+++ b/lib/fopen.c
@@ -16,10 +16,13 @@
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
 
+/* If the user's config.h happens to include <stdio.h>, let it include only
+   the system's <stdio.h> here, so that orig_fopen doesn't recurse to
+   rpl_fopen.  */
+#define __need_FILE
 #include <config.h>
 
 /* Get the original definition of fopen.  It might be defined as a macro.  */
-#define __need_FILE
 #include <stdio.h>
 #undef __need_FILE
 
--- a/lib/freopen.c
+++ b/lib/freopen.c
@@ -16,10 +16,13 @@
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
 
+/* If the user's config.h happens to include <stdio.h>, let it include only
+   the system's <stdio.h> here, so that orig_freopen doesn't recurse to
+   rpl_freopen.  */
+#define __need_FILE
 #include <config.h>
 
 /* Get the original definition of freopen.  It might be defined as a macro.  */
-#define __need_FILE
 #include <stdio.h>
 #undef __need_FILE
 
--- a/lib/lstat.c
+++ b/lib/lstat.c
@@ -17,6 +17,10 @@
 
 /* written by Jim Meyering */
 
+/* If the user's config.h happens to include <sys/stat.h>, let it include only
+   the system's <sys/stat.h> here, so that orig_lstat doesn't recurse to
+   rpl_lstat.  */
+#define __need_system_sys_stat_h
 #include <config.h>
 
 #if !HAVE_LSTAT
@@ -27,7 +31,6 @@
 #else /* HAVE_LSTAT */
 
 /* Get the original definition of lstat.  It might be defined as a macro.  */
-# define __need_system_sys_stat_h
 # include <sys/types.h>
 # include <sys/stat.h>
 # undef __need_system_sys_stat_h
--- a/lib/open.c
+++ b/lib/open.c
@@ -16,13 +16,16 @@
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
 
+/* If the user's config.h happens to include <fcntl.h>, let it include only
+   the system's <fcntl.h> here, so that orig_open doesn't recurse to
+   rpl_open.  */
+#define __need_system_fcntl_h
 #include <config.h>
 
 /* Get the original definition of open.  It might be defined as a macro.  */
-#define __need_system_fcntl_h
 #include <fcntl.h>
+#include <sys/types.h>
 #undef __need_system_fcntl_h
-#include <sys/types.h>
 
 static inline int
 orig_open (const char *filename, int flags, mode_t mode)
--- a/lib/stat.c
+++ b/lib/stat.c
@@ -16,10 +16,13 @@
 
 /* written by Eric Blake */
 
+/* If the user's config.h happens to include <sys/stat.h>, let it include only
+   the system's <sys/stat.h> here, so that orig_stat doesn't recurse to
+   rpl_stat.  */
+#define __need_system_sys_stat_h
 #include <config.h>
 
 /* Get the original definition of stat.  It might be defined as a macro.  */
-#define __need_system_sys_stat_h
 #include <sys/types.h>
 #include <sys/stat.h>
 #undef __need_system_sys_stat_h