diff --git a/src/utils/byteorder.h.in b/src/utils/byteorder.h.in index 494d537ca..e153346b7 100644 --- a/src/utils/byteorder.h.in +++ b/src/utils/byteorder.h.in @@ -1,3 +1,5 @@ +/* .h file GENERATED FROM byterorder.h.in */ + /* byteorder.h - cross-platform header for byte ordering * * Copyright (C) 2017 SINTEF Materials and Chemistry @@ -60,10 +62,10 @@ #cmakedefine HAVE_BSWAP_64 /* Whether function bswap_64 exists */ #cmakedefine HAVE_BSWAP_128 /* Whether function bswap_128 exists */ -#cmakedefine HAVE_BYTESWAP_USHORT /* Whether function _byteswap_ushort exists */ -#cmakedefine HAVE_BYTESWAP_ULONG /* Whether function _byteswap_ulong exists */ -#cmakedefine HAVE_BYTESWAP_UINT64 /* Whether function _byteswap_uint64 exists */ -#cmakedefine HAVE_BYTESWAP_UINT128/* Whether function _byteswap_uint128 exists*/ +#cmakedefine HAVE__BYTESWAP_USHORT /* Whether function _byteswap_ushort exists */ +#cmakedefine HAVE__BYTESWAP_ULONG /* Whether function _byteswap_ulong exists */ +#cmakedefine HAVE__BYTESWAP_UINT64 /* Whether function _byteswap_uint64 exists */ +#cmakedefine HAVE__BYTESWAP_UINT128/* Whether function _byteswap_uint128 exists*/ #cmakedefine HAVE_HTOBE16 /* Whether function htobe16 exists */ #cmakedefine HAVE_HTOBE32 /* Whether function htobe32 exists */ @@ -74,11 +76,43 @@ #include "integers.h" #ifdef HAVE_ENDIAN_H -# include -#endif + #if defined(__APPLE__) && defined(__MACH__) + #include + #else + #include + #endif /* defined(__APPLE__) && defined(__MACH__) */ +#endif /* ifdef HAVE_ENDIAN_H */ #ifdef HAVE_BYTESWAP_H -# include + #if defined(__APPLE__) && defined(__MACH__) + #include + #ifdef HAVE_BSWAP_16 + #define bswap_16(x) OSSwapInt16(x) + #endif + #ifdef HAVE_BSWAP_32 + #define bswap_32(x) OSSwapInt32(x) + #endif + #ifdef HAVE_BSWAP_64 + #define bswap_64(x) OSSwapInt64(x) + #endif + #ifdef HAVE_BSWAP_128 + #define bswap_128(x) OSSwapInt128(x) + #endif + #ifdef HAVE_HTOBE16 + #define htobe16(x) OSSwapHostToBigInt16(x) + #endif + #ifdef HAVE_HTOBE32 + #define htobe32(x) OSSwapHostToBigInt32(x) + #endif + #ifdef HAVE_HTOBE64 + #define htobe64(x) OSSwapHostToBigInt64(x) + #endif + #ifdef HAVE_HTOBE128 + #define htobe128(x) OSSwapHostToBigInt128(x) + #endif + #else + #include + #endif /* defined(__APPLE__) && defined(__MACH__) */ #endif @@ -161,6 +195,10 @@ # else # error "Byte order not supported: " # BYTE_ORDER # endif +#elif (defined(__APPLE__) && defined(__MACH__) && defined(HAVE_HTOBE16)) +# define htole16(x) (uint16_t)(x) +# define be16toh(x) bswap_16(x) +# define le16toh(x) (uint16_t)(x) #endif #ifndef HAVE_HTOBE32 @@ -177,6 +215,10 @@ # else # error "Byte order not supported: " # BYTE_ORDER # endif +#elif (defined(__APPLE__) && defined(__MACH__) && defined(HAVE_HTOBE32)) +# define htole32(x) (uint32_t)(x) +# define be32toh(x) bswap_32(x) +# define le32toh(x) (uint32_t)(x) #endif #ifndef HAVE_HTOBE64 @@ -193,6 +235,10 @@ # else # error "Byte order not supported: " # BYTE_ORDER # endif +#elif (defined(__APPLE__) && defined(__MACH__) && defined(HAVE_HTOBE64)) +# define htole64(x) (uint64_t)(x) +# define be64toh(x) bswap_64(x) +# define le64toh(x) (uint64_t)(x) #endif #ifdef bswap128 @@ -210,6 +256,10 @@ # else # error "Byte order not supported: " # BYTE_ORDER # endif +# elif (defined(__APPLE__) && defined(__MACH__) && defined(HAVE_HTOBE128)) +# define htole128(x) (uint128_t)(x) +# define be128toh(x) bswap_128(x) +# define le128toh(x) (uint128_t)(x) # endif #endif diff --git a/src/utils/compat-src/getopt.h b/src/utils/compat-src/getopt.h index ac1f536b3..89095c226 100644 --- a/src/utils/compat-src/getopt.h +++ b/src/utils/compat-src/getopt.h @@ -6,8 +6,6 @@ * Released under the MIT license * https://github.com/takamin/win-c/blob/master/LICENSE */ -#ifndef _GETOPT_H_ -#define _GETOPT_H_ #ifdef __cplusplus extern "C" { @@ -16,6 +14,8 @@ extern "C" { #ifdef HAVE_GETOPT #include #else +#ifndef _GETOPT_H_ +#define _GETOPT_H_ int getopt(int argc, char* const argv[], const char* optstring); diff --git a/src/utils/config.h.in b/src/utils/config.h.in index b64d04949..0767a266a 100644 --- a/src/utils/config.h.in +++ b/src/utils/config.h.in @@ -79,20 +79,23 @@ #cmakedefine HAVE_MBSTOWCS_S #cmakedefine HAVE_WCSTOMBS_S +#cmakedefine HAVE_STRLCPY +#cmakedefine HAVE_STRLCAT + #cmakedefine HAVE_GETOPT #cmakedefine HAVE_GETOPT_LONG -// #cmakedefine HAVE_SNPRINTF -// #cmakedefine HAVE__SNPRINTF -// #cmakedefine HAVE_VSNPRINTF -// #cmakedefine HAVE__VSNPRINTF -// #cmakedefine HAVE_VASPRINTF -// #cmakedefine HAVE__VASPRINTF -// #cmakedefine HAVE_ASPRINTF -// #cmakedefine HAVE__ASPRINTF -// #cmakedefine HAVE_LOCALECONV -// #cmakedefine HAVE_VA_COPY -// #cmakedefine HAVE___VA_COPY +#cmakedefine HAVE_SNPRINTF +#cmakedefine HAVE__SNPRINTF +#cmakedefine HAVE_VSNPRINTF +#cmakedefine HAVE__VSNPRINTF +#cmakedefine HAVE_VASPRINTF +#cmakedefine HAVE__VASPRINTF +#cmakedefine HAVE_ASPRINTF +#cmakedefine HAVE__ASPRINTF +#cmakedefine HAVE_LOCALECONV +#cmakedefine HAVE_VA_COPY +#cmakedefine HAVE___VA_COPY #cmakedefine HAVE_MTX_INIT #cmakedefine HAVE_MTX_LOCK diff --git a/src/utils/dsl.h b/src/utils/dsl.h index 0471ba8f4..d26a4c3a2 100644 --- a/src/utils/dsl.h +++ b/src/utils/dsl.h @@ -49,10 +49,10 @@ /* Determine platform */ -#if defined __APPLE__ && defined __MARCH__ +#if defined __APPLE__ && defined __MACH__ # define DSL_PLATFORM DSL_Posix # ifndef DSL_PREFIX -# define DSL_PREFIX "" +# define DSL_PREFIX "lib" # endif # ifndef DSL_EXT # define DSL_EXT ".dylib" diff --git a/src/utils/fileinfo.c b/src/utils/fileinfo.c index ec35dd001..d836f1cbb 100644 --- a/src/utils/fileinfo.c +++ b/src/utils/fileinfo.c @@ -12,7 +12,7 @@ #include #include -#if defined(__unix__) +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) # ifndef POSIX # define POSIX # endif diff --git a/src/utils/fileutils.c b/src/utils/fileutils.c index 00dbde851..94b660050 100644 --- a/src/utils/fileutils.c +++ b/src/utils/fileutils.c @@ -71,11 +71,11 @@ static char *_platform_names[] = {"Native", "Unix", "Windows", "Apple", NULL}; */ FUPlatform fu_native_platform(void) { -#if defined POSIX +#if defined POSIX && !defined(__APPLE__) return fuUnix; #elif defined WINDOWS return fuWindows; -#elif defined __APPLE__ +#elif (defined __APPLE__ && defined __MACH__) return fuApple; #else return fuUnknownPlatform; @@ -91,6 +91,7 @@ int fu_supported_platform(FUPlatform platform) switch (platform) { case fuUnix: case fuWindows: + case fuApple: return 1; default: return 0; @@ -127,8 +128,11 @@ const char *fu_dirsep(FUPlatform platform) { if (platform == fuNative) platform = fu_native_platform(); switch (platform) { - case fuUnix: return "/"; - case fuWindows: return "\\"; + case fuUnix: + case fuApple: + return "/"; + case fuWindows: + return "\\"; default: return err(1, "unsupported platform: %d", platform), NULL; } } @@ -140,8 +144,11 @@ const char *fu_pathsep(FUPlatform platform) { if (platform == fuNative) platform = fu_native_platform(); switch (platform) { - case fuUnix: return ":"; - case fuWindows: return ";"; + case fuUnix: + case fuApple: + return ":"; + case fuWindows: + return ";"; default: return err(1, "unsupported platform: %d", platform), NULL; } } @@ -590,6 +597,7 @@ char *fu_nativepath(const char *path, char *dest, size_t size, { switch (fu_native_platform()) { case fuUnix: + case fuApple: return fu_unixpath(path, dest, size, pathsep); case fuWindows: return fu_winpath(path, dest, size, pathsep); @@ -811,7 +819,7 @@ FUPlatform fu_paths_set_platform(FUPaths *paths, FUPlatform platform) for (i=0; i < paths->n; i++) { const char *p = paths->paths[i]; - if (platform == fuUnix) + if (platform == fuUnix || platform == fuApple) paths->paths[i] = fu_unixpath(p, NULL, 0, ":"); else if (platform == fuWindows) paths->paths[i] = fu_winpath(p, NULL, 0, ";"); @@ -942,7 +950,10 @@ int fu_paths_insertn(FUPaths *paths, const char *path, size_t len, int n) if (!fu_supported_platform(platform)) FAIL1("unsupported platform: %d", platform); switch (platform) { - case fuUnix: p = fu_unixpath(path, NULL, 0, paths->pathsep); break; + case fuUnix: + case fuApple: + p = fu_unixpath(path, NULL, 0, paths->pathsep); + break; case fuWindows: p = fu_winpath(path, NULL, 0, paths->pathsep); break; default: assert(0); // should never happen } @@ -1292,7 +1303,7 @@ FUIter *fu_pathsiter_init(const FUPaths *paths, const char *pattern) } /* - Help function for fu_paths_iter_nextfile(), which does not take `pattern` + Help function for fu_pathsiter_next(), which does not take `pattern` into account. */ const char *_fu_pathsiter_next(FUIter *iter) @@ -1394,7 +1405,7 @@ const char *fu_pathsiter_next(FUIter *iter) } /* - Deallocates iterator created with fu_paths_iter_init(). + Deallocates iterator created with fu_pathsiter_init(). Returns non-zero on error. */ int fu_pathsiter_deinit(FUIter *iter) diff --git a/src/utils/fileutils.h b/src/utils/fileutils.h index 817385cde..de331de86 100644 --- a/src/utils/fileutils.h +++ b/src/utils/fileutils.h @@ -22,7 +22,7 @@ enum { }; -#if defined __unix__ || (defined __APPLE__ && defined __MARCH__) +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) /* POSIX */ # ifndef POSIX # define POSIX @@ -65,7 +65,7 @@ typedef enum _FUPlatform { fuNative=0, /*!< Platform we are compiling on */ fuUnix, /*!< Unix-like platforms; POSIX complient */ fuWindows, /*!< Windows */ - fuApple, /*!< Apple - not yet supported... */ + fuApple, /*!< Apple */ fuLastPlatform /*!< Must always be the last */ } FUPlatform;