__fsetlocking.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. /* Not threadsafe. */
  11. /* Notes:
  12. * When setting the locking mode, glibc returns the previous setting.
  13. * glibc treats invalid locking_mode args as FSETLOCKING_INTERNAL.
  14. */
  15. int __fsetlocking(FILE *stream, int locking_mode)
  16. {
  17. #ifdef __UCLIBC_HAS_THREADS__
  18. int current = 1 + (stream->__user_locking & 1);
  19. /* Check constant assumptions. We can't test at build time
  20. * since these are enums. */
  21. assert((FSETLOCKING_QUERY == 0) && (FSETLOCKING_INTERNAL == 1)
  22. && (FSETLOCKING_BYCALLER == 2));
  23. __STDIO_STREAM_VALIDATE(stream);
  24. assert(((unsigned int) locking_mode) <= 2);
  25. if (locking_mode != FSETLOCKING_QUERY) {
  26. stream->__user_locking = ((locking_mode == FSETLOCKING_BYCALLER)
  27. ? 1
  28. : _stdio_user_locking); /* 0 or 2 */
  29. __STDIO_STREAM_VALIDATE(stream);
  30. }
  31. return current;
  32. #else
  33. __STDIO_STREAM_VALIDATE(stream);
  34. assert(((unsigned int) locking_mode) <= 2);
  35. return FSETLOCKING_INTERNAL;
  36. #endif
  37. }
  38. libc_hidden_def(__fsetlocking)