netinet/in.h: add IPPROTO_MH
[uclibc-ng.git] / libc / stdio / __fsetlocking.c
blob6d4fc18b8e5885e327d20bdd67ae9189c2d35d60
1 /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
3 * GNU Library General Public License (LGPL) version 2 or later.
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
6 */
8 #include "_stdio.h"
9 #include <stdio_ext.h>
12 /* Not threadsafe. */
14 /* Notes:
15 * When setting the locking mode, glibc returns the previous setting.
16 * glibc treats invalid locking_mode args as FSETLOCKING_INTERNAL.
19 int __fsetlocking(FILE *stream, int locking_mode)
21 #ifdef __UCLIBC_HAS_THREADS__
22 int current = 1 + (stream->__user_locking & 1);
24 /* Check constant assumptions. We can't test at build time
25 * since these are enums. */
26 assert((FSETLOCKING_QUERY == 0) && (FSETLOCKING_INTERNAL == 1)
27 && (FSETLOCKING_BYCALLER == 2));
29 __STDIO_STREAM_VALIDATE(stream);
30 assert(((unsigned int) locking_mode) <= 2);
32 if (locking_mode != FSETLOCKING_QUERY) {
33 stream->__user_locking = ((locking_mode == FSETLOCKING_BYCALLER)
34 ? 1
35 : _stdio_user_locking); /* 0 or 2 */
36 __STDIO_STREAM_VALIDATE(stream);
39 return current;
40 #else
41 __STDIO_STREAM_VALIDATE(stream);
42 assert(((unsigned int) locking_mode) <= 2);
44 return FSETLOCKING_INTERNAL;
45 #endif
47 libc_hidden_def(__fsetlocking)