Thread overview
std.file.exists returns the opposite result
Jul 17, 2005
sito
Jul 27, 2005
Adrian Ratnapala
[patch] Re: std.file.exists returns the opposite result
Aug 07, 2005
Nick
July 17, 2005
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
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
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;