home *** CD-ROM | disk | FTP | other *** search
- /*
- * 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;
- }