rd_bytes.c 761 B

1234567891011121314151617181920212223242526272829303132333435
  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. #define MININT (1 << (sizeof(int) * 8 - 1))
  9. #define MAXCHUNK (~MININT) /* Highest count we read(2). */
  10. /* Unfortunately, MAXCHUNK is too large with some compilers. Put it in
  11. an int!
  12. */
  13. void rd_fatal();
  14. static int maxchunk = MAXCHUNK;
  15. /*
  16. * We don't have to worry about byte order here.
  17. * Just read "cnt" bytes from file-descriptor "fd".
  18. */
  19. void rd_bytes(int fd, char *string, long cnt)
  20. {
  21. while (cnt) {
  22. register int n = cnt >= maxchunk ? maxchunk : cnt;
  23. if (read(fd, string, n) != n)
  24. rd_fatal();
  25. string += n;
  26. cnt -= n;
  27. }
  28. }