diff --git a/samples/exiv2json.cpp b/samples/exiv2json.cpp index 795e9871..ba754c0c 100644 --- a/samples/exiv2json.cpp +++ b/samples/exiv2json.cpp @@ -23,6 +23,7 @@ #include #include "Jzon.h" +#include #include #include #include @@ -41,20 +42,6 @@ # endif #endif -#if defined(_MSC_VER) || defined(__MINGW__) -#include -#ifndef PATH_MAX -# define PATH_MAX 512 -#endif -const char* realpath(const char* file,char* path) -{ - GetFullPathName(file,PATH_MAX,path,NULL); - return path; -} -#else -#include -#endif - struct Token { std::string n; // the name eg "History" bool a; // name is an array eg History[] @@ -249,8 +236,7 @@ void fileSystemPush(const char* path,Jzon::Node& nfs) { auto& fs = dynamic_cast(nfs); fs.Add("path",path); - char resolved_path[2000]; // PATH_MAX]; - fs.Add("realpath",realpath(path,resolved_path)); + fs.Add("realpath", std::filesystem::absolute(std::filesystem::path(path)).string()); struct stat buf; memset(&buf,0,sizeof(buf)); diff --git a/samples/geotag.cpp b/samples/geotag.cpp index d873a495..544dad44 100644 --- a/samples/geotag.cpp +++ b/samples/geotag.cpp @@ -24,6 +24,7 @@ #include #include "unused.h" +#include #include #include #include @@ -84,17 +85,6 @@ string getExifTime(time_t t); time_t parseTime(const char* ,bool bAdjust=false); int timeZoneAdjust(); -// platform specific code -#if defined(_MSC_VER) || defined(__MINGW__) -char* realpath(const char* file,char* path) -{ - char* result = (char*) malloc(_MAX_PATH); - if (result) GetFullPathName(file,_MAX_PATH,result,NULL); - return result ; - UNUSED(path); -} -#endif - // Command-line parser class Options { public: @@ -838,19 +828,13 @@ int main(int argc,const char* argv[]) if ( options.verbose ) printf("%s %s ",arg,types[type]) ; if ( type == typeImage ) { time_t t = readImageTime(std::string(arg)) ; -#ifdef __APPLE__ - char buffer[1024]; -#else - char* buffer = nullptr; -#endif - char* path = realpath(arg,buffer); - if ( t && path ) { + auto p = std::filesystem::absolute(std::filesystem::path(arg)); + std::string path = p.string(); + if ( t && !path.empty() ) { if (options.verbose) - printf("%s %ld %s", path, static_cast(t), asctime(localtime(&t))); + printf("%s %ld %s", path.c_str(), static_cast(t), asctime(localtime(&t))); gFiles.push_back(path); } - if (path && path != buffer) - ::free(path); } if ( type == typeUnknown ) { fprintf(stderr,"error: illegal syntax %s\n",arg); diff --git a/src/actions.cpp b/src/actions.cpp index 1c6899d6..2d12fda6 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -40,6 +40,7 @@ #include "i18n.h" // NLS support. // + standard includes +#include #include #include #include @@ -69,6 +70,8 @@ #define _setmode(a,b) #endif +namespace fs = std::filesystem; + // ***************************************************************************** // local declarations namespace { @@ -1786,29 +1789,25 @@ namespace { return os.str(); } // tm2Str - std::string temporaryPath() - { - static int count = 0; - std::lock_guard guard(cs); + std::string temporaryPath() + { + static int count = 0; + std::lock_guard guard(cs); #if defined(_MSC_VER) || defined(__MINGW__) - char lpTempPathBuffer[MAX_PATH]; - GetTempPath(MAX_PATH,lpTempPathBuffer); - std::string tmp(lpTempPathBuffer); - tmp += "\\"; HANDLE process=0; DWORD pid = ::GetProcessId(process); #else pid_t pid = ::getpid(); - std::string tmp = "/tmp/"; #endif - std::string result = tmp + Exiv2::toString(pid) + "_" + std::to_string(count); - if (Exiv2::fileExists(result)) { - std::remove(result.c_str()); - } + /// \todo check if we can use std::tmpnam + auto p = fs::temp_directory_path() / (Exiv2::toString(pid) + "_" + std::to_string(count)); + if (fs::exists(p)) { + fs::remove(p); + } - return result; - } + return p.string(); + } int metacopy(const std::string& source, const std::string& tgt,