home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / program / lynxlib / ffile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-23  |  1.3 KB  |  60 lines

  1. /* This source file is part of the LynxLib miscellaneous library by
  2. Robert Fischer, and is Copyright 1990 by Robert Fischer.  It costs no
  3. money, and you may not make money off of it, but you may redistribute
  4. it.  It comes with ABSOLUTELY NO WARRANTY.  See the file LYNXLIB.DOC
  5. for more details.
  6. To contact the author:
  7.     Robert Fischer \\80 Killdeer Rd \\Hamden, CT   06517   USA
  8.     (203) 288-9599     fischer-robert@cs.yale.edu                 */
  9.  
  10. #include <stdio.h>
  11. #include <vfile.h>
  12.  
  13. /* VFILE driver for normal C streams */
  14.  
  15.  
  16. f_putc(c, f)
  17. char c;
  18. FILE *f;
  19. {
  20.     putc(c, f);
  21. }
  22.  
  23. int f_getc(f)
  24. FILE *f;
  25. {
  26.     return getc(f);
  27. }
  28.  
  29. int f_eof(f)
  30. FILE *f;
  31. {
  32.     return feof(f);
  33. }
  34.  
  35. /* -------------------------------------------------------- */
  36. extern fclose();
  37.  
  38. VFILE *open_ffile(name, mode)    /* Works just like fopen() */
  39. char *name;
  40. char *mode;
  41. {
  42. VFILE *v;
  43.     v = malloc(sizeof(*v));
  44.     v->curpos = &ftell;
  45.     v->do_eof = &f_eof;
  46.     v->do_getc = &f_getc;
  47.     v->do_putc = &f_putc;
  48.     v->do_close = &fclose;
  49.     if (name == NULL) {        /* Don't open, just bind to an old open file, given in mode */
  50.         v->p = mode;
  51.         return v;
  52.     }
  53.     if ((v->p = fopen(name, mode)) == 0) {
  54.         free(v);
  55.         return 0;
  56.     }
  57.     return v;
  58. }
  59. /* -------------------------------------------------------- */
  60.