home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
CPM
/
BDSC
/
BDSC-4
/
BDSLIB.ARK
/
FREAD.C
< prev
next >
Wrap
Text File
|
1983-07-15
|
1KB
|
59 lines
/*
* fread
* This function conforms as closely as possible to the function
* provided by the Version 7 U**X C Library. It reads at most
* `nitems' objects of size `size' from `stream' into memory at
* the location specified by `ptr'. It returns the number of
* items read or zero if error or end of file occurs.
* Last Edit 7/1/83
*/
int
fread(ptr, size, nitems, stream)
char *ptr;
int size, nitems;
FILE *stream;
{
int bytesread;
int c, i;
for (i = 0; i < nitems; i++) {
for (bytesread = 0; bytesread < size; bytesread++) {
c = fgetc(stream);
if (feof(stream) || ferror(stream))
return i;
*ptr++ = c;
}
}
return i;
}
/*
* fwrite
* This function conforms as closely as possible to the function
* provided by the Version 7 U**X C Library. It writes at most
* `nitems' objects of size `size' from `stream' from memory at
* the location specified by `ptr'. It returns the number of
* items written or zero if error or end of file occurs.
* Last Edit 7/1/83
*/
int
fwrite(ptr, size, nitems, stream)
char *ptr;
int size, nitems;
FILE *stream;
{
int bytesread;
int i;
for (i = 0; i < nitems; i++) {
for (bytesread = 0; bytesread < size; bytesread++) {
fputc(*ptr++, stream);
if (ferror(stream))
return i;
}
}
return i;
}