home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume2 / advsys / part03 / advfio.c < prev    next >
C/C++ Source or Header  |  1987-10-23  |  936b  |  64 lines

  1.  
  2. /* advfio.c - file i/o routines for the adventure compiler */
  3. /*
  4.     Copyright (c) 1986, by David Michael Betz
  5.     All rights reserved
  6. */
  7.  
  8. #define BSIZE    8192
  9.  
  10. /* global variables */
  11. long ad_foff;
  12.  
  13. /* external routines */
  14. extern long lseek();
  15.  
  16. /* local variables */
  17. static char buf[BSIZE];
  18. static int boff;
  19. static int fd;
  20.  
  21. ad_create(name)
  22.   char *name;
  23. {
  24.     /* create the file */
  25.     if ((fd = creat(name,0666)) < 0)
  26.     fail("can't create output file");
  27.     
  28.     /* initialize the buffer and file offset */
  29.     ad_foff = 0L;
  30.     boff = 0;
  31. }
  32.  
  33. ad_close()
  34. {
  35.     ad_flush();
  36.     close(fd);
  37. }
  38.  
  39. ad_putc(ch)
  40.   int ch;
  41. {
  42.     buf[boff++] = ch; ad_foff++;
  43.     if (boff >= BSIZE)
  44.     ad_flush();
  45. }
  46.  
  47. ad_seek(pos)
  48.   long pos;
  49. {
  50.     ad_flush();
  51.     if (lseek(fd,pos,0) != pos)
  52.     fail("error positioning output file");
  53.     ad_foff = pos;
  54. }
  55.  
  56. ad_flush()
  57. {
  58.     if (boff) {
  59.     if (write(fd,buf,boff) != boff)
  60.         fail("error writing to output file");
  61.     boff = 0;
  62.     }
  63. }
  64.