Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F135955616
D4980.id12961.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D4980.id12961.diff
View Options
Index: include/stdio.h
===================================================================
--- include/stdio.h
+++ include/stdio.h
@@ -253,7 +253,9 @@
int fsetpos(FILE *, const fpos_t *);
long ftell(FILE *);
size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
-int getc(FILE *);
+#ifndef __LIBC_C
+static __inline int getc(FILE *);
+#endif
int getchar(void);
char *gets(char *);
void perror(const char *);
@@ -302,7 +304,9 @@
char *ctermid(char *);
FILE *fdopen(int, const char *);
-int fileno(FILE *);
+#ifndef __LIBC_C
+static __inline int fileno(FILE *);
+#endif
#endif /* __POSIX_VISIBLE */
#if __POSIX_VISIBLE >= 199209
@@ -319,7 +323,9 @@
* These are normally used through macros as defined below, but POSIX
* requires functions as well.
*/
-int getc_unlocked(FILE *);
+#ifndef __LIBC_C
+static __inline int getc_unlocked(FILE *);
+#endif
int getchar_unlocked(void);
int putc_unlocked(int, FILE *);
int putchar_unlocked(int);
@@ -328,7 +334,9 @@
void clearerr_unlocked(FILE *);
int feof_unlocked(FILE *);
int ferror_unlocked(FILE *);
-int fileno_unlocked(FILE *);
+#ifndef __LIBC_C
+static __inline int fileno_unlocked(FILE *);
+#endif
#endif
#if __POSIX_VISIBLE >= 200112
@@ -482,23 +490,61 @@
extern int __isthreaded;
+#define __sfileno(p) ((p)->_file)
+
+#if __POSIX_VISIBLE
+#ifndef __LIBC_C
+extern int __fileno_mt(FILE *fp);
+extern int __getc_mt(FILE *fp);
+
+static __inline int
+fileno(FILE *p)
+{
+ return (!__isthreaded ? __sfileno(p) : (__fileno_mt)(p));
+}
+
+static __inline int
+getc(FILE *p)
+{
+ return (!__isthreaded ? __sgetc(p) : (__getc_mt)(p));
+}
+#endif
+#endif
+
+#if __BSD_VISIBLE
+/*
+ * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12
+ * B.8.2.7 for the rationale behind the *_unlocked() macros.
+ */
+#ifndef __LIBC_C
+static __inline int
+fileno_unlocked(FILE *p)
+{
+ return __sfileno(p);
+}
+
+#if __POSIX_VISIBLE >= 199506
+static __inline int
+getc_unlocked(FILE *p)
+{
+ return __sgetc(p);
+}
+#endif
+
+#endif
+#endif
+
#ifndef __cplusplus
#define __sfeof(p) (((p)->_flags & __SEOF) != 0)
#define __sferror(p) (((p)->_flags & __SERR) != 0)
#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
-#define __sfileno(p) ((p)->_file)
#define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p))
#define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p))
#define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p))
-#if __POSIX_VISIBLE
-#define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p))
-#endif
-
-#define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp))
#define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp))
#define getchar() getc(stdin)
@@ -512,10 +558,8 @@
#define feof_unlocked(p) __sfeof(p)
#define ferror_unlocked(p) __sferror(p)
#define clearerr_unlocked(p) __sclearerr(p)
-#define fileno_unlocked(p) __sfileno(p)
#endif
#if __POSIX_VISIBLE >= 199506
-#define getc_unlocked(fp) __sgetc(fp)
#define putc_unlocked(x, fp) __sputc(x, fp)
#define getchar_unlocked() getc_unlocked(stdin)
Index: lib/libc/stdio/Symbol.map
===================================================================
--- lib/libc/stdio/Symbol.map
+++ lib/libc/stdio/Symbol.map
@@ -164,6 +164,8 @@
FBSD_1.4 {
fdclose;
+ __fileno_mt;
+ __getc_mt;
};
FBSDprivate_1.0 {
Index: lib/libc/stdio/fileno.c
===================================================================
--- lib/libc/stdio/fileno.c
+++ lib/libc/stdio/fileno.c
@@ -37,6 +37,7 @@
__FBSDID("$FreeBSD$");
#include "namespace.h"
+#define __LIBC_C
#include <stdio.h>
#include "un-namespace.h"
#include "libc_private.h"
@@ -56,6 +57,22 @@
return (fd);
}
+/*
+ * wrapper for fileno() above, this is to be only used inside stdio.h static __inline fileno() wrapper
+ * to avoid symbol conflict for multithreaded programs (that causes infinite recursion).
+ */
+#if defined(__strong_reference)
+__strong_reference(fileno, __fileno_mt);
+#elif defined(__weak_reference)
+__weak_reference(fileno, __fileno_mt);
+#else
+int
+__fileno_mt(FILE *fp)
+{
+ return fileno(fp);
+}
+#endif
+
int
fileno_unlocked(FILE *fp)
{
Index: lib/libc/stdio/getc.c
===================================================================
--- lib/libc/stdio/getc.c
+++ lib/libc/stdio/getc.c
@@ -37,6 +37,7 @@
__FBSDID("$FreeBSD$");
#include "namespace.h"
+#define __LIBC_C
#include <stdio.h>
#include "un-namespace.h"
#include "libc_private.h"
@@ -57,6 +58,23 @@
return (retval);
}
+/*
+ * wrapper for getc() above, this is to be only used inside stdio.h static __inline getc() wrapper
+ * to avoid symbol conflict for multithreaded programs (that causes infinite recursion).
+ */
+#if defined(__strong_reference)
+__strong_reference(getc, __getc_mt);
+#elif defined(__weak_reference)
+__weak_reference(getc, __getc_mt);
+#else
+int
+__getc_mt(FILE *fp)
+{
+ return getc(fp);
+}
+#endif
+
+
int
getc_unlocked(FILE *fp)
{
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 15, 1:14 PM (22 m, 13 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25327416
Default Alt Text
D4980.id12961.diff (4 KB)
Attached To
Mode
D4980: Avoid C++ namespace pollution from POSIX headers
Attached
Detach File
Event Timeline
Log In to Comment