Skip to content

Commit

Permalink
use __has_include
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Jan 29, 2023
1 parent 3766382 commit 915c01d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 57 deletions.
2 changes: 1 addition & 1 deletion app/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// + standard includes
#include <sys/stat.h> // for stat()
#include <sys/types.h> // for stat()
#ifdef EXV_HAVE_UNISTD_H
#if __has_include(<unistd.h>)
#include <unistd.h> // for stat()
#endif

Expand Down
12 changes: 0 additions & 12 deletions cmake/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
// Define if you require webready support.
#cmakedefine EXV_ENABLE_WEBREADY

// Define if you have the <libintl.h> header file.
#cmakedefine EXV_HAVE_LIBINTL_H

// Define if you want translation of program messages to the user's native language
#cmakedefine EXV_ENABLE_NLS

Expand Down Expand Up @@ -44,15 +41,6 @@
// Define if you have the munmap function.
#cmakedefine EXV_HAVE_MUNMAP

/* Define if you have the <libproc.h> header file. */
#cmakedefine EXV_HAVE_LIBPROC_H

/* Define if you have the <unistd.h> header file. */
#cmakedefine EXV_HAVE_UNISTD_H

// Define if you have the <sys/mman.h> header file.
#cmakedefine EXV_HAVE_SYS_MMAN_H

// Define if you have the zlib library.
#cmakedefine EXV_HAVE_LIBZ

Expand Down
4 changes: 2 additions & 2 deletions samples/getopt-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// getopt.{cpp|hpp} is not part of libexiv2
#include "getopt.hpp"

#ifdef EXV_HAVE_UNISTD_H
#if __has_include(<unistd.h>)
#include <unistd.h>
#endif
#include <iostream>
Expand Down Expand Up @@ -79,7 +79,7 @@ int main(int argc, char** const argv) {

int n;

#ifdef EXV_HAVE_UNISTD_H
#if __has_include(<unistd.h>)
std::cout << "standard getopt()" << std::endl;
do {
n = ::getopt(argc, argv, ::optstring);
Expand Down
16 changes: 8 additions & 8 deletions src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
#include "image_int.hpp"
#include "types.hpp"

// + standard includes
#include <fcntl.h> // _O_BINARY in FileIo::FileIo
#include <sys/stat.h> // for stat, chmod

#include <cstdio> // for remove, rename
#include <cstdlib> // for alloc, realloc, free
#include <cstring> // std::memcpy
#include <ctime> // timestamp for the name of temporary file
#include <fstream> // write the temporary file
#include <iostream>

#ifdef EXV_HAVE_SYS_MMAN_H
// + standard includes
#include <fcntl.h> // _O_BINARY in FileIo::FileIo
#include <sys/stat.h> // for stat, chmod

#if __has_include(<sys/mman.h>)
#include <sys/mman.h> // for mmap and munmap
#endif
#ifdef EXV_HAVE_PROCESS_H
#if __has_include(<process.h>)
#include <process.h>
#endif
#ifdef EXV_HAVE_UNISTD_H
#include <unistd.h> // for getpid, stat
#if __has_include(<unistd.h>)
#include <unistd.h>
#endif

#ifdef EXV_USE_CURL
Expand Down
14 changes: 6 additions & 8 deletions src/futils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ namespace fs = std::experimental::filesystem;
// clang-format on
#endif

#if defined(__APPLE__) && defined(EXV_HAVE_LIBPROC_H)
#if __has_include(<libproc.h>)
#include <libproc.h>
#endif

#if __has_include(<unistd.h>)
#include <unistd.h> // for stat()
#endif

#if defined(__FreeBSD__)
#include <libprocstat.h>
#include <sys/mount.h>
Expand All @@ -45,10 +49,6 @@ namespace fs = std::experimental::filesystem;
#include <sys/un.h>
#endif

#ifdef EXV_HAVE_UNISTD_H
#include <unistd.h> // for stat()
#endif

#ifndef _MAX_PATH
#define _MAX_PATH 1024
#endif
Expand Down Expand Up @@ -346,14 +346,12 @@ std::string getProcessPath() {
}
CloseHandle(processHandle);
}
#elif defined(__APPLE__)
#ifdef EXV_HAVE_LIBPROC_H
#elif __has_include(<libproc.h>)
const int pid = getpid();
char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
if (proc_pidpath(pid, pathbuf, sizeof(pathbuf)) > 0) {
ret = pathbuf;
}
#endif
#elif defined(__FreeBSD__)
unsigned int n;
char buffer[PATH_MAX] = {};
Expand Down
38 changes: 12 additions & 26 deletions src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector<std::regex>& key
int enable_video = 0;
int use_curl = 0;

#ifdef EXV_HAVE_INTTYPES_H
#if __has_include(<inttypes.h>)
have_inttypes = 1;
#endif

Expand All @@ -324,29 +324,31 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector<std::regex>& key
have_iconv = 1;
#endif

#ifdef EXV_HAVE_LIBINTL_H
#ifdef EXV_ENABLE_NLS
have_libintl = 1;
#endif

#ifdef EXV_HAVE_MEMORY_H
#if __has_include(<memory.h>)
have_memory = 1;
#endif

#ifdef EXV_HAVE_STDBOOL_H
#if __has_include(<stdbool.h>)
have_stdbool = 1;
#endif

#if __has_include(<stdint.h>)
have_stdint = 1;
#endif

#ifdef EXV_HAVE_STDLIB_H
#if __has_include(<stdlib.h>)
have_stdlib = 1;
#endif

#ifdef EXV_HAVE_STRERROR_R
have_strerror_r = 1;
#endif

#ifdef EXV_HAVE_STRINGS_H
#if __has_include(<strings.h>)
have_strings = 1;
#endif

Expand All @@ -358,19 +360,19 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector<std::regex>& key
have_munmap = 1;
#endif

#ifdef EXV_HAVE_SYS_STAT_H
#if __has_include(<sys/stat.h>)
have_sys_stat = 1;
#endif

#ifdef EXV_HAVE_SYS_TYPES_H
#if __has_include(<sys/types.h>)
have_sys_types = 1;
#endif

#ifdef EXV_HAVE_UNISTD_H
#if __has_include(<unistd.h>)
have_unistd = 1;
#endif

#ifdef EXV_HAVE_SYS_MMAN_H
#if __has_include(<sys/mman.h>)
have_sys_mman = 1;
#endif

Expand All @@ -390,22 +392,6 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector<std::regex>& key
adobe_xmpsdk = EXV_ADOBE_XMPSDK;
#endif

#ifdef EXV_HAVE_BOOL
have_bool = 1;
#endif

#ifdef EXV_HAVE_STRINGS
have_strings = 1;
#endif

#ifdef EXV_SYS_TYPES
have_sys_types = 1;
#endif

#ifdef EXV_HAVE_UNISTD
have_unistd = 1;
#endif

#ifdef EXV_ENABLE_BMFF
enable_bmff = 1;
#endif
Expand Down

0 comments on commit 915c01d

Please sign in to comment.