From 955962eaa85e5fb2914d6e1aaca9ebf316a2fd1b Mon Sep 17 00:00:00 2001 From: Robin Mills Date: Sat, 11 May 2019 16:53:11 +0100 Subject: [PATCH] Code revisions after review by @piponazo --- README.md | 21 ++--- cmake/packaging.cmake | 7 +- src/version.cpp | 192 +++++++++++++++++++++--------------------- 3 files changed, 110 insertions(+), 110 deletions(-) diff --git a/README.md b/README.md index e5ce0326..8d30ca0c 100644 --- a/README.md +++ b/README.md @@ -832,30 +832,25 @@ cmd ### Unix -Exiv2 can be built on many Unix and Linux distros. We actively support the Unix Distributions NetBSD and FreeBSD +Exiv2 can be built on many Unix and Linux distros. We actively support the Unix Distributions NetBSD and FreeBSD. -#### NetBSD - -NetBSD uses pkgsrc as the package manager. You can build exiv2 with the commands: +I am willing to support Exiv2 on commercial Unix distributions such as Solaris, AIX, HP-UX and OSF/1 provided you provide with an ssh account on your platform. I will require super-user privileges to install software. -```bash -$ cd /usr/pkgsrc/graphics/exiv2 -$ make install -``` +#### NetBSD -You can build exiv2 from source using the methods described for linux. I build and installed exiv2 using "Pure CMake" and didn't require conan. -You will want to use `pkgsrc` to build/install +You can build exiv2 from source using the methods described for linux. I built and installed exiv2 using "Pure CMake" and didn't require conan. +You will want to use the package manager `pkgsrc` to build/install: 1) gcc (currently GCC 5.5.0)
2) python3
3) cmake
4) bash
5) sudo
-6) chksum +6) chksum
7) gettext
I entered links into the file system `# ln -s /usr/pkg/bin/python37 /usr/local/bin/python3` and `# ln -s /usr/pkg/bin/bash /bin/bash` -It's important to ensure that `LD_LIBRARY_PATH` includes /usr/local/lib and /usr/pkg/lib. It's important to ensure that PATH includes `/usr/local/bin`, `/usr/pkg/bin` and`/usr/pkg/sbin`. +It's important to ensure that `LD_LIBRARY_PATH` includes `/usr/local/lib` and `/usr/pkg/lib`. It's important to ensure that PATH includes `/usr/local/bin`, `/usr/pkg/bin` and `/usr/pkg/sbin`. #### FreeBSD @@ -865,4 +860,4 @@ FreeBSD uses pkg as the package manager. You should install the dependency expa Written by Robin Mills
robin@clanmills.com
-Revised: 2019-05-09 \ No newline at end of file +Revised: 2019-05-10 \ No newline at end of file diff --git a/cmake/packaging.cmake b/cmake/packaging.cmake index 8535a95c..be0aef09 100644 --- a/cmake/packaging.cmake +++ b/cmake/packaging.cmake @@ -71,11 +71,12 @@ endif() set (VS "") # VisualStudio if ( MSVC ) - if ( MSVC_VERSION STREQUAL 2100 ) + # https://gitlab.kitware.com/cmake/cmake/blob/v3.10.0-rc5/Modules/Platform/Windows-MSVC.cmake#L51-68 + if ( MSVC_VERSION GREATER 1919 ) set(VS 2019) - elseif ( MSVC_VERSION STREQUAL 2000 ) + elseif ( MSVC_VERSION GREATER 1909 ) set(VS 2017) - elseif ( MSVC_VERSION STREQUAL 1900 ) + elseif ( MSVC_VERSION GREATER 1899 ) set(VS 2015) elseif ( MSVC_VERSION STREQUAL 1800 ) set(VS 2013) diff --git a/src/version.cpp b/src/version.cpp index 330023d6..ad095935 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -63,6 +63,35 @@ #include #endif +#ifndef lengthof +#define lengthof(x) sizeof(x)/sizeof(x[0]) +#endif +#ifndef _MAX_PATH +#define _MAX_PATH 512 +#endif + +// platform specific support for dumpLibraryInfo +#if defined(WIN32) +# include +# include + +// tell MSVC to link psapi. +#ifdef _MSC_VER +#pragma comment( lib, "psapi" ) +#endif + +#elif defined(__APPLE__) +# include +#endif + +#if defined(__FreeBSD__) +#include +#include +#include +#include +#include +#endif + namespace Exiv2 { int versionNumber() { @@ -93,41 +122,7 @@ namespace Exiv2 { { return versionNumber() >= EXIV2_MAKE_VERSION(major,minor,patch); } - -} // namespace Exiv2 - -#ifndef lengthof -#define lengthof(x) sizeof(x)/sizeof(x[0]) -#endif -#ifndef _MAX_PATH -#define _MAX_PATH 512 -#endif - -// platform specific support for dumpLibraryInfo -#if defined(WIN32) -# include -# include - -// tell MSVC to link psapi. -#ifdef _MSC_VER -#pragma comment( lib, "psapi" ) -#endif - -#elif defined(__APPLE__) -# include -#endif - -#if defined(__FreeBSD__) -#include -#include -#include -#include -#include -#include -#include -#include -#include -#endif +} // namespace Exiv2 static bool shouldOutput(const exv_grep_keys_t& greps,const char* key,const std::string& value) { @@ -167,10 +162,75 @@ static void output(std::ostream& os,const exv_grep_keys_t& greps,const char* nam output(os,greps,name,stringStream.str()); } -void Exiv2::dumpLibraryInfo(std::ostream& os,const exv_grep_keys_t& keys) +static bool pushPath(std::string& path,Exiv2::StringVector& libs,Exiv2::StringSet& paths) +{ + bool result = Exiv2::fileExists(path,true) && paths.find(path) == paths.end() && path != "/" ; + if ( result ) { + paths.insert(path); + libs.push_back(path); + } + return result ; +} + +static Exiv2::StringVector getLoadedLibraries() { - Exiv2::StringVector libs; // libs[0] == executable + Exiv2::StringVector libs ; + Exiv2::StringSet paths; + std::string path ; +#if defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW__) + // enumerate loaded libraries and determine path to executable + HMODULE handles[200]; + DWORD cbNeeded; + if ( EnumProcessModules(GetCurrentProcess(),handles,lengthof(handles),&cbNeeded)) { + char szFilename[_MAX_PATH]; + for ( DWORD h = 0 ; h < cbNeeded/sizeof(handles[0]) ; h++ ) { + GetModuleFileNameA(handles[h],szFilename,lengthof(szFilename)) ; + std::string path(szFilename); + pushPath(path,libs,paths); + } + } +#elif defined(__APPLE__) + // man 3 dyld + uint32_t count = _dyld_image_count(); + for (uint32_t image = 0 ; image < count ; image++ ) { + std::string path(_dyld_get_image_name(image)); + pushPath(path,libs,paths); + } +#elif defined(__FreeBSD__) + unsigned int n; + struct procstat* procstat = procstat_open_sysctl(); + struct kinfo_proc* procs = procstat ? procstat_getprocs(procstat, KERN_PROC_PID, getpid(), &n) : NULL; + struct filestat_list* files = procs ? procstat_getfiles(procstat, procs, true) : NULL; + if ( files ) { + filestat* entry; + STAILQ_FOREACH(entry, files, next) { + std::string path(entry->fs_path); + pushPath(path,libs,paths); + } + } + // free resources + if ( files ) procstat_freefiles(procstat, files); + if ( procs ) procstat_freeprocs(procstat, procs); + if ( procstat ) procstat_close (procstat); + +#elif defined(__unix__) + // read file /proc/self/maps which has a list of files in memory + std::ifstream maps("/proc/self/maps",std::ifstream::in); + std::string string ; + while ( std::getline(maps,string) ) { + std::size_t pos = string.find_last_of(' '); + if ( pos != std::string::npos ) { + std::string path = string.substr(pos+1); + pushPath(path,libs,paths); + } + } +#endif + return libs; +} + +void Exiv2::dumpLibraryInfo(std::ostream& os,const exv_grep_keys_t& keys) +{ int bits = 8*sizeof(void*); #ifdef NDEBUG int debug=0; @@ -424,63 +484,7 @@ void Exiv2::dumpLibraryInfo(std::ostream& os,const exv_grep_keys_t& keys) use_ssh=1; #endif -#define PUSH_PATH(path,libs,paths) \ - if ( Exiv2::fileExists(path,true) && paths.find(path) == paths.end() && path != "/" ) { \ - paths.insert(path); \ - libs.push_back(path); \ - } - - Exiv2::StringSet paths; -#if defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW__) - // enumerate loaded libraries and determine path to executable - HMODULE handles[200]; - DWORD cbNeeded; - if ( EnumProcessModules(GetCurrentProcess(),handles,lengthof(handles),&cbNeeded)) { - char szFilename[_MAX_PATH]; - for ( DWORD h = 0 ; h < cbNeeded/sizeof(handles[0]) ; h++ ) { - GetModuleFileNameA(handles[h],szFilename,lengthof(szFilename)) ; - std::string path(szFilename); - PUSH_PATH(path,libs,paths); - } - } -#elif defined(__APPLE__) - // man 3 dyld - uint32_t count = _dyld_image_count(); - for (uint32_t image = 0 ; image < count ; image++ ) { - std::string path(_dyld_get_image_name(image)); - PUSH_PATH(path,libs,paths); - } -#elif defined(__FreeBSD__) - unsigned int n; - struct procstat* procstat = procstat_open_sysctl(); - struct kinfo_proc* procs = procstat ? procstat_getprocs(procstat, KERN_PROC_PID, getpid(), &n) : NULL; - struct filestat_list* files = procs ? procstat_getfiles(procstat, procs, true) : NULL; - if ( files ) { - filestat* entry; - STAILQ_FOREACH(entry, files, next) { - std::string path(entry->fs_path); - PUSH_PATH(path,libs,paths); - } - } - // free resources - if ( files ) procstat_freefiles(procstat, files); - if ( procs ) procstat_freeprocs(procstat, procs); - if ( procstat ) procstat_close (procstat); - -#elif defined(__unix__) - // read file /proc/self/maps which has a list of files in memory - std::ifstream maps("/proc/self/maps",std::ifstream::in); - std::string string ; - while ( std::getline(maps,string) ) { - std::size_t pos = string.find_last_of(' '); - if ( pos != std::string::npos ) { - std::string path = string.substr(pos+1); - PUSH_PATH(path,libs,paths); - } - } -#else - UNUSED(paths); -#endif + Exiv2::StringVector libs =getLoadedLibraries(); output(os,keys,"exiv2",Exiv2::versionString()); output(os,keys,"platform" , platform );