home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 161_01 / fdlib.c < prev    next >
C/C++ Source or Header  |  1985-08-29  |  933b  |  61 lines

  1. #include <stdio.h>
  2. #include "config.h"
  3. #include "timer1.h"
  4.  
  5. FILE *fp;
  6. int fd;
  7. int i;
  8. char buf[BUFSIZ];
  9. static char buf100[] = "1   2   3   4   5   6   7   8   9   10  \
  10. 11  12  13  14  15  16  17  18  19  20  21  22  23  24  25 \n";
  11.  
  12. fp = fopen("100kc", "r");
  13. if (fp == NULL)
  14.     {
  15.     fp = fopen("100kc", "w");
  16.     for (i = 0; i < 1000; ++i)
  17.         fprintf(fp, buf100);
  18.     }
  19. fclose(fp);
  20.  
  21. fp = fopen("tmpforw", "w");
  22. fclose(fp);
  23. DO_STMT("open, close")
  24.     {
  25.     fd = open("tmpforw", 1);
  26.     close(fd);
  27.     }
  28. OD
  29.  
  30. fd = open("100kc", 0);
  31. DO_STMT("read-BUFSIZ chars")
  32.     {
  33.     if (read(fd, buf, BUFSIZ) < BUFSIZ)
  34.         {
  35.         lseek(fd, 0L, 0);
  36.         }
  37.     }
  38. OD
  39. close(fd);
  40.  
  41.  
  42. fd = open("100kc", 0);
  43. DO_STMT("lseek, read-BUFSIZ")
  44.     {
  45.     lseek(fd, (long)(i = (i + BUFSIZ) & 32767), 0);
  46.     read(fd, buf, BUFSIZ);
  47.     }
  48. OD
  49. close(fd);
  50.  
  51. fd = open(JUNKFILE, 1);
  52. DO_STMT("write-BUFSIZ chars")
  53.     {
  54.     write(fd, buf, BUFSIZ);
  55.     }
  56. OD
  57. close(fd);
  58.  
  59.  
  60. }
  61.