From 91b3683ad0b6228bf85eefdb32e2ac3f717bd41c Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 23 Mar 2016 21:57:41 +0100 Subject: More cleanup. --- src/path.cc | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/path.cc') diff --git a/src/path.cc b/src/path.cc index 080bd12..21a8f89 100644 --- a/src/path.cc +++ b/src/path.cc @@ -33,19 +33,21 @@ #include #include -std::string getPath(std::string file) +std::string getPath(const std::string& file) { - std::string p; -#ifndef __MINGW32__ - char *b = strdup(file.c_str()); - p = dirname(b); - free(b); + std::string path; + +#ifdef __MINGW32__ + char drive[_MAX_DRIVE]; + char dir[_MAX_DIR]; + _splitpath(file.c_str(), drive, dir, NULL, NULL); + path = std::string(drive) + dir; #else - char drive[_MAX_DRIVE]; - char dir[_MAX_DIR]; - _splitpath(file.c_str(), drive, dir, NULL, NULL); - p = std::string(drive) + dir; + // POSIX + char* buffer = strdup(file.c_str()); + path = dirname(buffer); + free(buffer); #endif - return p; + return path; } -- cgit v1.2.3