wr_bytes.c 725 B

12345678910111213141516171819202122232425262728293031323334
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. #include "obj.h"
  7. #include <unistd.h>
  8. void wr_fatal();
  9. #define MININT (1 << (sizeof(int) * 8 - 1))
  10. #define MAXCHUNK (~MININT) /* Highest count we write(2). */
  11. /* Notice that MAXCHUNK itself might be too large with some compilers.
  12. You have to put it in an int!
  13. */
  14. static int maxchunk = MAXCHUNK;
  15. /*
  16. * Just write "cnt" bytes to file-descriptor "fd".
  17. */
  18. void wr_bytes(int fd, char *string, long cnt)
  19. {
  20. while (cnt) {
  21. int n = cnt >= maxchunk ? maxchunk : cnt;
  22. if (write(fd, string, n) != n)
  23. wr_fatal();
  24. string += n;
  25. cnt -= n;
  26. }
  27. }