[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]
[MD:1766] Bug fix of file-readable-p
- X-ml-count: 1766
- Subject: [MD:1766] Bug fix of file-readable-p
- From: Shun-ichi GOTO <gotoh@xxxxxxxxxxx>
- Date: Mon, 17 Apr 2000 21:22:54 +0900 (JST)
- X-mailer: Mew version 1.95b3 on Emacs 20.6 / Mule 4.1 (AOI)
Thanx for your suggestion.
>>>>> at Mon, 17 Apr 2000 14:08:32 +0200 (IST)
>>>>> eliz == Eli Zaretskii <eliz@xxxxxxxxxxxxx> said,
eliz> IIRC, `stat' fails (returns -1) on Windows for root directories. If I'm
eliz> right, this means that file-writable-p, as you suggest to patch it, will
eliz> return nil for any file in the root directory of any drive.
Now I made small program to check behavior of stat() of Microsoft Visual
C/C++ 6.0 (Emacs was compiled with it) and do test on Windows 2000 and
Windows 95.
----result---------------------------------------------------------------
Win2000 Win95
stat.exe / OK, dir OK, dir
stat.exe \ OK, dir OK, dir
stat.exe c:/ OK, dir OK, dir
stat.exe c:\ OK, dir OK, dir
stat.exe c: FAIL FAIL
stat.exe c:\autoexec.bat OK, file OK, file ... existing file
stat.exe c:\new-file.txt FAIL FAIL ... no file => stat() fail
stat.exe e:\ OK, dir OK, dir ... I have e: drive
stat.exe e: FAIL FAIL
stat.exe h:\ OK, dir OK, dir ... h: is network drive
stat.exe h: FAIL FAIL
stat.exe z:\ FAIL FAIL ... I don't have Z:
stat.exe z: FAIL FAIL
-------------------------------------------------------------------------
eliz> The test cases you included didn't check this case. Could you please
eliz> check that, both on Wndows NT and Windows 9X (if you have access to it)
eliz> and see if this problem indeed exists?
And I did additional test on original NT Emacs and patched one.
Both emacs make same result except non-existant drive.
I think that the patch works well.
----------------------------------
Original Patched
(file-writable-p "/new-file.txt") t t
(file-writable-p "/rw.txt") t t
(file-writable-p "/ro.txt") nil nil
(file-writable-p "c:/new-file.txt") t t
(file-writable-p "c:/rw.txt") t t
(file-writable-p "c:/ro.txt") nil nil
(file-writable-p "c:/") t t
(file-writable-p "c:") t t
(file-writable-p "e:/") t t
(file-writable-p "e:") t t
(file-writable-p "e:/rw.txt") t t
(file-writable-p "e:/ro.txt") nil nil
(file-writable-p "e:/new-file") t t
(file-writable-p "h:/") t t
(file-writable-p "h:") t t
(file-writable-p "h:/rw.txt") t t
(file-writable-p "h:/ro.txt") nil nil
(file-writable-p "h:/new-file") t t
(file-writable-p "z:/") t nil <--- differ
(file-writable-p "z:") t nil <--- differ
(file-writable-p "z:/new-file.txt") t nil <--- differ
------------------
--- Regards,
Shun-ichi Goto <gotoh@xxxxxxxxxxx>
R&D Group, TAIYO Corp., Tokyo, JAPAN
#include <stdio.h>
#include <sys/stat.h>
main(int argc, char **argv)
{
struct stat st;
int ret;
ret = stat( argv[1], &st );
printf("stat(\"%s\") => %d\n", argv[1], ret);
if ( ret < 0 ) {
puts("stat() failed");
} else {
printf("%s %s directory\n",
argv[1],
((st.st_mode & S_IFMT) == S_IFDIR)? "is": "is not");
}
}