1
0

fputws.c 519 B

1234567891011121314151617181920212223242526272829
  1. #include "stdio_impl.h"
  2. #include "locale_impl.h"
  3. #include <wchar.h>
  4. int fputws(const wchar_t *restrict ws, FILE *restrict f)
  5. {
  6. unsigned char buf[BUFSIZ];
  7. size_t l=0;
  8. locale_t *ploc = &CURRENT_LOCALE, loc = *ploc;
  9. FLOCK(f);
  10. fwide(f, 1);
  11. *ploc = f->locale;
  12. while (ws && (l = wcsrtombs((void *)buf, (void*)&ws, sizeof buf, 0))+1 > 1)
  13. if (__fwritex(buf, l, f) < l) {
  14. FUNLOCK(f);
  15. *ploc = loc;
  16. return -1;
  17. }
  18. FUNLOCK(f);
  19. *ploc = loc;
  20. return l; /* 0 or -1 */
  21. }
  22. weak_alias(fputws, fputws_unlocked);