home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / program / lynxlib / vfile.c < prev    next >
C/C++ Source or Header  |  1993-10-23  |  3KB  |  91 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. /* A few support files for VFILE.H */
  11. #include <vfile.h>
  12. #include <stdio.h>
  13.  
  14. BOOLEAN read_bytes(in, num, outbuf) /* Reads num bytes from in to outbuf */
  15. /* Returns FALSE if not all could be read */
  16. VFILE *in;      /* File to read from */
  17. long num;       /* number of bytes to read */
  18. register BYTE *outbuf;  /* File to read to */
  19. {
  20. register BYTE *end;
  21.     end = outbuf + num;
  22.     while (outbuf != end)
  23.         *(outbuf++) = vgetc(in);
  24.     return !veof(in);
  25. }
  26. /* -------------------------------------------------------- */
  27. unsigned vfread(buf, size, num, file)            /* Analog of fread() */
  28. /* Returns number of chars read */
  29. char *buf;      /* Buf to read to */
  30. unsigned size;  /* Size of data objects */
  31. unsigned num;   /* Number of objects */
  32. VFILE *file;    /* File to read from */
  33. {
  34. register char *end;
  35. long lsize, lnum;
  36. register char *read;          /* Number of chars read */
  37. register int i;
  38.     lsize = size;
  39.     lnum = num;
  40.  
  41.     end = buf + (lsize * lnum);
  42.     read = buf;
  43.     while (read != end) {
  44.         if ((i=vgetc(file)) == EOF) return (unsigned)((read-buf)/lsize);
  45.         *(read++) = (char)i;
  46.     }
  47.     return num;
  48. }
  49. /* -------------------------------------------------------- */
  50. BOOLEAN write_bytes(out, num, inbuf)    /* Writes bytes to out from inbuf */
  51. /* Returns FALSE if not all could be written */
  52. VFILE *out;     /* File to write to */
  53. long num;       /* number of bytes to read */
  54. register BYTE *inbuf;   /* Buffer to read from */
  55. {
  56. register BYTE *end;
  57.     end = inbuf + num;
  58.     while (inbuf != end)
  59.         vputc(*(inbuf++), out);
  60.     return !veof(out);
  61. }
  62. /* -------------------------------------------------------- */
  63. long vfwrite(buf, size, num, file)            /* Analog of fwrite() */
  64. /* As a hack, this does not return any error, ever.  It always returns
  65.    num, pretending there's no error. */
  66. char *buf;      /* Buf to read to */
  67. unsigned size;  /* Size of data objects */
  68. unsigned num;   /* Number of objects */
  69. VFILE *file;    /* File to read from */
  70. {
  71. register char *end;
  72. long lsize, lnum;
  73.     lsize = size;
  74.     lnum = num;
  75.  
  76.     end = buf + (lsize * lnum);
  77.     while (buf != end)
  78.         vputc(*(buf++), file);
  79.     return num;
  80. }
  81. /* -------------------------------------------------------- */
  82. BOOLEAN vputs(out, s)   /* Writes the string s to out, doesn't append '\n' */
  83. VFILE *out;     /* File to write to */
  84. register char *s;        /* String to write */
  85. {
  86.     while (*s != NIL)
  87.         vputc(*(s++), out);
  88.     return !veof(out);
  89. }
  90. /* -------------------------------------------------------- */
  91.