home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!munnari.oz.au!goanna!ok
- From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
- Newsgroups: comp.std.c
- Subject: Re: Operations on Files
- Keywords: ANSI C, files
- Message-ID: <14335@goanna.cs.rmit.oz.au>
- Date: 3 Sep 92 12:10:40 GMT
- References: <robertl.4.715452734@county.lmt.mn.org>
- Organization: Comp Sci, RMIT, Melbourne, Australia
- Lines: 40
-
- In article <robertl.4.715452734@county.lmt.mn.org>, robertl@county.lmt.mn.org (ROBERT LAUMEYER) writes:
- >
- > The ANSI C standard seems to have a rather odd mix of file
- > operations. Why didn't they add (over K&R) some other useful file
- > operations such as fileexist, getfirst, getnext, etc? It seems that
- > these could not be much more dependent on the underlying file system than
- > rename or remove.
-
- What are getfirst and getnext? If they are the MS-DOS functions, don't
- forget that
- (a) wild-cards are very OS-dependent. (Indeed, not all UNIX shells offer
- the same set of wild-cards.)
- (b) When multiple threads may modify the file system (e.g. a multi-user
- system, or a file server accessed by many PCs), it is not altogether
- clear what getnext should do when the file system has _changed_ since
- the original call to getfirst.
- (c) there are _other_ file system interfaces, such as the ftw() function,
- with at least as good a claim to standardisation.
-
- Basically, if we had waited for a really good set of file system operations
- we'd _still_ be waiting.
-
- As for fileexist, what does that _mean_? Does a file "exist" for you
- if you are not permitted to inspect the directory containing its name?
- Even if a file exists, if you are about to run out of file descriptors
- or stream buffers you may not be able to open it.
-
- A reasonably good workaround is
-
- int file_exists(const char *file_name)
- {
- FILE *stream;
- stream = fopen(file_name, "rb");
- if (stream != NULL) fclose(stream);
- return stream != NULL;
- }
-
- This at least answers a useful question: "would I be able to open this file?"
- --
- You can lie with statistics ... but not to a statistician.
-