Skip to content

Commit b90d5c5

Browse files
author
Tal Hadad
committed
fix OS calc of current directory and fix windows headers inclusion
1 parent 6167676 commit b90d5c5

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

simplecpp.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@
4040
#include <utility>
4141
#include <vector>
4242

43+
#ifdef _WIN32
44+
#include <direct.h>
45+
#else
46+
#include <unistd.h>
47+
#endif
48+
4349
#ifdef SIMPLECPP_WINDOWS
4450
#include <windows.h>
4551
#undef ERROR
46-
#else
47-
#include <unistd.h>
4852
#endif
4953

5054
#if __cplusplus >= 201103L
@@ -2686,24 +2690,17 @@ static bool isCpp17OrLater(const simplecpp::DUI &dui)
26862690

26872691

26882692
static std::string currentDirectoryOSCalc() {
2689-
#ifdef SIMPLECPP_WINDOWS
2690-
TCHAR NPath[MAX_PATH];
2691-
GetCurrentDirectory(MAX_PATH, NPath);
2692-
#ifdef _UNICODE
2693-
// convert the result from TCHAR* to char*
2694-
char NPathA[MAX_PATH];
2695-
::WideCharToMultiByte(CP_ACP, 0, NPath, lstrlen(NPath), NPathA, MAX_PATH, NULL, NULL);
2696-
return NPathA;
2697-
#else
2698-
// in this case, TCHAR* is just defined to be a char*
2699-
return NPath;
2700-
#endif
2693+
const std::size_t size = 4096;
2694+
char currentPath[size];
2695+
2696+
#ifndef _WIN32
2697+
if (getcwd(currentPath, size) != nullptr)
27012698
#else
2702-
const std::size_t size = 1024;
2703-
char the_path[size];
2704-
getcwd(the_path, size);
2705-
return the_path;
2699+
if (_getcwd(currentPath, size) != nullptr)
27062700
#endif
2701+
return std::string(currentPath);
2702+
2703+
return "";
27072704
}
27082705

27092706
static const std::string& currentDirectory() {

0 commit comments

Comments
 (0)