summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-11-14 14:42:59 -0800
committerElliott Hughes <enh@google.com>2014-11-14 14:42:59 -0800
commit168667c972a1e9ede5b64ad6cee0666e9b96d4d8 (patch)
treed4312b237b885460537ce9dc8fe53e26564a7d48
parent898aab282cff2a2949bc1726f8a4b81c1c30148e (diff)
downloadbionic-168667c972a1e9ede5b64ad6cee0666e9b96d4d8.zip
bionic-168667c972a1e9ede5b64ad6cee0666e9b96d4d8.tar.gz
bionic-168667c972a1e9ede5b64ad6cee0666e9b96d4d8.tar.bz2
Add non-macro stdin/stdout/stderr too.
Various C and C++ standards explicitly say that stdin/stdout/stderr should be macros, but glibc makes them global variables too. This means it's possible to write code that uses those names as locals, but that code (toybox being an example) won't build on bionic. If we'd done this earlier, we could have hidden __sF for LP64, but it's too late now. Change-Id: I90cf8c73f52b66e1760b8fa2e135b9f9f9651230
-rw-r--r--libc/include/stdio.h13
-rw-r--r--libc/stdio/fileext.h4
-rw-r--r--libc/stdio/findfp.c5
3 files changed, 13 insertions, 9 deletions
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index a7ec615..c0dac1a 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -146,7 +146,16 @@ typedef struct __sFILE {
fpos_t _offset; /* current lseek offset */
} FILE;
+/* Legacy BSD implementation of stdin/stdout/stderr. */
extern FILE __sF[];
+/* More obvious implementation. */
+extern FILE* stdin;
+extern FILE* stdout;
+extern FILE* stderr;
+/* C99 and earlier plus current C++ standards say these must be macros. */
+#define stdin stdin
+#define stdout stdout
+#define stderr stderr
#define __SLBF 0x0001 /* line buffered */
#define __SNBF 0x0002 /* unbuffered */
@@ -209,10 +218,6 @@ extern FILE __sF[];
#define SEEK_END 2 /* set file offset to EOF plus offset */
#endif
-#define stdin (&__sF[0])
-#define stdout (&__sF[1])
-#define stderr (&__sF[2])
-
/*
* Functions defined in ANSI C standard.
*/
diff --git a/libc/stdio/fileext.h b/libc/stdio/fileext.h
index 7efff8f..dc89fff 100644
--- a/libc/stdio/fileext.h
+++ b/libc/stdio/fileext.h
@@ -43,10 +43,6 @@ struct __sfileext {
pthread_mutex_t _lock; /* file lock */
};
-__LIBC_HIDDEN__ extern struct __sfileext __sFext[3];
-
-#define _FILEEXT_INITIALIZER {{NULL,0},{0},PTHREAD_RECURSIVE_MUTEX_INITIALIZER}
-
#define _EXT(fp) ((struct __sfileext *)((fp)->_ext._base))
#define _UB(fp) _EXT(fp)->_ub
#define _FLOCK(fp) _EXT(fp)->_lock
diff --git a/libc/stdio/findfp.c b/libc/stdio/findfp.c
index ef8e9e6..5e51198 100644
--- a/libc/stdio/findfp.c
+++ b/libc/stdio/findfp.c
@@ -59,12 +59,15 @@ static struct glue uglue = { 0, FOPEN_MAX - 3, usual };
static struct glue *lastglue = &uglue;
_THREAD_PRIVATE_MUTEX(__sfp_mutex);
-struct __sfileext __sFext[3];
+static struct __sfileext __sFext[3];
FILE __sF[3] = {
std(__SRD, STDIN_FILENO), /* stdin */
std(__SWR, STDOUT_FILENO), /* stdout */
std(__SWR|__SNBF, STDERR_FILENO) /* stderr */
};
+FILE* stdin = &__sF[0];
+FILE* stdout = &__sF[1];
+FILE* stderr = &__sF[2];
struct glue __sglue = { &uglue, 3, __sF };
static struct glue *