fputwc.c 605 B

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