stdin/stdout/stderr are special; their mutexes are initialized by
__sinit. There's no unit test for this, because __sinit has already
been called by the time the first unit test runs, but you could
reproduce this failure with a trivial main() that calls flockfile
or ftrylockfile on one of the standard streams before otherwise
using stdio.
Bug:
18208568
Change-Id: I28d232cf05a9f198a2bed61854d8047b23d2091d
// struct __sfileext (see fileext.h).
void flockfile(FILE* fp) {
+ if (!__sdidinit) {
+ __sinit();
+ }
+
if (fp != NULL) {
pthread_mutex_lock(&_FLOCK(fp));
}
}
int ftrylockfile(FILE* fp) {
+ if (!__sdidinit) {
+ __sinit();
+ }
+
// The specification for ftrylockfile() says it returns 0 on success,
// or non-zero on error. So return an errno code directly on error.
if (fp == NULL) {
}
void funlockfile(FILE* fp) {
+ if (!__sdidinit) {
+ __sinit();
+ }
+
if (fp != NULL) {
pthread_mutex_unlock(&_FLOCK(fp));
}
#include <pthread.h>
+__BEGIN_DECLS
+
/*
* file extension
*/
_FILEEXT_INIT(f); \
} while (0)
+__END_DECLS
+
#endif /* _FILEEXT_H_ */
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
/*
* The first few FILEs are statically allocated; others are dynamically
* allocated and linked in via this glue structure.
/* This was referenced by a couple of different pieces of middleware and the Crystax NDK. */
__LIBC64_HIDDEN__ extern struct glue __sglue;
+
+__END_DECLS
#include "wcio.h"
#include "fileext.h"
+__BEGIN_DECLS
+
/*
* Android <= KitKat had getc/putc macros in <stdio.h> that referred
* to __srget/__swbuf, so those symbols need to be public for LP32
wint_t __fputwc_unlock(wchar_t wc, FILE *fp);
#pragma GCC visibility pop
+
+__END_DECLS
#ifndef _WCIO_H_
#define _WCIO_H_
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
/* minimal requirement of SUSv2 */
#define WCIO_UNGETWC_BUFSIZE 1
#define WCIO_INIT(fp) \
memset(&(_EXT(fp)->_wcio), 0, sizeof(struct wchar_io_data))
+__END_DECLS
+
#endif /*_WCIO_H_*/