]> git.ipfire.org Git - thirdparty/squid.git/blob - compat/stdio.h
Merge from trunk
[thirdparty/squid.git] / compat / stdio.h
1 #ifndef _SQUID_COMPAT_STDIO_H
2 #define _SQUID_COMPAT_STDIO_H
3
4 /** 64-bit broken <cstdio>
5 *
6 * <stdio.h> provides fgetpos64, fopen64 if __USE_FILE_OFFSET64 is defined.
7 * It then checks whether a gcc-specific __REDIRECT macro is available
8 * (defined in <sys/cdefs.h>, depending on __GNUC__ begin available).
9 * If it is not available, it does a preprocessor #define.
10 * Which <cstdio> undefines, with this comment:
11 * "// Get rid of those macros defined in <stdio.h> in lieu of real functions.".
12 * When it does a namespace redirection ("namespace std { using ::fgetpos; }") it goes blam, as
13 * fgetpos64 is available, while fgetpos is not.
14 */
15
16 // Import the stdio.h definitions first to do the state setup
17 #if HAVE_STDIO_H
18 #include <stdio.h>
19 #endif
20
21 // Check for the buggy case
22 #if defined(__USE_FILE_OFFSET64) && !defined(__REDIRECT)
23
24 // Define the problem functions as needed
25 #if defined(fgetpos)
26 #undef fgetpos
27 inline int fgetpos(FILE *f, fpos64_t *p) { return fgetpos64(f,p); }
28 #endif
29 #if defined(fopen)
30 #undef fopen
31 inline FILE * fopen(const char *f, const char *m) { return fopen64(f,m); }
32 #endif
33 #if defined(freopen)
34 #undef freopen
35 inline FILE * freopen(const char *f, const char *m, FILE *s) { return freopen64(f,m,s); }
36 #endif
37 #if defined(fsetpos)
38 #undef fsetpos
39 inline int fsetpos(FILE *f, fpos64_t *p) { return fsetpos64(f,p); }
40 #endif
41 #if defined(tmpfile)
42 #undef tmpfile
43 inline FILE * tmpfile(void) { return tmpfile64(); }
44 #endif
45
46 #endif /* __USE_FILE_OFFSET64 && !__REDIRECT */
47
48 // Finally import the <cstdio> stuff we actually use
49 #if defined(__cplusplus)
50 #include <cstdio>
51 #endif
52
53 #ifndef MAXPATHLEN
54 #define MAXPATHLEN SQUID_MAXPATHLEN
55 #endif
56
57 #endif /* _SQUID_COMPAT_STDIO_H */