fwide.c 826 B

1234567891011121314151617181920212223242526272829303132
  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. /* TODO: According to SUSv3 should return EBADF if invalid stream. */
  9. int fwide(register FILE *stream, int mode)
  10. {
  11. __STDIO_AUTO_THREADLOCK_VAR;
  12. __STDIO_AUTO_THREADLOCK(stream);
  13. __STDIO_STREAM_VALIDATE(stream);
  14. if (mode && !(stream->__modeflags & (__FLAG_WIDE|__FLAG_NARROW))) {
  15. stream->__modeflags |= ((mode > 0) ? __FLAG_WIDE : __FLAG_NARROW);
  16. }
  17. mode = (stream->__modeflags & __FLAG_WIDE)
  18. - (stream->__modeflags & __FLAG_NARROW);
  19. assert((stream->__modeflags & (__FLAG_WIDE|__FLAG_NARROW))
  20. != (__FLAG_WIDE|__FLAG_NARROW));
  21. __STDIO_AUTO_THREADUNLOCK(stream);
  22. return mode;
  23. }