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);
  10. #ifdef __DO_UNLOCKED
  11. weak_alias(__fgetws_unlocked,fgetws_unlocked);
  12. #ifndef __UCLIBC_HAS_THREADS__
  13. weak_alias(__fgetws_unlocked,fgetws);
  14. #endif
  15. wchar_t *__fgetws_unlocked(wchar_t *__restrict ws, int n,
  16. FILE *__restrict stream)
  17. {
  18. register wchar_t *p = ws;
  19. wint_t wi;
  20. __STDIO_STREAM_VALIDATE(stream);
  21. while ((n > 1)
  22. && ((wi = __fgetwc_unlocked(stream)) != WEOF)
  23. && ((*p++ = wi) != '\n')
  24. ) {
  25. --n;
  26. }
  27. if (p == ws) {
  28. /* TODO -- should we set errno? */
  29. /* if (n <= 0) { */
  30. /* errno = EINVAL; */
  31. /* } */
  32. return NULL;
  33. }
  34. *p = 0;
  35. return ws;
  36. }
  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