int secure;
volatile int threads_minus_1;
size_t *auxv;
- FILE *ofl_head;
- volatile int ofl_lock[2];
size_t tls_size;
size_t page_size;
struct __locale_struct global_locale;
FILE *__fdopen(int, const char *);
int __fmodeflags(const char *);
-#define OFLLOCK() LOCK(libc.ofl_lock)
-#define OFLUNLOCK() UNLOCK(libc.ofl_lock)
+FILE *__ofl_add(FILE *f);
+FILE **__ofl_lock(void);
+void __ofl_unlock(void);
#define feof(f) ((f)->flags & F_EOF)
#define ferror(f) ((f)->flags & F_ERR)
if (!libc.threaded) f->lock = -1;
/* Add new FILE to open file list */
- OFLLOCK();
- f->next = libc.ofl_head;
- if (libc.ofl_head) libc.ofl_head->prev = f;
- libc.ofl_head = f;
- OFLUNLOCK();
-
- return f;
+ return __ofl_add(f);
}
weak_alias(__fdopen, fdopen);
void __stdio_exit(void)
{
FILE *f;
- OFLLOCK();
- for (f=libc.ofl_head; f; f=f->next) close_file(f);
+ for (f=*__ofl_lock(); f; f=f->next) close_file(f);
close_file(__stdin_used);
close_file(__stdout_used);
}
__unlist_locked_file(f);
if (!(perm = f->flags & F_PERM)) {
- OFLLOCK();
+ FILE **head = __ofl_lock();
if (f->prev) f->prev->next = f->next;
if (f->next) f->next->prev = f->prev;
- if (libc.ofl_head == f) libc.ofl_head = f->next;
- OFLUNLOCK();
+ if (*head == f) *head = f->next;
+ __ofl_unlock();
}
r = fflush(f);
r = __stdout_used ? fflush(__stdout_used) : 0;
- OFLLOCK();
- for (f=libc.ofl_head; f; f=f->next) {
+ for (f=*__ofl_lock(); f; f=f->next) {
FLOCK(f);
if (f->wpos > f->wbase) r |= __fflush_unlocked(f);
FUNLOCK(f);
}
- OFLUNLOCK();
+ __ofl_unlock();
return r;
}
if (!libc.threaded) f->lock = -1;
- OFLLOCK();
- f->next = libc.ofl_head;
- if (libc.ofl_head) libc.ofl_head->prev = f;
- libc.ofl_head = f;
- OFLUNLOCK();
-
- return f;
+ return __ofl_add(f);
}
--- /dev/null
+#include "stdio_impl.h"
+#include "libc.h"
+
+static FILE *ofl_head;
+static volatile int ofl_lock[2];
+
+FILE **__ofl_lock()
+{
+ LOCK(ofl_lock);
+ return &ofl_head;
+}
+
+void __ofl_unlock()
+{
+ UNLOCK(ofl_lock);
+}
--- /dev/null
+#include "stdio_impl.h"
+
+FILE *__ofl_add(FILE *f)
+{
+ FILE **head = __ofl_lock();
+ f->next = *head;
+ if (*head) (*head)->prev = f;
+ *head = f;
+ __ofl_unlock();
+ return f;
+}
if (!libc.threaded) f->lock = -1;
- OFLLOCK();
- f->next = libc.ofl_head;
- if (libc.ofl_head) libc.ofl_head->prev = f;
- libc.ofl_head = f;
- OFLUNLOCK();
-
- return f;
+ return __ofl_add(f);
}
if (!libc.threaded) f->lock = -1;
- OFLLOCK();
- f->next = libc.ofl_head;
- if (libc.ofl_head) libc.ofl_head->prev = f;
- libc.ofl_head = f;
- OFLUNLOCK();
-
- return f;
+ return __ofl_add(f);
}
if (!libc.can_do_threads) return ENOSYS;
self = __pthread_self();
if (!libc.threaded) {
- for (FILE *f=libc.ofl_head; f; f=f->next)
+ for (FILE *f=*__ofl_lock(); f; f=f->next)
init_file_lock(f);
+ __ofl_unlock();
init_file_lock(__stdin_used);
init_file_lock(__stdout_used);
init_file_lock(__stderr_used);