]> 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>
Mon, 18 Apr 2011 11:46:39 +0000 (05:46 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 18 Apr 2011 11:46:39 +0000 (05:46 -0600)
stdio.h in that case 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/stdio.h [new file with mode: 0644]
lib/getnameinfo.c
lib/inet_ntop.c
lib/tempnam.c

index bdb302c0a22b6c2b6633b96898e6d7e598898ed7..08f8deeb9eb6815edc8c778900016fb2fc2095fe 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 9d14a32cbe94d57c88ea6e65f42b3aacccf78eba..d92c57e5d4f83bd43f146c48493be811946dd891 100644 (file)
@@ -17,6 +17,7 @@ libcompat_la_SOURCES = \
        compat_shared.h \
        fdsetsize.h \
        osdetect.h \
+       stdio.h \
        stdvarargs.h \
        valgrind.h \
        \
index b1e06e331533a6c396363df3e50e29915e637e0a..c9d32799b400df3f489e9ad8f5ccdb74b6012cc9 100644 (file)
 
 #include "config.h"
 
-#if HAVE_STDIO_H
-#include <stdio.h>
-#endif
-#if HAVE_STDLIB_H
-#include <stdlib.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 3059cdeff964579ace7a38b995aa3013ff0f2ac0..1924f2b711186c3207181087e9fd8aec44b247da 100644 (file)
@@ -75,6 +75,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                  */
 /*****************************************************/
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 ab8ac0f2185ab9050b7c7ff1958d1fa0347df634..b598e1a59738f1181e09924e9f1a93f8f4454697 100644 (file)
 
 #ifndef HAVE_GETNAMEINFO
 
-#if HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#if HAVE_STDIO_H
-#include <stdio.h>
-#endif
 #if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
index cc0b60a525955e24f2e4a18974300c45109ac610..57567cfcbcda10dc9f76c807d72338a17b0df8e6 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
index 0ff9f88e35bef14a2b378eb137318149f6d1e7b4..d39db237e4c1861557fbab2b78537740387db432 100644 (file)
 #if HAVE_LIBC_H
 #include <libc.h>
 #endif
-#if HAVE_STDIO_H
-#include <stdio.h>
-#endif
-#if HAVE_TYPES_H
-#include <sys/types.h>
-#endif
 #if HAVE_LIMITS_H
 #include <limits.h>
 #endif