fputwc.c 663 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "stdio_impl.h"
  2. #include <wchar.h>
  3. #include <limits.h>
  4. #include <ctype.h>
  5. wint_t __fputwc_unlocked(wchar_t c, FILE *f)
  6. {
  7. char mbc[MB_LEN_MAX];
  8. int l;
  9. f->mode |= f->mode+1;
  10. if (isascii(c)) {
  11. c = putc_unlocked(c, f);
  12. } else if (f->wpos + MB_LEN_MAX < f->wend) {
  13. l = wctomb((void *)f->wpos, c);
  14. if (l < 0) c = WEOF;
  15. else f->wpos += l;
  16. } else {
  17. l = wctomb(mbc, c);
  18. if (l < 0 || __fwritex((void *)mbc, l, f) < l) c = WEOF;
  19. }
  20. return c;
  21. }
  22. wint_t fputwc(wchar_t c, FILE *f)
  23. {
  24. FLOCK(f);
  25. c = __fputwc_unlocked(c, f);
  26. FUNLOCK(f);
  27. return c;
  28. }
  29. weak_alias(__fputwc_unlocked, fputwc_unlocked);
  30. weak_alias(__fputwc_unlocked, putwc_unlocked);