Fixed wrong C library lookups

This commit is contained in:
Andrei Alexandrescu 2011-11-12 21:55:22 -06:00
parent 0ee6a1afbd
commit 703f612973
3 changed files with 24 additions and 23 deletions

View file

@ -1942,8 +1942,8 @@ version (Posix) string getcwd()
{ {
auto p = cenforce(core.sys.posix.unistd.getcwd(null, 0), auto p = cenforce(core.sys.posix.unistd.getcwd(null, 0),
"cannot get cwd"); "cannot get cwd");
scope(exit) std.c.stdlib.free(p); scope(exit) core.stdc.stdlib.free(p);
return p[0 .. std.c.string.strlen(p)].idup; return p[0 .. core.stdc.string.strlen(p)].idup;
} }
unittest unittest
@ -2657,14 +2657,14 @@ void copy(in char[] from, in char[] to)
{ {
scope(failure) core.sys.posix.unistd.close(fdw); scope(failure) core.sys.posix.unistd.close(fdw);
auto BUFSIZ = 4096u * 16; auto BUFSIZ = 4096u * 16;
auto buf = std.c.stdlib.malloc(BUFSIZ); auto buf = core.stdc.stdlib.malloc(BUFSIZ);
if (!buf) if (!buf)
{ {
BUFSIZ = 4096; BUFSIZ = 4096;
buf = std.c.stdlib.malloc(BUFSIZ); buf = core.stdc.stdlib.malloc(BUFSIZ);
buf || assert(false, "Out of memory in std.file.copy"); buf || assert(false, "Out of memory in std.file.copy");
} }
scope(exit) std.c.stdlib.free(buf); scope(exit) core.stdc.stdlib.free(buf);
for (auto size = statbuf.st_size; size; ) for (auto size = statbuf.st_size; size; )
{ {
@ -3040,8 +3040,8 @@ private struct DirIteratorImpl
return false; return false;
} }
} }
while( std.c.string.strcmp(findinfo.cFileName.ptr, ".") == 0 while( core.stdc.string.strcmp(findinfo.cFileName.ptr, ".") == 0
|| std.c.string.strcmp(findinfo.cFileName.ptr, "..") == 0) || core.stdc.string.strcmp(findinfo.cFileName.ptr, "..") == 0)
if(FindNextFileA(_stack.data[$-1].h, findinfo) == FALSE) if(FindNextFileA(_stack.data[$-1].h, findinfo) == FALSE)
{ {
popDirStack(); popDirStack();
@ -3091,8 +3091,8 @@ private struct DirIteratorImpl
for(dirent* fdata; (fdata = readdir(_stack.data[$-1].h)) != null; ) for(dirent* fdata; (fdata = readdir(_stack.data[$-1].h)) != null; )
{ {
// Skip "." and ".." // Skip "." and ".."
if(std.c.string.strcmp(fdata.d_name.ptr, ".") && if(core.stdc.string.strcmp(fdata.d_name.ptr, ".") &&
std.c.string.strcmp(fdata.d_name.ptr, "..") ) core.stdc.string.strcmp(fdata.d_name.ptr, "..") )
{ {
_cur._init(_stack.data[$-1].dirpath, fdata); _cur._init(_stack.data[$-1].dirpath, fdata);
return true; return true;
@ -3831,8 +3831,8 @@ version(Windows)
do do
{ {
// Skip "." and ".." // Skip "." and ".."
if(std.c.string.strcmp(fileinfo.cFileName.ptr, ".") == 0 || if(core.stdc.string.strcmp(fileinfo.cFileName.ptr, ".") == 0 ||
std.c.string.strcmp(fileinfo.cFileName.ptr, "..") == 0) core.stdc.string.strcmp(fileinfo.cFileName.ptr, "..") == 0)
{ {
continue; continue;
} }
@ -3858,8 +3858,8 @@ else version(Posix)
for(dirent* fdata; (fdata = readdir(h)) != null; ) for(dirent* fdata; (fdata = readdir(h)) != null; )
{ {
// Skip "." and ".." // Skip "." and ".."
if(!std.c.string.strcmp(fdata.d_name.ptr, ".") || if(!core.stdc.string.strcmp(fdata.d_name.ptr, ".") ||
!std.c.string.strcmp(fdata.d_name.ptr, "..")) !core.stdc.string.strcmp(fdata.d_name.ptr, ".."))
{ {
continue; continue;
} }

View file

@ -2588,7 +2588,7 @@ string expandTilde(string inputPath)
assert(char_pos >= 0); assert(char_pos >= 0);
// Search end of C string // Search end of C string
size_t end = std.c.string.strlen(c_path); size_t end = core.stdc.string.strlen(c_path);
// Remove trailing path separator, if any // Remove trailing path separator, if any
if (end && isDirSeparator(c_path[end - 1])) if (end && isDirSeparator(c_path[end - 1]))
@ -2646,7 +2646,7 @@ string expandTilde(string inputPath)
while (1) while (1)
{ {
extra_memory = std.c.stdlib.malloc(extra_memory_size); extra_memory = core.stdc.stdlib.malloc(extra_memory_size);
if (extra_memory == null) if (extra_memory == null)
goto Lerror; goto Lerror;
@ -2667,20 +2667,20 @@ string expandTilde(string inputPath)
goto Lerror; goto Lerror;
// extra_memory isn't large enough // extra_memory isn't large enough
std.c.stdlib.free(extra_memory); core.stdc.stdlib.free(extra_memory);
extra_memory_size *= 2; extra_memory_size *= 2;
} }
path = combineCPathWithDPath(result.pw_dir, path, last_char); path = combineCPathWithDPath(result.pw_dir, path, last_char);
Lnotfound: Lnotfound:
std.c.stdlib.free(extra_memory); core.stdc.stdlib.free(extra_memory);
return path; return path;
Lerror: Lerror:
// Errors are going to be caused by running out of memory // Errors are going to be caused by running out of memory
if (extra_memory) if (extra_memory)
std.c.stdlib.free(extra_memory); core.stdc.stdlib.free(extra_memory);
onOutOfMemoryError(); onOutOfMemoryError();
return null; return null;
} }

View file

@ -21,6 +21,7 @@ module std.process;
import core.stdc.stdlib; import core.stdc.stdlib;
import std.c.stdlib;
import core.stdc.errno; import core.stdc.errno;
import core.thread; import core.thread;
import std.c.process; import std.c.process;
@ -277,7 +278,7 @@ version(Posix)
{ {
// No, so must traverse PATHs, looking for first match // No, so must traverse PATHs, looking for first match
string[] envPaths = std.string.split( string[] envPaths = std.string.split(
to!string(std.c.stdlib.getenv("PATH")), ":"); to!string(core.stdc.stdlib.getenv("PATH")), ":");
int iRet = 0; int iRet = 0;
// Note: if any call to execve() succeeds, this process will cease // Note: if any call to execve() succeeds, this process will cease
@ -388,7 +389,7 @@ string getenv(in char[] name)
{ {
// Cache the last call's result // Cache the last call's result
static string lastResult; static string lastResult;
auto p = std.c.stdlib.getenv(toStringz(name)); auto p = core.stdc.stdlib.getenv(toStringz(name));
if (!p) return null; if (!p) return null;
auto value = p[0 .. strlen(p)]; auto value = p[0 .. strlen(p)];
if (value == lastResult) return lastResult; if (value == lastResult) return lastResult;