Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/backend/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ int os_file_exists(const char *name)
DWORD dw;
int result;

dw = GetFileAttributes(name);
dw = GetFileAttributesA(name);
if (dw == -1L)
result = 0;
else if (dw & FILE_ATTRIBUTE_DIRECTORY)
Expand Down Expand Up @@ -710,7 +710,7 @@ char *file_8dot3name(const char *filename)
char *buf;
int i;

h = FindFirstFile(filename,&fileinfo);
h = FindFirstFileA(filename,&fileinfo);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*A versions are basically deprecated junk on Windows. Do not use unless absolutely needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P.S.: NT kernel is UTF-16 throughout.

if (h == INVALID_HANDLE_VALUE)
return NULL;
if (fileinfo.cAlternateFileName[0])
Expand Down Expand Up @@ -770,15 +770,15 @@ int file_write(char *name, void *buffer, unsigned len)
HANDLE h;
DWORD numwritten;

h = CreateFileA((LPTSTR)name,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,
h = CreateFileA((LPCSTR)name,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,NULL);
if (h == INVALID_HANDLE_VALUE)
{
if (GetLastError() == ERROR_PATH_NOT_FOUND)
{
if (!file_createdirs(name))
{
h = CreateFileA((LPTSTR)name,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,
h = CreateFileA((LPCSTR)name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,NULL);
if (h != INVALID_HANDLE_VALUE)
goto Lok;
Expand Down
16 changes: 15 additions & 1 deletion src/dmd_msc.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization Condition="'$(Configuration)'=='Release'">true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
Expand All @@ -43,7 +55,7 @@
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>.\root;.\tk;.\backend;.;vcbuild;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)'=='Debug'">DEBUG;_DEBUG;TARGET_WINDOS%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)'=='Debug'">DEBUG;_DEBUG;TARGET_WINDOS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)'=='Release'">TARGET_WINDOS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary Condition="'$(Configuration)'=='Debug'">MultiThreadedDebug</RuntimeLibrary>
<RuntimeLibrary Condition="'$(Configuration)'=='Release'">MultiThreaded</RuntimeLibrary>
Expand Down Expand Up @@ -237,6 +249,7 @@
<ClCompile Include="root\outbuffer.c" />
<ClCompile Include="root\speller.c" />
<ClCompile Include="root\stringtable.c" />
<ClCompile Include="root\utils.c" />
<CustomBuild Include="idgen.d">
<Message>Building and running $(IntDir)%(Filename).exe</Message>
<Command>dmd -od$(IntDir) -of$(IntDir)%(Filename).exe %(Filename)%(Extension) &amp;&amp; $(IntDir)%(Filename).exe</Command>
Expand Down Expand Up @@ -363,6 +376,7 @@
<ClInclude Include="root\root.h" />
<ClInclude Include="root\speller.h" />
<ClInclude Include="root\stringtable.h" />
<ClInclude Include="root\utils.h" />
<ClInclude Include="id.h" />
<ClInclude Include="vcbuild\alloca.h" />
<ClInclude Include="vcbuild\fenv.h" />
Expand Down
16 changes: 7 additions & 9 deletions src/dmd_msc.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,6 @@
<ClCompile Include="root\checkedint.c">
<Filter>src\root</Filter>
</ClCompile>
<ClCompile Include="root\dmgcmem.c">
<Filter>src\root</Filter>
</ClCompile>
<ClCompile Include="root\longdouble.c">
<Filter>src\root</Filter>
</ClCompile>
Expand Down Expand Up @@ -462,6 +459,9 @@
<ClCompile Include="root\stringtable.c">
<Filter>src\root</Filter>
</ClCompile>
<ClCompile Include="root\utils.c">
<Filter>src\root</Filter>
</ClCompile>
<ClCompile Include="cdxxx.c">
<Filter>src\generated</Filter>
</ClCompile>
Expand Down Expand Up @@ -758,6 +758,9 @@
<ClInclude Include="root\stringtable.h">
<Filter>src\root</Filter>
</ClInclude>
<ClInclude Include="root\utils.h">
<Filter>src\root</Filter>
</ClInclude>
<ClInclude Include="id.h">
<Filter>src\generated</Filter>
</ClInclude>
Expand All @@ -779,9 +782,6 @@
<ClInclude Include="nspace.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="backend\obj.h">
<Filter>src\backend</Filter>
</ClInclude>
<ClInclude Include="tokens.h">
<Filter>src</Filter>
</ClInclude>
Expand All @@ -790,9 +790,6 @@
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="idgen.c">
<Filter>src\gen</Filter>
</CustomBuild>
<CustomBuild Include="impcnvgen.c">
<Filter>src\gen</Filter>
</CustomBuild>
Expand All @@ -803,5 +800,6 @@
<CustomBuild Include="vcbuild\ldfpu.asm">
<Filter>src\vcbuild</Filter>
</CustomBuild>
<CustomBuild Include="idgen.d" />
</ItemGroup>
</Project>
16 changes: 15 additions & 1 deletion src/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "errors.h"
#include "outbuffer.h"
#include "rmem.h"
#include "utils.h"

enum COLOR
{
Expand Down Expand Up @@ -176,8 +177,15 @@ void verrorPrint(Loc loc, COLOR headerColor, const char *header, const char *for

if (global.params.color)
setConsoleColorBright(true);
if (*p)
if (*p) {
#ifdef _WIN32
LPCWSTR wstr = UTF8toWide(p);
fwprintf(stderr, L"%s\n", wstr);
free((void *)wstr);
#else
fprintf(stderr, "%s: ", p);
#endif
}
mem.xfree(p);

if (global.params.color)
Expand All @@ -191,7 +199,13 @@ void verrorPrint(Loc loc, COLOR headerColor, const char *header, const char *for
fprintf(stderr, "%s ", p2);
OutBuffer tmp;
tmp.vprintf(format, ap);
#ifdef _WIN32
LPCWSTR wstr = UTF8toWide(tmp.peekString());
fwprintf(stderr, L"%s\n", wstr);
free((void *)wstr);
#else
fprintf(stderr, "%s\n", tmp.peekString());
#endif
fflush(stderr);
}

Expand Down
15 changes: 9 additions & 6 deletions src/inifile.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "root.h"
#include "rmem.h"
#include "port.h"
#include "utils.h"

#define LOG 0

Expand Down Expand Up @@ -63,15 +64,17 @@ const char *findConfFile(const char *argv0, const char *inifile)
* o directory off of argv0
* o SYSCONFDIR (default=/etc/) (non-windows)
*/
const char *filename = FileName::combine(getenv("HOME"), inifile);
const char *filename = FileName::combine(dgetenv("HOME"), inifile);
if (FileName::exists(filename))
return filename;

#if _WIN32 // This fix by Tim Matthews
char resolved_name[MAX_PATH + 1];
if (GetModuleFileNameA(NULL, resolved_name, MAX_PATH + 1) && FileName::exists(resolved_name))
WCHAR wresolved_name[MAX_PATH + 1];
if (GetModuleFileNameW(NULL, wresolved_name, MAX_PATH + 1) && FileName::exists(wresolved_name))
{
char *resolved_name = wideToUTF8(wresolved_name);
filename = FileName::replaceName(resolved_name, inifile);
free(resolved_name);
if (FileName::exists(filename))
return filename;
}
Expand Down Expand Up @@ -204,7 +207,7 @@ void parseConfFile(const char *filename, const char *envsectionname)
memcpy(p, &line[k + 1], len2);
p[len2] = 0;
Port::strupr(p);
char *penv = getenv(p);
char *penv = dgetenv(p);
if (penv)
buf.writestring(penv);
free(p);
Expand Down Expand Up @@ -267,7 +270,7 @@ void parseConfFile(const char *filename, const char *envsectionname)
else if (p[0] == '?' && p[1] == '=')
{
*p = '\0';
if (getenv(pn))
if (dgetenv(pn))
{
pn = NULL;
break;
Expand All @@ -289,7 +292,7 @@ void parseConfFile(const char *filename, const char *envsectionname)

if (pn)
{
putenv(strdup(pn));
dputenv(strdup(pn));
#if LOG
printf("\tputenv('%s')\n", pn);
//printf("getenv(\"TEST\") = '%s'\n",getenv("TEST"));
Expand Down
60 changes: 10 additions & 50 deletions src/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,13 @@
#include <string.h>
#include <stdlib.h>

#if _WIN32
#include <process.h>
#ifdef _MSC_VER
#include <windows.h>
#endif
#endif

#if __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#endif

#if __linux__ || __APPLE__
#define HAS_POSIX_SPAWN 1
#include <spawn.h>
#if __APPLE__
#include <crt_externs.h>
#endif
#else
#define HAS_POSIX_SPAWN 0
#endif
#include "utils.h"

#include "root.h"

Expand Down Expand Up @@ -248,7 +233,7 @@ int runLINK()

/* Append the path to the VC lib files, and then the SDK lib files
*/
const char *vcinstalldir = getenv("VCINSTALLDIR");
const char *vcinstalldir = dgetenv("VCINSTALLDIR");
if (vcinstalldir)
{ cmdbuf.writestring(" /LIBPATH:\"");
cmdbuf.writestring(vcinstalldir);
Expand All @@ -258,7 +243,7 @@ int runLINK()
cmdbuf.writestring("\\lib\"");
}

const char *windowssdkdir = getenv("WindowsSdkDir");
const char *windowssdkdir = dgetenv("WindowsSdkDir");
if (windowssdkdir)
{ cmdbuf.writestring(" /LIBPATH:\"");
cmdbuf.writestring(windowssdkdir);
Expand All @@ -284,9 +269,9 @@ int runLINK()
sprintf(p, "@%s", lnkfilename);
}

const char *linkcmd = getenv(global.params.is64bit ? "LINKCMD64" : "LINKCMD");
const char *linkcmd = dgetenv(global.params.is64bit ? "LINKCMD64" : "LINKCMD");
if (!linkcmd)
linkcmd = getenv("LINKCMD"); // backward compatible
linkcmd = dgetenv("LINKCMD"); // backward compatible
if (!linkcmd)
{
if (vcinstalldir)
Expand Down Expand Up @@ -435,7 +420,7 @@ int runLINK()
sprintf(p, "@%s", lnkfilename);
}

const char *linkcmd = getenv("LINKCMD");
const char *linkcmd = dgetenv("LINKCMD");
if (!linkcmd)
linkcmd = "link";
int status = executecmd(linkcmd, p);
Expand Down Expand Up @@ -747,7 +732,6 @@ int executecmd(const char *cmd, const char *args)
{
int status;
size_t len;

if (global.params.verbose)
fprintf(global.stdmsg, "%s %s\n", cmd, args);

Expand All @@ -757,7 +741,7 @@ int executecmd(const char *cmd, const char *args)
{
char *q = (char *) alloca(8 + len + 1);
sprintf(q,"_CMDLINE=%s", args);
status = putenv(q);
status = dputenv(q);
if (status == 0)
{
args = "@_CMDLINE";
Expand All @@ -772,23 +756,10 @@ int executecmd(const char *cmd, const char *args)
// Normalize executable path separators, see Bugzilla 9330
cmd = toWinPath(cmd);

#ifdef _MSC_VER
if(strchr(cmd, ' '))
{
// MSVCRT: spawn does not work with spaces in the executable
size_t cmdlen = strlen(cmd);
char* shortName = new char[cmdlen + 1]; // enough space
DWORD len = GetShortPathName(cmd, shortName, cmdlen + 1);
if(len > 0 && len <= cmdlen)
cmd = shortName;
}
#endif

status = executearg0(cmd,args);
if (status == -1)
{
// spawnlp returns intptr_t in some systems, not int
status = spawnlp(0,cmd,cmd,args,NULL);
status = dspawnlp(0,cmd,cmd,args,NULL);
}

// if (global.params.verbose)
Expand Down Expand Up @@ -827,8 +798,7 @@ int executearg0(const char *cmd, const char *args)
file = FileName::replaceName(argv0, cmd);

//printf("spawning '%s'\n",file);
// spawnlp returns intptr_t in some systems, not int
return spawnl(0,file,file,args,NULL);
return dspawnl(0,file,file,args,NULL);
}
#endif

Expand All @@ -854,15 +824,6 @@ int runProgram()
argv.push(global.params.exefile);
for (size_t i = 0; i < global.params.runargs_length; i++)
{ const char *a = global.params.runargs[i];

#if _WIN32
// BUG: what about " appearing in the string?
if (strchr(a, ' '))
{ char *b = (char *)mem.xmalloc(3 + strlen(a));
sprintf(b, "\"%s\"", a);
a = b;
}
#endif
argv.push(a);
}
argv.push(NULL);
Expand All @@ -873,8 +834,7 @@ int runProgram()
ex = FileName::combine(".", ex);
else
ex = global.params.exefile;
// spawnlp returns intptr_t in some systems, not int
return spawnv(0,ex,argv.tdata());
return dspawnv(0,ex,argv.tdata());
#elif __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun
pid_t childpid;
int status;
Expand Down
Loading