iofwrite_u.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Copyright (C) 1993-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>.
  14. As a special exception, if you link the code in this file with
  15. files compiled with a GNU compiler to produce an executable,
  16. that does not cause the resulting executable to be covered by
  17. the GNU Lesser General Public License. This exception does not
  18. however invalidate any other reasons why the executable file
  19. might be covered by the GNU Lesser General Public License.
  20. This exception applies to code released by its copyright holders
  21. in files containing the exception. */
  22. #include "libioP.h"
  23. #include <stdio.h>
  24. #undef fwrite_unlocked
  25. size_t
  26. fwrite_unlocked (const void *buf, size_t size, size_t count, FILE *fp)
  27. {
  28. size_t request = size * count;
  29. size_t written = 0;
  30. CHECK_FILE (fp, 0);
  31. if (request == 0)
  32. return 0;
  33. if (_IO_fwide (fp, -1) == -1)
  34. {
  35. written = _IO_sputn (fp, (const char *) buf, request);
  36. /* We have written all of the input in case the return value indicates
  37. this or EOF is returned. The latter is a special case where we
  38. simply did not manage to flush the buffer. But the data is in the
  39. buffer and therefore written as far as fwrite is concerned. */
  40. if (written == request || written == EOF)
  41. return count;
  42. }
  43. return written / size;
  44. }
  45. libc_hidden_def (fwrite_unlocked)