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