fgetws.c 1.1 KB

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