Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
July 17, 2005 std.file.exists returns the opposite result | ||||
---|---|---|---|---|
| ||||
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) |
July 27, 2005 Re: std.file.exists returns the opposite result | ||||
---|---|---|---|---|
| ||||
Posted in reply to sito | 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) > > |
August 07, 2005 [patch] Re: std.file.exists returns the opposite result | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adrian Ratnapala | 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; |
Copyright © 1999-2021 by the D Language Foundation