digitalmars.D.bugs - std.file.exists returns the opposite result
- sito (11/11) Jul 17 2005 DMD 0.128, linux.
- Adrian Ratnapala (9/20) Jul 27 2005 This is right. The new version of exists() for
- Nick (11/15) Aug 06 2005 Right. Here is a short patch on this one too:
DMD 0.128, linux. -- exists_bug.d -- import std.file; void main() { assert(exists(".")); } -- $ dmd exists_bug.d $ ./exists_bug Error: AssertError Failure exists_bug(5)
Jul 17 2005
This is right. The new version of exists() for Linux uses the access() libc call, but interprets the result the wrong way, it does: return access(toStringz(name),0) != 0; but access() returns zero on _success_, -1 on failure. Just removing the "!= 0" or changing it to "!= -1" or "== 0" should do the trick. In article <dbe7c9$rsh$1 digitaldaemon.com>, sito says...DMD 0.128, linux. -- exists_bug.d -- import std.file; void main() { assert(exists(".")); } -- $ dmd exists_bug.d $ ./exists_bug Error: AssertError Failure exists_bug(5)
Jul 27 2005
In article <dc7o4v$2g2a$1 digitaldaemon.com>, Adrian Ratnapala says...This is right. The new version of exists() for Linux uses the access() libc call, but interprets the result the wrong way, it does: [snip]Right. Here is a short patch on this one too: --- file.d 2005-08-06 21:57:06.000000000 +0200 +++ filefixed.d 2005-08-07 08:54:31.133089424 +0200 -804,7 +804,7 int exists(char[] name) { - return access(toStringz(name),0) != 0; + return access(toStringz(name),0) == 0; /+ struct_stat statbuf;
Aug 06 2005