Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Marshall <keithmarshall@@users.sf.net>2008-08-30 21:27:18 +0400
committerKeith Marshall <keithmarshall@@users.sf.net>2008-08-30 21:27:18 +0400
commit20167d0a5fd7646d101e55e68e282da36ed6463a (patch)
treef982ececfdeb19d09c0cec657a03bf5d9b24ed81 /winsup/mingw/include
parent782ac76f36edf0ce907c62fb7e8e183c3d246335 (diff)
Implement conditional replacement for printf() family functions.
Diffstat (limited to 'winsup/mingw/include')
-rw-r--r--winsup/mingw/include/_mingw.h74
-rw-r--r--winsup/mingw/include/stdio.h132
2 files changed, 182 insertions, 24 deletions
diff --git a/winsup/mingw/include/_mingw.h b/winsup/mingw/include/_mingw.h
index 230727219..65f23a598 100644
--- a/winsup/mingw/include/_mingw.h
+++ b/winsup/mingw/include/_mingw.h
@@ -1,3 +1,4 @@
+#ifndef __MINGW_H
/*
* _mingw.h
*
@@ -19,10 +20,12 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
-
-#ifndef __MINGW_H
#define __MINGW_H
+#define __MINGW32_VERSION 3.14
+#define __MINGW32_MAJOR_VERSION 3
+#define __MINGW32_MINOR_VERSION 14
+
#if __GNUC__ >= 3
#pragma GCC system_header
#endif
@@ -30,24 +33,45 @@
/* These are defined by the user (or the compiler)
to specify how identifiers are imported from a DLL.
- __DECLSPEC_SUPPORTED Defined if dllimport attribute is supported.
- __MINGW_IMPORT The attribute definition to specify imported
- variables/functions.
- _CRTIMP As above. For MS compatibility.
- __MINGW32_VERSION Runtime version.
- __MINGW32_MAJOR_VERSION Runtime major version.
- __MINGW32_MINOR_VERSION Runtime minor version.
- __MINGW32_BUILD_DATE Runtime build date.
+ __DECLSPEC_SUPPORTED Defined if dllimport attribute is supported.
+ __MINGW_IMPORT The attribute definition to specify imported
+ variables/functions.
+ _CRTIMP As above. For MS compatibility.
+ __MINGW32_VERSION Runtime version.
+ __MINGW32_MAJOR_VERSION Runtime major version.
+ __MINGW32_MINOR_VERSION Runtime minor version.
+ __MINGW32_BUILD_DATE Runtime build date.
+
+ Macros to enable MinGW features which deviate from standard MSVC
+ compatible behaviour; these may be specified directly in user code,
+ activated implicitly, (e.g. by specifying _POSIX_C_SOURCE or such),
+ or by inclusion in __MINGW_FEATURES__:
+
+ __USE_MINGW_ANSI_STDIO Select a more ANSI C99 compatible
+ implementation of printf() and friends.
Other macros:
- __int64 define to be long long. Using a typedef doesn't
- work for "unsigned __int64"
+ __int64 define to be long long. Using a typedef
+ doesn't work for "unsigned __int64"
All headers should include this first, and then use __DECLSPEC_SUPPORTED
to choose between the old ``__imp__name'' style or __MINGW_IMPORT
style declarations. */
+
+/* Manifest definitions identifying the flag bits, controlling activation
+ * of MinGW features, as specified by the user in __MINGW_FEATURES__.
+ */
+#define __MINGW_ANSI_STDIO__ 0x0000000000000001ULL
+/*
+ * The following three are not yet formally supported; they are
+ * included here, to document anticipated future usage.
+ */
+#define __MINGW_LC_EXTENSIONS__ 0x0000000000000050ULL
+#define __MINGW_LC_MESSAGES__ 0x0000000000000010ULL
+#define __MINGW_LC_ENVVARS__ 0x0000000000000040ULL
+
/* Try to avoid problems with outdated checks for GCC __attribute__ support. */
#undef __attribute__
@@ -188,8 +212,28 @@ allow GCC to optimize away some EH unwind code, at least in DW2 case. */
# define __MSVCRT_VERSION__ 0x0600
#endif
-#define __MINGW32_VERSION 3.14
-#define __MINGW32_MAJOR_VERSION 3
-#define __MINGW32_MINOR_VERSION 14
+/* Activation of MinGW specific extended features:
+ */
+#ifndef __USE_MINGW_ANSI_STDIO
+/*
+ * If user didn't specify it explicitly...
+ */
+# if defined __STRICT_ANSI__ || defined _ISOC99_SOURCE \
+ || defined _POSIX_SOURCE || defined _POSIX_C_SOURCE \
+ || defined _XOPEN_SOURCE || defined _XOPEN_SOURCE_EXTENDED \
+ || defined _GNU_SOURCE || defined _BSD_SOURCE \
+ || defined _SVID_SOURCE
+ /*
+ * but where any of these source code qualifiers are specified,
+ * then assume ANSI I/O standards are preferred over Microsoft's...
+ */
+# define __USE_MINGW_ANSI_STDIO 1
+# else
+ /*
+ * otherwise use whatever __MINGW_FEATURES__ specifies...
+ */
+# define __USE_MINGW_ANSI_STDIO (__MINGW_FEATURES__ & __MINGW_ANSI_STDIO__)
+# endif
+#endif
#endif /* __MINGW_H */
diff --git a/winsup/mingw/include/stdio.h b/winsup/mingw/include/stdio.h
index c01de5efd..c05b1b1dd 100644
--- a/winsup/mingw/include/stdio.h
+++ b/winsup/mingw/include/stdio.h
@@ -194,16 +194,130 @@ _CRTIMP void __cdecl __MINGW_NOTHROW setbuf (FILE*, char*);
/*
* Formatted Output
+ *
+ * MSVCRT implementations are not ANSI C99 conformant...
+ * we offer these conforming alternatives from libmingwex.a
+ */
+#undef __mingw_stdio_redirect__
+#define __mingw_stdio_redirect__(F) __cdecl __MINGW_NOTHROW __mingw_##F
+
+extern int __mingw_stdio_redirect__(fprintf)(FILE*, const char*, ...);
+extern int __mingw_stdio_redirect__(printf)(const char*, ...);
+extern int __mingw_stdio_redirect__(sprintf)(char*, const char*, ...);
+extern int __mingw_stdio_redirect__(snprintf)(char*, size_t, const char*, ...);
+extern int __mingw_stdio_redirect__(vfprintf)(FILE*, const char*, __VALIST);
+extern int __mingw_stdio_redirect__(vprintf)(const char*, __VALIST);
+extern int __mingw_stdio_redirect__(vsprintf)(char*, const char*, __VALIST);
+extern int __mingw_stdio_redirect__(vsnprintf)(char*, size_t, const char*, __VALIST);
+
+#if __USE_MINGW_ANSI_STDIO
+/*
+ * User has expressed a preference for C99 conformance...
*/
+# undef __mingw_stdio_redirect__
+# ifdef __cplusplus
+/*
+ * For C++ we use inline implementations, to avoid interference
+ * with namespace qualification, which may result from using #defines.
+ */
+# define __mingw_stdio_redirect__ static inline __cdecl __MINGW_NOTHROW
+
+# elif defined __GNUC__
+/*
+ * FIXME: Is there any GCC version prerequisite here?
+ *
+ * We also prefer inline implementations for C, when we can be confident
+ * that the GNU specific __inline__ mechanism is supported.
+ */
+# define __mingw_stdio_redirect__ static __inline__ __cdecl __MINGW_NOTHROW
+
+# else
+/*
+ * Can't use inlines; fall back on module local static stubs.
+ */
+# define __mingw_stdio_redirect__ static __cdecl __MINGW_NOTHROW
+# endif
+
+__mingw_stdio_redirect__
+int fprintf (FILE *__stream, const char *__format, ...)
+{
+ register int __retval;
+ __builtin_va_list __argv; __builtin_va_start( __argv, __format );
+ __retval = __mingw_vfprintf( __stream, __format, __argv );
+ __builtin_va_end( __argv );
+ return __retval;
+}
+
+__mingw_stdio_redirect__
+int printf (const char *__format, ...)
+{
+ register int __retval;
+ __builtin_va_list __argv; __builtin_va_start( __argv, __format );
+ __retval = __mingw_vprintf( __format, __argv );
+ __builtin_va_end( __argv );
+ return __retval;
+}
+
+__mingw_stdio_redirect__
+int sprintf (char *__stream, const char *__format, ...)
+{
+ register int __retval;
+ __builtin_va_list __argv; __builtin_va_start( __argv, __format );
+ __retval = __mingw_vsprintf( __stream, __format, __argv );
+ __builtin_va_end( __argv );
+ return __retval;
+}
-_CRTIMP int __cdecl __MINGW_NOTHROW fprintf (FILE*, const char*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW printf (const char*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW sprintf (char*, const char*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW _snprintf (char*, size_t, const char*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW vfprintf (FILE*, const char*, __VALIST);
-_CRTIMP int __cdecl __MINGW_NOTHROW vprintf (const char*, __VALIST);
-_CRTIMP int __cdecl __MINGW_NOTHROW vsprintf (char*, const char*, __VALIST);
-_CRTIMP int __cdecl __MINGW_NOTHROW _vsnprintf (char*, size_t, const char*, __VALIST);
+__mingw_stdio_redirect__
+int vfprintf (FILE *__stream, const char *__format, __VALIST __argv)
+{
+ return __mingw_vfprintf( __stream, __format, __argv );
+}
+
+__mingw_stdio_redirect__
+int vprintf (const char *__format, __VALIST __argv)
+{
+ return __mingw_vprintf( __format, __argv );
+}
+
+__mingw_stdio_redirect__
+int vsprintf (char *__stream, const char *__format, __VALIST __argv)
+{
+ return __mingw_vsprintf( __stream, __format, __argv );
+}
+
+#else
+/*
+ * Default configuration: simply direct all calls to MSVCRT...
+ */
+_CRTIMP int __cdecl __MINGW_NOTHROW fprintf (FILE*, const char*, ...);
+_CRTIMP int __cdecl __MINGW_NOTHROW printf (const char*, ...);
+_CRTIMP int __cdecl __MINGW_NOTHROW sprintf (char*, const char*, ...);
+_CRTIMP int __cdecl __MINGW_NOTHROW vfprintf (FILE*, const char*, __VALIST);
+_CRTIMP int __cdecl __MINGW_NOTHROW vprintf (const char*, __VALIST);
+_CRTIMP int __cdecl __MINGW_NOTHROW vsprintf (char*, const char*, __VALIST);
+
+#endif
+/*
+ * Regardless of user preference, always offer these alternative
+ * entry points, for direct access to the MSVCRT implementations.
+ */
+#undef __mingw_stdio_redirect__
+#define __mingw_stdio_redirect__(F) __cdecl __MINGW_NOTHROW __msvcrt_##F
+
+_CRTIMP int __mingw_stdio_redirect__(fprintf)(FILE*, const char*, ...);
+_CRTIMP int __mingw_stdio_redirect__(printf)(const char*, ...);
+_CRTIMP int __mingw_stdio_redirect__(sprintf)(char*, const char*, ...);
+_CRTIMP int __mingw_stdio_redirect__(vfprintf)(FILE*, const char*, __VALIST);
+_CRTIMP int __mingw_stdio_redirect__(vprintf)(const char*, __VALIST);
+_CRTIMP int __mingw_stdio_redirect__(vsprintf)(char*, const char*, __VALIST);
+
+#undef __mingw_stdio_redirect__
+
+/* The following pair ALWAYS refer to the MSVCRT implementations...
+ */
+_CRTIMP int __cdecl __MINGW_NOTHROW _snprintf (char*, size_t, const char*, ...);
+_CRTIMP int __cdecl __MINGW_NOTHROW _vsnprintf (char*, size_t, const char*, __VALIST);
#ifndef __NO_ISOCEXT /* externs in libmingwex.a */
/*
@@ -213,7 +327,7 @@ _CRTIMP int __cdecl __MINGW_NOTHROW _vsnprintf (char*, size_t, const char*, __VA
* compatible with C99, but the following are; if you want the MSVCRT
* behaviour, you *must* use the Microsoft uglified names.
*/
-int __cdecl __MINGW_NOTHROW snprintf(char *, size_t, const char *, ...);
+int __cdecl __MINGW_NOTHROW snprintf (char *, size_t, const char *, ...);
int __cdecl __MINGW_NOTHROW vsnprintf (char *, size_t, const char *, __VALIST);
int __cdecl __MINGW_NOTHROW vscanf (const char * __restrict__, __VALIST);