__fsetlocking.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #include "_stdio.h"
  8. #include <stdio_ext.h>
  9. libc_hidden_proto(__fsetlocking)
  10. #ifdef __UCLIBC_HAS_THREADS__
  11. libc_hidden_proto(_stdio_user_locking)
  12. #endif
  13. /* 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.
  17. */
  18. int __fsetlocking(FILE *stream, int locking_mode)
  19. {
  20. #ifdef __UCLIBC_HAS_THREADS__
  21. int current = 1 + (stream->__user_locking & 1);
  22. /* Check constant assumptions. We can't test at build time
  23. * since these are enums. */
  24. assert((FSETLOCKING_QUERY == 0) && (FSETLOCKING_INTERNAL == 1)
  25. && (FSETLOCKING_BYCALLER == 2));
  26. __STDIO_STREAM_VALIDATE(stream);
  27. assert(((unsigned int) locking_mode) <= 2);
  28. if (locking_mode != FSETLOCKING_QUERY) {
  29. stream->__user_locking = ((locking_mode == FSETLOCKING_BYCALLER)
  30. ? 1
  31. : _stdio_user_locking); /* 0 or 2 */
  32. __STDIO_STREAM_VALIDATE(stream);
  33. }
  34. return current;
  35. #else
  36. __STDIO_STREAM_VALIDATE(stream);
  37. assert(((unsigned int) locking_mode) <= 2);
  38. return FSETLOCKING_INTERNAL;
  39. #endif
  40. }
  41. libc_hidden_def(__fsetlocking)