tpi_read.c 682 B

123456789101112131415161718192021222324252627282930313233
  1. #include "tpi_daytime.h"
  2. ssize_t
  3. tpi_read(int fd, void *buf, size_t len)
  4. {
  5. struct strbuf ctlbuf;
  6. struct strbuf datbuf;
  7. union T_primitives rcvbuf;
  8. int flags;
  9. ctlbuf.maxlen = sizeof(union T_primitives);
  10. ctlbuf.buf = (char *) &rcvbuf;
  11. datbuf.maxlen = len;
  12. datbuf.buf = buf;
  13. datbuf.len = 0;
  14. flags = 0;
  15. Getmsg(fd, &ctlbuf, &datbuf, &flags);
  16. if (ctlbuf.len >= (int) sizeof(long)) {
  17. if (rcvbuf.type == T_DATA_IND)
  18. return(datbuf.len);
  19. else if (rcvbuf.type == T_ORDREL_IND)
  20. return(0);
  21. else
  22. err_quit("tpi_read: unexpected type %d", rcvbuf.type);
  23. } else if (ctlbuf.len == -1)
  24. return(datbuf.len);
  25. else
  26. err_quit("tpi_read: bad length from getmsg");
  27. }