From d45b8954d25703a4ff48517fbffff7a2b32b8aae Mon Sep 17 00:00:00 2001 From: MrBesen Date: Mon, 14 Dec 2020 13:40:42 +0100 Subject: [PATCH] compiles on windows --- .gitignore | 1 + Makefile | 5 ++++- src/files.cpp | 26 ++++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 4a0b4bc..299598a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.out build/ *.exe +*.dll *.o .gdb_history diff --git a/Makefile b/Makefile index c2087c6..5da8747 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,11 @@ # `make clean all` nicht mit -j verwenden! -> race condition im make file # statdessen: `make clean; make all -j` verwenden +# windows name +# NAME = lib$(NAMESHORT).dll + NAMESHORT = mrbesen -NAME = lib$(NAMESHORT).so +NAME ?= lib$(NAMESHORT).so NAMETEST = test CFLAGS = -fpic -std=c++17 -O2 -g -pipe -Wall -Wextra -Wno-unused-parameter -Wpedantic CXX = g++ diff --git a/src/files.cpp b/src/files.cpp index 61538c4..b80f5ff 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -1,4 +1,4 @@ -#include "files.h" +#include "files.h" #include #include @@ -11,6 +11,14 @@ #include "util.h" +#ifndef PATH_MAX +#define PATH_MAX 1024 +#endif + +#if defined(_WIN32) || defined(_WIN64) +#include +#endif + void mrbesen::files::parent(const std::string& child, std::string& out) { //letzten path trenner finden size_t pos = child.rfind('/', child.length() -2); //das erste Zeichen überspringen (könnte ein / sein) @@ -147,9 +155,23 @@ bool mrbesen::files::copy(const std::string& from, const std::string& to) { } std::string mrbesen::files::realPath(const std::string& str) { + #if defined(_WIN32) ||defined(_WIN64) + wchar_t bufferin[PATH_MAX]; + for(uint32_t i = 0; i < str.size(); ++i) { + bufferin[i] = str[i]; + } + bufferin[str.size()] = 0; + + wchar_t bufferA[PATH_MAX]; + wchar_t* ret = ::_wfullpath(bufferA, bufferin, PATH_MAX); + char buffer[PATH_MAX]; + for(uint32_t i = 0; ret[i]; ++i) { + buffer[i] = ret[i]; + } + #else char buffer[PATH_MAX]; char* ret = ::realpath(str.c_str(), buffer); + #endif if(ret == nullptr) return ""; - return std::string(buffer); } \ No newline at end of file