outcpt.c 975 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. *
  5. * This product is part of the Amsterdam Compiler Kit.
  6. *
  7. * Permission to use, sell, duplicate or disclose this software must be
  8. * obtained in writing. Requests for such permissions may be sent to
  9. *
  10. * Dr. Andrew S. Tanenbaum
  11. * Wiskundig Seminarium
  12. * Vrije Universiteit
  13. * Postbox 7161
  14. * 1007 MC Amsterdam
  15. * The Netherlands
  16. *
  17. */
  18. /* Author: J.W. Stevenson */
  19. #include <stdlib.h>
  20. #include <errno.h>
  21. #include <unistd.h>
  22. #include <pc_file.h>
  23. #include <pc_err.h>
  24. extern _trp();
  25. _flush(f) struct file *f; {
  26. int i,n;
  27. f->ptr = f->bufadr;
  28. n = f->buflen - f->count;
  29. if (n <= 0)
  30. return;
  31. f->count = f->buflen;
  32. if ((i = write(f->ufd,f->bufadr,n)) < 0 && errno == EINTR)
  33. return;
  34. if (i != n)
  35. _trp(EWRITE);
  36. }
  37. _outcpt(f) struct file *f; {
  38. f->flags &= ~ELNBIT;
  39. f->ptr += f->size;
  40. if ((f->count -= f->size) <= 0)
  41. _flush(f);
  42. }