From 5b44c55d55ab67a19bb27ff7df00711a74a6e4e2 Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Thu, 7 Apr 2011 01:58:14 +1200 Subject: [PATCH] Portability: Provide stdio wrappers for 64-bit in cstdio C++ builds 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 undefines, with this comment: "// Get rid of those macros defined in 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 #if defined(__USE_FILE_OFFSET64) &&!defined(__REDIRECT) && defined(fgetpos) #undef fgetpos int fgetpos (FILE * f, fpos64_t *p) { return fgetpos64(f,p); } #endif #include This every time we use (directly or indirectly). This is triggered by us defining -D_FILE_OFFSET_BITS=64 when --enable-large-files configure is used. --- compat/GnuRegex.c | 6 ----- compat/Makefile.am | 1 + compat/assert.cc | 8 ------- compat/compat.h | 3 +++ compat/debug.h | 4 ---- compat/eui64_aton.c | 4 ---- compat/getnameinfo.c | 3 --- compat/inet_ntop.c | 3 --- compat/stdio.h | 53 ++++++++++++++++++++++++++++++++++++++++++++ compat/tempnam.c | 3 --- 10 files changed, 57 insertions(+), 31 deletions(-) create mode 100644 compat/stdio.h diff --git a/compat/GnuRegex.c b/compat/GnuRegex.c index 3bfa598942..5a15f2e2b9 100644 --- a/compat/GnuRegex.c +++ b/compat/GnuRegex.c @@ -452,12 +452,6 @@ unsigned char **source; #ifdef DEBUG -/* We use standard I/O for debugging. */ -#include - -/* It is useful to test things that ``must'' be true when debugging. */ -#include - static int debug = 0; #define DEBUG_STATEMENT(e) e diff --git a/compat/Makefile.am b/compat/Makefile.am index 671c5106d1..fc8238350e 100644 --- a/compat/Makefile.am +++ b/compat/Makefile.am @@ -31,6 +31,7 @@ libcompat_squid_a_SOURCES = \ initgroups.h \ osdetect.h \ psignal.h \ + stdio.h \ stdvarargs.h \ strnstr.cc \ strsep.h \ diff --git a/compat/assert.cc b/compat/assert.cc index 65bcbbb0f5..c9d32799b4 100644 --- a/compat/assert.cc +++ b/compat/assert.cc @@ -33,14 +33,6 @@ #include "config.h" -#if HAVE_STDIO_H -#include -#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); diff --git a/compat/compat.h b/compat/compat.h index cb28156b48..e1de846f5b 100644 --- a/compat/compat.h +++ b/compat/compat.h @@ -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 */ diff --git a/compat/debug.h b/compat/debug.h index 65cf7b09d0..b262c28964 100644 --- a/compat/debug.h +++ b/compat/debug.h @@ -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 -#endif #if HAVE_UNISTD_H #include #endif diff --git a/compat/eui64_aton.c b/compat/eui64_aton.c index d56221ae27..020fdac9e6 100644 --- a/compat/eui64_aton.c +++ b/compat/eui64_aton.c @@ -77,10 +77,6 @@ #include "config.h" #include "compat/eui64_aton.h" -#if HAVE_STDIO_H -#include -#endif - /* * Convert an ASCII representation of an EUI-64 to binary form. */ diff --git a/compat/getnameinfo.c b/compat/getnameinfo.c index 2d3d135b1f..9dc5e1ce7e 100644 --- a/compat/getnameinfo.c +++ b/compat/getnameinfo.c @@ -80,9 +80,6 @@ #include "compat/inet_ntop.h" #include "compat/getaddrinfo.h" -#if HAVE_STDIO_H -#include -#endif #if HAVE_SYS_SOCKET_H #include #endif diff --git a/compat/inet_ntop.c b/compat/inet_ntop.c index 6e1fe0ef66..147c494de4 100644 --- a/compat/inet_ntop.c +++ b/compat/inet_ntop.c @@ -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 #endif -#if HAVE_STDIO_H -#include -#endif #if HAVE_STRING_H #include #endif diff --git a/compat/stdio.h b/compat/stdio.h new file mode 100644 index 0000000000..8bcc117e2d --- /dev/null +++ b/compat/stdio.h @@ -0,0 +1,53 @@ +#ifndef _SQUID_COMPAT_STDIO_H +#define _SQUID_COMPAT_STDIO_H + +/** 64-bit broken + * + * provides fgetpos64, fopen64 if __USE_FILE_OFFSET64 is defined. + * It then checks whether a gcc-specific __REDIRECT macro is available + * (defined in , depending on __GNUC__ begin available). + * If it is not available, it does a preprocessor #define. + * Which undefines, with this comment: + * "// Get rid of those macros defined in 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 +#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 stuff we actually use +#if HAVE_CSTDIO +#include +#endif + +#endif /* _SQUID_COMPAT_STDIO_H */ diff --git a/compat/tempnam.c b/compat/tempnam.c index dff1c9896f..8e61f44671 100644 --- a/compat/tempnam.c +++ b/compat/tempnam.c @@ -14,9 +14,6 @@ #if HAVE_LIBC_H #include #endif -#if HAVE_STDIO_H -#include -#endif #if HAVE_LIMITS_H #include #endif -- 2.47.2