__fsetlocking.c 1.2 KB

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