D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6814 - Calling std.file.readLink causes code to not compile.
Summary: Calling std.file.readLink causes code to not compile.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-15 16:57 UTC by Kapps
Modified: 2012-01-07 23:35 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kapps 2011-10-15 16:57:39 UTC
The function std.file.readLink attempts to convert a char[2048] to a char* implicitly, causing any code calling it to result in a compiler error.

Test Case:

import std.stdio;
import std.file;

void main() {
        string Path = readLink("/proc/self/exe");
        writefln(Path);
}

Output:

/usr/include/d/dmd/phobos/std/file.d(1834): Error: function core.sys.posix.unistd.readlink (in const(char*), char*, ulong) is not callable using argument types (const(char*),char[2048LU],ulong)
/usr/include/d/dmd/phobos/std/file.d(1835): Error: cannot implicitly convert expression (buffer) of type char[2048LU] to char*

Fix:
Just add a .ptr when calling the core.sys version.

As an unrelated issue, readLink will also truncate without warning if the path resolves to more than 2047 characters, but I'm not sure if that's worth opening a separate bug report for.
Comment 1 Jonathan M Davis 2011-10-15 17:48:09 UTC
This is very bizarre, because the unit tests compile and run just fine for readLink. But your example does indeed fail to compile.
Comment 2 Jonathan M Davis 2011-10-15 18:31:26 UTC
https://github.com/D-Programming-Language/phobos/pull/294
Comment 3 Brad Roberts 2012-01-07 23:35:56 UTC
Fix pulled back in Oct 2011.  Closing.