make FILE a complete type for pre-C11 standard profiles
authorRich Felker <dalias@aerifal.cx>
Tue, 12 Mar 2019 19:24:00 +0000 (15:24 -0400)
committerRich Felker <dalias@aerifal.cx>
Tue, 12 Mar 2019 19:24:00 +0000 (15:24 -0400)
C11 removed the requirement that FILE be a complete type, which was
deemed erroneous, as part of the changes introduced by N1439 regarding
completeness of types (see footnote 6 for specific mention of FILE).
however the current version of POSIX is still based on C99 and
incorporates the old requirement that FILE be a complete type.

expose an arbitrary, useless complete type definition because the
actual object used to represent FILE streams cannot be public/ABI.

thanks to commit 13d1afa46f8098df290008c681816c9eb89ffbdb, we now have
a framework for suppressing the public complete-type definition of FILE
when stdio.h is included internally, so that a different internal
definition can be provided. this is perfectly well-defined, since the
same struct tag can refer to different types in different translation
units. it would be a problem if the implementation were accessing the
application's FILE objects or vice versa, but either would be
undefined behavior.

include/alltypes.h.in
include/stdio.h
include/wchar.h
src/include/stdio.h
src/include/wchar.h [new file with mode: 0644]

index 622ca01d777d668bd98bae626c24dd9b47718962..4cc879b1d70c66343a25cd7481a1ee9f9e86c1fa 100644 (file)
@@ -57,6 +57,7 @@ TYPEDEF struct { unsigned __attr; } pthread_condattr_t;
 TYPEDEF struct { unsigned __attr; } pthread_barrierattr_t;
 TYPEDEF struct { unsigned __attr[2]; } pthread_rwlockattr_t;
 
+STRUCT _IO_FILE { char __x; };
 TYPEDEF struct _IO_FILE FILE;
 
 TYPEDEF struct __mbstate_t { unsigned __opaque1, __opaque2; } mbstate_t;
index afadd9124a847dfdf6b407049c7e0a32d9f389f4..3604198c3e503aba5335919cc3f429b7a8350beb 100644 (file)
@@ -11,6 +11,10 @@ extern "C" {
 #define __NEED___isoc_va_list
 #define __NEED_size_t
 
+#if __STDC_VERSION__ < 201112L
+#define __NEED_struct__IO_FILE
+#endif
+
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
  || defined(_BSD_SOURCE)
index 369b1e9f25a4225e5c1a02e6e4bc49736a1e1500..88eb55b18cc1ff04819adb40f75fb8c33d860af8 100644 (file)
@@ -14,6 +14,10 @@ extern "C" {
 #define __NEED_wint_t
 #define __NEED_mbstate_t
 
+#if __STDC_VERSION__ < 201112L
+#define __NEED_struct__IO_FILE
+#endif
+
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define __NEED_locale_t
index 534c69079cb6d5127e6fa8784cf12bcad4fa07a8..fae3755b4a15bfdf1fcca4bb0c2dac9356456d19 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef STDIO_H
 #define STDIO_H
 
+#define __DEFINED_struct__IO_FILE
+
 #include "../../include/stdio.h"
 
 #undef stdin
diff --git a/src/include/wchar.h b/src/include/wchar.h
new file mode 100644 (file)
index 0000000..79f5d0e
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef WCHAR_H
+#define WCHAR_H
+
+#define __DEFINED_struct__IO_FILE
+
+#include "../../include/wchar.h"
+
+#endif
+