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 >
Wrap
C/C++ Source or Header
|
1993-10-23
|
3KB
|
91 lines
/* This source file is part of the LynxLib miscellaneous library by
Robert Fischer, and is Copyright 1990 by Robert Fischer. It costs no
money, and you may not make money off of it, but you may redistribute
it. It comes with ABSOLUTELY NO WARRANTY. See the file LYNXLIB.DOC
for more details.
To contact the author:
Robert Fischer \\80 Killdeer Rd \\Hamden, CT 06517 USA
(203) 288-9599 fischer-robert@cs.yale.edu */
/* A few support files for VFILE.H */
#include <vfile.h>
#include <stdio.h>
BOOLEAN read_bytes(in, num, outbuf) /* Reads num bytes from in to outbuf */
/* Returns FALSE if not all could be read */
VFILE *in; /* File to read from */
long num; /* number of bytes to read */
register BYTE *outbuf; /* File to read to */
{
register BYTE *end;
end = outbuf + num;
while (outbuf != end)
*(outbuf++) = vgetc(in);
return !veof(in);
}
/* -------------------------------------------------------- */
unsigned vfread(buf, size, num, file) /* Analog of fread() */
/* Returns number of chars read */
char *buf; /* Buf to read to */
unsigned size; /* Size of data objects */
unsigned num; /* Number of objects */
VFILE *file; /* File to read from */
{
register char *end;
long lsize, lnum;
register char *read; /* Number of chars read */
register int i;
lsize = size;
lnum = num;
end = buf + (lsize * lnum);
read = buf;
while (read != end) {
if ((i=vgetc(file)) == EOF) return (unsigned)((read-buf)/lsize);
*(read++) = (char)i;
}
return num;
}
/* -------------------------------------------------------- */
BOOLEAN write_bytes(out, num, inbuf) /* Writes bytes to out from inbuf */
/* Returns FALSE if not all could be written */
VFILE *out; /* File to write to */
long num; /* number of bytes to read */
register BYTE *inbuf; /* Buffer to read from */
{
register BYTE *end;
end = inbuf + num;
while (inbuf != end)
vputc(*(inbuf++), out);
return !veof(out);
}
/* -------------------------------------------------------- */
long vfwrite(buf, size, num, file) /* Analog of fwrite() */
/* As a hack, this does not return any error, ever. It always returns
num, pretending there's no error. */
char *buf; /* Buf to read to */
unsigned size; /* Size of data objects */
unsigned num; /* Number of objects */
VFILE *file; /* File to read from */
{
register char *end;
long lsize, lnum;
lsize = size;
lnum = num;
end = buf + (lsize * lnum);
while (buf != end)
vputc(*(buf++), file);
return num;
}
/* -------------------------------------------------------- */
BOOLEAN vputs(out, s) /* Writes the string s to out, doesn't append '\n' */
VFILE *out; /* File to write to */
register char *s; /* String to write */
{
while (*s != NIL)
vputc(*(s++), out);
return !veof(out);
}
/* -------------------------------------------------------- */