Mail Archives: djgpp/1997/08/23/03:34:59
Marco Monteiro wrote:
>Hello,
>
> how can i inspect if a file exists?
> I'm using the function following function; is there a better one?
>
Marco,
Perusing the DJGPP libc sources, it seems to me that access(filename,
R_OK) will give you the results that you want, without the overhead of
an fopen and an fclose. Just call:
access("filename.ext", R_OK)
Zero return value means the file is available for reading, which
implies that it actually exists. So this code should work:
if (access("filename.ext", R_OK)) {
fprint("FILE %s does not exist\n", "filename.ext");
exit(1);
}
/* From here on we know the file exists... */
----------------------------------------------------
Peter J. Farley III (pjfarley AT dorsai DOT org)
- Raw text -