Mail Archives: djgpp/1998/05/03/10:40:07
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).
- Raw text -