Date: Sun, 3 May 1998 17:38:17 +0300 (IDT) From: Eli Zaretskii To: "Salvador Eduardo Tropea (SET)" cc: djgpp AT delorie DOT com Subject: Re: fstat and stat in a Novell disk (fstat have a flaw) In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Wed, 29 Apr 1998, Salvador Eduardo Tropea (SET) wrote: > I have some questions about fstat/stat. I found they work VERY > different. They are different, indeed. Neither DOS nor Windows don't let you know the full pathname of a file given the handle on which it is open, so there's no way these two could do exactly the same. I wouldn't use the words ``VERY different'', though. Is there any other difference in the results except the write bit? If so, please tell what other discrepancies did you see. > But when using fstat it > uses some SFT(?) table, I don't know what's that, anyways, Novell > doesn't support it and hence libc just gives a general description, > that means: the file have read access because DOS ever have it, but > no write access just in case. This is documented behavior, see "info libc alpha fstat", under ``Implementation Notes''. You just cannot get at the file attributes under Novell on plain DOS, period. > That's bad for my editor because it detects the files as > read-only. I'm using stat because I want to get the program working > on UNIX. If you use `stat', it should report the file attributes under Novell as well; only `fstat' has this problem. If you cannot use `stat', a work-around would be to just try writing to the file, and if you get EACCES, treat it as if the file were not writable by the user. > Now the question is: why fstat can't use the file attributes to > solve it? Why don't you ask how does `fstat' succeed to report file attributes at all? There is no DOS call which allows to access file attributes given a handle alone, and as I said above, you can't get the file name by its handle. The DJGPP implementation of `fstat' goes out of its way--and succeeds--to compute them correctly under DOS and Windows 9X, but it fails under Novell versions which bypass DOS file-oriented data structures. You should look at the source code for `fstat' some day, to see how hard it is to report Unix-compatible results. Windows 9X adds a function to report file info given a handle, so on Windows `fstat' works correctly (you need the latest `fstat' from Tom Demmer's site or from the latest v2.02 alpha, to have this feature, as it was only introduced lately).