Ethereal-dev: Re: [Ethereal-dev] file_exists() returning the oposite?

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: "Guy Harris" <gharris@xxxxxxxxx>
Date: Tue, 7 Feb 2006 17:06:27 -0800 (PST)
LEGO wrote:
> I realy do not know if file_exists() from epan/filesystem.c works on
> windows but I've seen it does not on my mac and AFAIK it should not
> work on *NIX in general.

    ...

>   /*
>    * This is a bit tricky on win32. The st_ino field is documented as:
>    * "The inode, and therefore st_ino, has no meaning in the FAT, ..."
>    * but it *is* set to zero if stat() returns without an error,
>    * so this is working, but maybe not quite the way expected. ULFL
>    */
>    file_stat.st_ino = 1;   /* this will make things work if an error
> occured */
>    eth_stat(fname, &file_stat);

Is there some reason why we don't simply check whether eth_stat() returns
-1 or not?  On UN*X, to test whether a file exists, you would probably try
to stat it and, if the stat fails with ENOENT, say it doesn't exist,
otherwise (i.e., if it succeeds *or* if it fails and sets errno to
something other than ENOENT) say it does (even if we don't have permission
to look for it).

Would that work on Windows as well?

(We should also be checking for eth_stat() succeeding or failing in
files_equal() on UN*X, rather than doing the hack with the two st_ino
values.)