]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Portability: Provide stdio wrappers for 64-bit in cstdio C++ builds
authorFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 6 Apr 2011 13:58:14 +0000 (01:58 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 6 Apr 2011 13:58:14 +0000 (01:58 +1200)
stdio.h in that case on provides fgetpos64, fopen64 if
__USE_FILE_OFFSET64 is defined. It then checks whether a gcc-specific
 __REDIRECT macro is available (defined in sys/cdefs.h, depending on
__GNUC__ begin available).

If it is not available, it does a preprocessor #define.

Which <cstdio> undefines, with this comment:
 "// Get rid of those macros defined in <stdio.h> in lieu of real functions.".
When it does a namespace redirection ("namespace std { using ::fgetpos; }")
it goes blam, as fgetpos64 is available, while fgetpos is not.

To fix it, we need to supply global functions matching those
signatures (not macros).

e.g.

#include <stdio.h>
#if defined(__USE_FILE_OFFSET64) &&!defined(__REDIRECT) && defined(fgetpos)
#undef fgetpos
int fgetpos (FILE * f, fpos64_t *p) { return fgetpos64(f,p); }
#endif
#include <cstdio>

This every time we use <cstdio> (directly or indirectly).

This is triggered by us defining -D_FILE_OFFSET_BITS=64 when
--enable-large-files configure is used.

compat/GnuRegex.c
compat/Makefile.am
compat/assert.cc
compat/compat.h
compat/debug.h
compat/eui64_aton.c
compat/getnameinfo.c
compat/inet_ntop.c
compat/stdio.h [new file with mode: 0644]
compat/tempnam.c

index 3bfa598942fa3e011b62b25d06d594f3305fecf4..5a15f2e2b9999479b414e514c3ac12e12981685b 100644 (file)
@@ -452,12 +452,6 @@ unsigned char **source;
 
 #ifdef DEBUG
 
-/* We use standard I/O for debugging.  */
-#include <stdio.h>
-
-/* It is useful to test things that ``must'' be true when debugging.  */
-#include <assert.h>
-
 static int debug = 0;
 
 #define DEBUG_STATEMENT(e) e
index 671c5106d1d0ab293290b0625e9ae5f262380cb6..fc8238350e0bc731b880ce690fe6ad5eb13f3cca 100644 (file)
@@ -31,6 +31,7 @@ libcompat_squid_a_SOURCES = \
        initgroups.h \
        osdetect.h \
        psignal.h \
+       stdio.h \
        stdvarargs.h \
        strnstr.cc \
        strsep.h \
index 65bcbbb0f5d6339cf107781d9e7cec5be239f875..c9d32799b400df3f489e9ad8f5ccdb74b6012cc9 100644 (file)
 
 #include "config.h"
 
-#if HAVE_STDIO_H
-#include <stdio.h>
-#endif
-
-#if 0
-#include "compat/assert.h"
-#endif
-
 void xassert(const char *expr, const char *file, int line)
 {
     fprintf(stderr, "assertion failed: %s:%d: \"%s\"\n", file, line, expr);
index cb28156b48cd78ae0ed72fef28638ece529783cd..e1de846f5b6dc60b7577e654faf645ecd7a6eab4 100644 (file)
@@ -86,6 +86,9 @@
 #include "compat/stdvarargs.h"
 #include "compat/assert.h"
 
+/* cstdio has a bunch of problems with 64-bit definitions */
+#include "compat/stdio.h"
+
 
 /*****************************************************/
 /* component-specific portabilities                  */
index 65cf7b09d042bb2b2d6f9fc00e613db7ec9f8d20..b262c28964b0f31a3b827b288ea90592ac657acb 100644 (file)
@@ -6,10 +6,6 @@
  * It shunts the debug messages down stderr for logging by Squid
  * or display to the user instead of corrupting the stdout data stream.
  */
-
-#if HAVE_STDIO_H
-#include <stdio.h>
-#endif
 #if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
index d56221ae27c194f47a1e9d0dc945dddd023e18d6..020fdac9e6fce6ed71be6da3b7faef27ed0cd01b 100644 (file)
 #include "config.h"
 #include "compat/eui64_aton.h"
 
-#if HAVE_STDIO_H
-#include <stdio.h>
-#endif
-
 /*
  * Convert an ASCII representation of an EUI-64 to binary form.
  */
index 2d3d135b1f53dc322c59c3d91ad391dc785ac4b3..9dc5e1ce7ee1b8d225d1b740db3968a77d80ca44 100644 (file)
@@ -80,9 +80,6 @@
 #include "compat/inet_ntop.h"
 #include "compat/getaddrinfo.h"
 
-#if HAVE_STDIO_H
-#include <stdio.h>
-#endif
 #if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
index 6e1fe0ef663e895e2cdd4ab11e661a69be6078c8..147c494de42e89740d92bd3dc1da701da4961146 100644 (file)
@@ -68,9 +68,6 @@ static const char rcsid[] = "inet_ntop.c,v 1.1.2.1.8.2 2005/11/03 23:08:40 marka
 #if HAVE_ERRNO_H
 #include <errno.h>
 #endif
-#if HAVE_STDIO_H
-#include <stdio.h>
-#endif
 #if HAVE_STRING_H
 #include <string.h>
 #endif
diff --git a/compat/stdio.h b/compat/stdio.h
new file mode 100644 (file)
index 0000000..8bcc117
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef _SQUID_COMPAT_STDIO_H
+#define _SQUID_COMPAT_STDIO_H
+
+/** 64-bit broken <cstdio>
+ *
+ * <stdio.h> provides fgetpos64, fopen64 if __USE_FILE_OFFSET64 is defined.
+ * It then checks whether a gcc-specific __REDIRECT macro is available
+ * (defined in <sys/cdefs.h>, depending on __GNUC__ begin available).
+ * If it is not available, it does a preprocessor #define.
+ * Which <cstdio> undefines, with this comment:
+ *   "// Get rid of those macros defined in <stdio.h>  in lieu of real functions.".
+ *  When it does a namespace redirection ("namespace std { using ::fgetpos; }") it goes blam, as
+ * fgetpos64 is available, while fgetpos is not.
+ */
+
+// Import the stdio.h definitions first to do the state setup
+#if HAVE_STDIO_H
+#include<stdio.h>
+#endif
+
+// Check for the buggy case
+#if defined(__USE_FILE_OFFSET64) && !defined(__REDIRECT)
+
+// Define the problem functions as needed
+#if defined(fgetpos)
+#undef fgetpos
+inline int fgetpos(FILE *f, fpos64_t *p) { return fgetpos64(f,p); }
+#endif
+#if defined(fopen)
+#undef fopen
+inline FILE * fopen(const char *f, const char *m) { return fopen64(f,m); }
+#endif
+#if defined(freopen)
+#undef freopen
+inline FILE * freopen(const char *f, const char *m, FILE *s) { return freopen64(f,m,s); }
+#endif
+#if defined(fsetpos)
+#undef fsetpos
+inline int fsetpos(FILE *f, fpos64_t *p) { return fsetpos64(f,p); }
+#endif
+#if defined(tmpfile)
+#undef tmpfile
+inline FILE * tmpfile(void) { return tmpfile64(); }
+#endif
+
+#endif /* __USE_FILE_OFFSET64 && !__REDIRECT */
+
+// Finally import the <cstdio> stuff we actually use
+#if HAVE_CSTDIO
+#include<cstdio>
+#endif
+
+#endif /* _SQUID_COMPAT_STDIO_H */
index dff1c9896f6c19711cb323446258e80a8dca9c59..8e61f4467164efed253a72aeea69a2c9f318f65d 100644 (file)
@@ -14,9 +14,6 @@
 #if HAVE_LIBC_H
 #include <libc.h>
 #endif
-#if HAVE_STDIO_H
-#include <stdio.h>
-#endif
 #if HAVE_LIMITS_H
 #include <limits.h>
 #endif