Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F136469567
D4980.id12676.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D4980.id12676.diff
View Options
Index: include/stdio.h
===================================================================
--- include/stdio.h
+++ include/stdio.h
@@ -302,7 +302,9 @@
char *ctermid(char *);
FILE *fdopen(int, const char *);
-int fileno(FILE *);
+#ifndef __FILENO_C
+static __inline int fileno(FILE *);
+#endif
#endif /* __POSIX_VISIBLE */
#if __POSIX_VISIBLE >= 199209
@@ -328,7 +330,9 @@
void clearerr_unlocked(FILE *);
int feof_unlocked(FILE *);
int ferror_unlocked(FILE *);
-int fileno_unlocked(FILE *);
+#ifndef __FILENO_C
+static __inline int fileno_unlocked(FILE *);
+#endif
#endif
#if __POSIX_VISIBLE >= 200112
@@ -482,22 +486,44 @@
extern int __isthreaded;
+#define __sfileno(p) ((p)->_file)
+
+#if __POSIX_VISIBLE
+#ifndef __FILENO_C
+extern int __fileno_mt(FILE *fp);
+static __inline int
+fileno(FILE *p)
+{
+ return (!__isthreaded ? __sfileno(p) : (__fileno_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 __FILENO_C
+static __inline int
+fileno_unlocked(FILE *p)
+{
+ return __sfileno(p);
+}
+#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))
@@ -512,7 +538,6 @@
#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)
Index: lib/libc/stdio/Symbol.map
===================================================================
--- lib/libc/stdio/Symbol.map
+++ lib/libc/stdio/Symbol.map
@@ -164,6 +164,7 @@
FBSD_1.4 {
fdclose;
+ __fileno_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 __FILENO_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)
{
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 18, 10:51 PM (9 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25558635
Default Alt Text
D4980.id12676.diff (3 KB)
Attached To
Mode
D4980: Avoid C++ namespace pollution from POSIX headers
Attached
Detach File
Event Timeline
Log In to Comment