comparison gen/configfile.cpp @ 1473:8309ebaa23d5

Fix for finding ldc.conf file with mingw
author Kelly Wilson <wilsonk cpsc.ucalgary.ca>
date Thu, 04 Jun 2009 16:04:26 -0600
parents 206329112670
children 1f29cbc36bf5
comparison
equal deleted inserted replaced
1471:230765fc82f4 1473:8309ebaa23d5
8 #include "libconfig.h++" 8 #include "libconfig.h++"
9 9
10 #include "gen/configfile.h" 10 #include "gen/configfile.h"
11 11
12 #include "mars.h" 12 #include "mars.h"
13
14 #if _WIN32
15 #include <windows.h>
16 #undef GetCurrentDirectory
17 #endif
13 18
14 namespace sys = llvm::sys; 19 namespace sys = llvm::sys;
15 20
16 ConfigFile::ConfigFile() 21 ConfigFile::ConfigFile()
17 { 22 {
48 #endif 53 #endif
49 p.appendComponent(filename); 54 p.appendComponent(filename);
50 55
51 if (!p.exists()) 56 if (!p.exists())
52 { 57 {
58 #if _WIN32
59 char buf[256];
60 GetModuleFileName(NULL, buf, 256);
61 p = *(new std::string(buf));
62 #else
53 // 4) try next to the executable 63 // 4) try next to the executable
54 p = sys::Path::GetMainExecutable(argv0, mainAddr); 64 p = sys::Path::GetMainExecutable(argv0, mainAddr);
65 #endif
55 p.eraseComponent(); 66 p.eraseComponent();
56 p.appendComponent(filename); 67 p.appendComponent(filename);
57 if (!p.exists()) 68 if (!p.exists())
58 { 69 {
59 // 5) fail load cfg, users still have the DFLAGS environment var 70 // 5) fail load cfg, users still have the DFLAGS environment var
60 std::cerr << "Error failed to locate the configuration file: " << filename << std::endl; 71 std::cerr << "Error failed to locate the configuration file: " << filename << std::endl;
61 return false; 72 return false;
62 } 73 }
63 } 74 }