Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!ucbcad!ucbvax!decvax!minow From: minow@decvax.UUCP (Martin Minow) Newsgroups: comp.sys.atari.st Subject: Re: FILE I/O Message-ID: <183@decvax.UUCP> Date: Tue, 10-Nov-87 20:05:29 EST Article-I.D.: decvax.183 Posted: Tue Nov 10 20:05:29 1987 Date-Received: Fri, 13-Nov-87 03:57:41 EST References: <2023@homxc.UUCP> Reply-To: minow@decvax.UUCP (Martin Minow) Organization: Digital Eq. Corp. - Merrimack NH. Lines: 108 Keywords: Mark Williams C, Fseek, fseek In article <2023@homxc.UUCP> jdn@homxc.UUCP (J.NAGY) asks about the difference between Fseek and fseek (etc.), noting that they look quite similar. The "lower-case" functions match the C stdio library routines. The "Upper-case" functions are direct calls to the operating system. (As such, they are closer to lseek(), open(), etc.) As noted, the lower-case functions are generally preferable for portability. The Upper-case functions are the only ones that can be used in a desk accessory (they don't expand memory). They are *much* harder to use. As a public-service, I'm including a small open a file and read a byte routine. The code is made ugly as the operating system doesn't seem to have a notion of "end of file." (It's extracted from a longer program and untested as such, so use it as a model only.) Martin Minow decvax!minow ----- #include #include #define FileBufferSize 512 typedef struct { int handle; long filesize; long offset; char *bp; char *ep; char buffer[FileBufferSize]; } FileInfo; #define FileTell(fid) ((fid)->offset) #define strchr index /* Brain-damaged Software Dev. */ FileInfo InFile; char filename[64]; /* Stores file name for open */ typeout(infile) char *infile; { register int c; if (strchr(infile, ':') == NULL && strchr(infile, '\\') == NULL) { filename[0] = Dgetdrv() + 'a'; filename[1] = ':'; filename[2] = EOS; Dgetpath(&filename[2], 0); /* Must use "default" here */ strcat(filename, "\\"); strcat(filename, infile); } else { strcpy(filename, infile); /* User specified drive name */ } if (FileOpen(&InFile, filename, 0) < 0) { Cconws("Can't open the file\r\n"); Pterm(1); } while ((c = FileGetc(&InFile)) != EOF) Cconout(c); Fclose(Infile.handle); Pterm(0); } int FileOpen(fid, filename, mode) register FileInfo *fid; /* Store stuff here */ char *filename; /* Fully-qualified file name */ int mode; /* Open mode */ { DMABUFFER stupid; /* Needed to get file size */ int status; Fsetdta(&stupid); if ((status = Fsfirst(filename, 0)) < 0) return (status); fid->filesize = stupid.d_fsize; fid->offset = 0; fid->bp = fid->ep = NULL; fid->handle = Fopen(filename, mode); return (fid->handle); } int FileGetc(fid) register FileInfo *fid; { register long readsize; register int result; if (fid->offset >= fid->filesize) return (EOF); while (fid->bp >= fid->ep) { readsize = fid->filesize - fid->offset; if (readsize > FileBufferSize) readsize = FileBufferSize; if ((readsize = Fread(fid->handle, readsize, fid->buffer)) <= 0) return (EOF); fid->bp = &fid->buffer[0]; fid->ep = &fid->buffer[readsize]; } fid->offset++; return(*fid->bp++ & 0xFF); }