lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org> |
| 2 | * |
| 3 | * GNU Library General Public License (LGPL) version 2 or later. |
| 4 | * |
| 5 | * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details. |
| 6 | */ |
| 7 | |
| 8 | #include "_stdio.h" |
| 9 | #include <stdio_ext.h> |
| 10 | |
| 11 | |
| 12 | /* Not threadsafe. */ |
| 13 | |
| 14 | /* Notes: |
| 15 | * When setting the locking mode, glibc returns the previous setting. |
| 16 | * glibc treats invalid locking_mode args as FSETLOCKING_INTERNAL. |
| 17 | */ |
| 18 | |
| 19 | int __fsetlocking(FILE *stream, int locking_mode) |
| 20 | { |
| 21 | #ifdef __UCLIBC_HAS_THREADS__ |
| 22 | int current = 1 + (stream->__user_locking & 1); |
| 23 | |
| 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)); |
| 28 | |
| 29 | __STDIO_STREAM_VALIDATE(stream); |
| 30 | assert(((unsigned int) locking_mode) <= 2); |
| 31 | |
| 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); |
| 37 | } |
| 38 | |
| 39 | return current; |
| 40 | #else |
| 41 | __STDIO_STREAM_VALIDATE(stream); |
| 42 | assert(((unsigned int) locking_mode) <= 2); |
| 43 | |
| 44 | return FSETLOCKING_INTERNAL; |
| 45 | #endif |
| 46 | } |
| 47 | libc_hidden_def(__fsetlocking) |