sysstatread.c 653 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <u.h>
  2. #include <lib9.h>
  3. // Change-Id: I1cfd642d29a3955499b3507f56f0449d1710700e
  4. // sys/src/nxm/port/devcons.c:
  5. // make reads on #c/sysstat return only as many bytes as
  6. // requested
  7. void
  8. main(void)
  9. {
  10. int ret; // 0 = pass, 1 = fail
  11. int fd, n;
  12. char buf[1];
  13. fd = sys_open("/dev/sysstat", OREAD);
  14. if(fd < 0){
  15. print("FAIL: couldn't open /dev/sysstat: %r\n");
  16. exits("FAIL");
  17. }
  18. ret = 0;
  19. for(;;){
  20. n = jehanne_read(fd, buf, sizeof(buf));
  21. if(n <= 0)
  22. break;
  23. if(n > sizeof(buf))
  24. ret = 1;
  25. }
  26. sys_close(fd);
  27. if(ret){
  28. print("FAIL: %d bytes read from /dev/sysstat\n", n);
  29. exits("FAIL");
  30. }
  31. print("PASS\n");
  32. exits("PASS");
  33. }