diff options
Diffstat (limited to 'src/path.cc')
-rw-r--r-- | src/path.cc | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/path.cc b/src/path.cc index c2e7910..993f9a6 100644 --- a/src/path.cc +++ b/src/path.cc @@ -40,7 +40,7 @@ std::string getPath(const std::string& file) #ifdef __MINGW32__ char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; - _splitpath(file.c_str(), drive, dir, NULL, NULL); + _splitpath(file.c_str(), drive, dir, nullptr, nullptr); path = std::string(drive) + dir; #else // POSIX @@ -51,3 +51,22 @@ std::string getPath(const std::string& file) return path; } + +std::string getFile(const std::string& file) +{ + std::string path; + +#ifdef __MINGW32__ + char fname[_MAX_FNAME]; + char ext[_MAX_EXT]; + _splitpath(file.c_str(), nullptr, nullptr, fname, ext); + path = std::string(fname) + "." + ext; +#else + // POSIX + char* buffer = strdup(file.c_str()); + path = basename(buffer); + free(buffer); +#endif + + return path; +} |