fgetws.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. extern wchar_t *__fgetws_unlocked(wchar_t *__restrict ws, int n,
  9. FILE *__restrict stream) attribute_hidden;
  10. #ifdef __DO_UNLOCKED
  11. wchar_t attribute_hidden *__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. weak_alias(__fgetws_unlocked,fgetws_unlocked)
  34. #ifndef __UCLIBC_HAS_THREADS__
  35. weak_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