Code revisions after review by @piponazo
This commit is contained in:
parent
b0a9cb5624
commit
955962eaa8
21
README.md
21
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.
|
||||
|
||||
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.
|
||||
|
||||
#### NetBSD
|
||||
|
||||
NetBSD uses pkgsrc as the package manager. You can build exiv2 with the commands:
|
||||
|
||||
```bash
|
||||
$ cd /usr/pkgsrc/graphics/exiv2
|
||||
$ make install
|
||||
```
|
||||
|
||||
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)<br>
|
||||
2) python3<br>
|
||||
3) cmake<br>
|
||||
4) bash<br>
|
||||
5) sudo<br>
|
||||
6) chksum
|
||||
6) chksum<br>
|
||||
7) gettext<br>
|
||||
|
||||
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<br>
|
||||
robin@clanmills.com<br>
|
||||
Revised: 2019-05-09
|
||||
Revised: 2019-05-10
|
||||
@ -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)
|
||||
|
||||
192
src/version.cpp
192
src/version.cpp
@ -63,6 +63,35 @@
|
||||
#include <sys/types.h>
|
||||
#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 <windows.h>
|
||||
# include <psapi.h>
|
||||
|
||||
// tell MSVC to link psapi.
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment( lib, "psapi" )
|
||||
#endif
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
# include <mach-o/dyld.h>
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <libprocstat.h>
|
||||
#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 <windows.h>
|
||||
# include <psapi.h>
|
||||
|
||||
// tell MSVC to link psapi.
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment( lib, "psapi" )
|
||||
#endif
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
# include <mach-o/dyld.h>
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
#include <sys/mount.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <libprocstat.h>
|
||||
#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());
|
||||
}
|
||||
|
||||
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 ;
|
||||
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)
|
||||
{
|
||||
Exiv2::StringVector libs; // libs[0] == executable
|
||||
|
||||
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 );
|
||||
|
||||
Loading…
Reference in New Issue
Block a user