fgetws.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. libc_hidden_proto(fgetws_unlocked)
  9. libc_hidden_proto(fgetwc_unlocked)
  10. #ifdef __DO_UNLOCKED
  11. wchar_t *fgetws_unlocked(wchar_t *__restrict ws, int n,
  12. FILE *__restrict stream)
  13. {
  14. register wchar_t *p = ws;
  15. wint_t wi;
  16. __STDIO_STREAM_VALIDATE(stream);
  17. while ((n > 1)
  18. && ((wi = fgetwc_unlocked(stream)) != WEOF)
  19. && ((*p++ = wi) != '\n')
  20. ) {
  21. --n;
  22. }
  23. if (p == ws) {
  24. /* TODO -- should we set errno? */
  25. /* if (n <= 0) { */
  26. /* errno = EINVAL; */
  27. /* } */
  28. return NULL;
  29. }
  30. *p = 0;
  31. return ws;
  32. }
  33. libc_hidden_def(fgetws_unlocked)
  34. #ifndef __UCLIBC_HAS_THREADS__
  35. strong_alias(fgetws_unlocked,fgetws)
  36. #endif
  37. #elif defined __UCLIBC_HAS_THREADS__
  38. wchar_t *fgetws(wchar_t *__restrict ws, int n, FILE *__restrict stream)
  39. {
  40. wchar_t *retval;
  41. __STDIO_AUTO_THREADLOCK_VAR;
  42. __STDIO_AUTO_THREADLOCK(stream);
  43. retval = fgetws_unlocked(ws, n, stream);
  44. __STDIO_AUTO_THREADUNLOCK(stream);
  45. return retval;
  46. }
  47. #endif