Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -899,10 +899,12 @@ 4BC176351D04963000C32718 /* OFTarArchiveEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BC176291D04963000C32718 /* OFTarArchiveEntry.m */; }; 4BC176361D04963000C32718 /* OFTarArchiveEntry+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC1762A1D04963000C32718 /* OFTarArchiveEntry+Private.h */; }; 4BC1C3EB184B5EB200BBF50F /* OFMapTable+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC1C3EA184B5EB200BBF50F /* OFMapTable+Private.h */; }; 4BCAA9AF1772432F003EF859 /* OFMessagePackExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BCAA9AD1772432E003EF859 /* OFMessagePackExtension.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BCAA9B01772432F003EF859 /* OFMessagePackExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BCAA9AE1772432E003EF859 /* OFMessagePackExtension.m */; }; + 4BCE4EC41ED98D1400502FF0 /* unistd_wrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BCE4EC31ED98D1400502FF0 /* unistd_wrapper.h */; }; + 4BCE4EC51ED98D1400502FF0 /* unistd_wrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BCE4EC31ED98D1400502FF0 /* unistd_wrapper.h */; }; 4BD112611CCB73A60076FDB9 /* OFGZIPStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BD1125F1CCB739A0076FDB9 /* OFGZIPStream.m */; }; 4BD112621CCB73A90076FDB9 /* OFGZIPStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BD1125E1CCB739A0076FDB9 /* OFGZIPStream.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BD306311D46CEAE00E2F372 /* PBKDF2Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BD306301D46CEAE00E2F372 /* PBKDF2Tests.m */; }; 4BD306341D46CEE300E2F372 /* pbkdf2.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BD306321D46CEE300E2F372 /* pbkdf2.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BD306351D46CEE300E2F372 /* pbkdf2.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BD306331D46CEE300E2F372 /* pbkdf2.m */; }; @@ -1573,10 +1575,11 @@ 4BC176291D04963000C32718 /* OFTarArchiveEntry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFTarArchiveEntry.m; path = src/OFTarArchiveEntry.m; sourceTree = ""; }; 4BC1762A1D04963000C32718 /* OFTarArchiveEntry+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFTarArchiveEntry+Private.h"; path = "src/OFTarArchiveEntry+Private.h"; sourceTree = ""; }; 4BC1C3EA184B5EB200BBF50F /* OFMapTable+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFMapTable+Private.h"; path = "src/OFMapTable+Private.h"; sourceTree = ""; }; 4BCAA9AD1772432E003EF859 /* OFMessagePackExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFMessagePackExtension.h; path = src/OFMessagePackExtension.h; sourceTree = ""; }; 4BCAA9AE1772432E003EF859 /* OFMessagePackExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFMessagePackExtension.m; path = src/OFMessagePackExtension.m; sourceTree = ""; }; + 4BCE4EC31ED98D1400502FF0 /* unistd_wrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = unistd_wrapper.h; path = src/unistd_wrapper.h; sourceTree = ""; }; 4BD1125E1CCB739A0076FDB9 /* OFGZIPStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFGZIPStream.h; path = src/OFGZIPStream.h; sourceTree = ""; }; 4BD1125F1CCB739A0076FDB9 /* OFGZIPStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFGZIPStream.m; path = src/OFGZIPStream.m; sourceTree = ""; }; 4BD306301D46CEAE00E2F372 /* PBKDF2Tests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PBKDF2Tests.m; path = tests/PBKDF2Tests.m; sourceTree = ""; }; 4BD306321D46CEE300E2F372 /* pbkdf2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pbkdf2.h; path = src/pbkdf2.h; sourceTree = ""; }; 4BD306331D46CEE300E2F372 /* pbkdf2.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = pbkdf2.m; path = src/pbkdf2.m; sourceTree = ""; }; @@ -2245,10 +2248,11 @@ 4B67998B1099E7C50041064A /* threading.h */, 4B3379CE1979326A0088E97E /* threading.m */, 4BABC29A197A8212006A93BD /* threading_pthread.m */, 4B67998C1099E7C50041064A /* unicode.h */, 4BFBDD1610A0724800051AFB /* unicode.m */, + 4BCE4EC31ED98D1400502FF0 /* unistd_wrapper.h */, ); name = ObjFW; sourceTree = ""; }; 4B6EF66D123535480076B512 /* Tests */ = { @@ -2607,10 +2611,11 @@ 4B2C22A61DA292BE00735907 /* OFThread+Private.h in Headers */, 4B2C22A71DA292BE00735907 /* OFTimer+Private.h in Headers */, 4B853CEC1EBFDEB000A4B2C4 /* OFXMLNode+Private.h in Headers */, 4B2C22A81DA292BE00735907 /* OFZIPArchiveEntry+Private.h in Headers */, 4B2C22AA1DA292BE00735907 /* socket_helpers.h in Headers */, + 4BCE4EC51ED98D1400502FF0 /* unistd_wrapper.h in Headers */, 4BFC37BE1E50E11C00EE1269 /* common.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; 4B3D23731337FBC800DD29B8 /* Headers */ = { @@ -2831,10 +2836,11 @@ 4B6C8ADC17BD5C2E00B194F2 /* OFThread+Private.h in Headers */, 4B6C8ADD17BD5C2E00B194F2 /* OFTimer+Private.h in Headers */, 4B853CEB1EBFDEB000A4B2C4 /* OFXMLNode+Private.h in Headers */, 4B6C8ADE17BD5C2E00B194F2 /* OFZIPArchiveEntry+Private.h in Headers */, 4B7DD58218942FE200990FD6 /* socket_helpers.h in Headers */, + 4BCE4EC41ED98D1400502FF0 /* unistd_wrapper.h in Headers */, 4BFC37BD1E50E11C00EE1269 /* common.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; 4B5D70711DA2F87A00B3B2D7 /* Headers */ = { Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -1230,11 +1230,11 @@ ]) ]) dnl This needs to be after all other header checks, as they include unistd.h, dnl which in old glibc versions uses __block. This is worked around in the code -dnl by undefining __USE_XOPEN. +dnl by providing a wrapper for unistd.h which takes care of this. AC_MSG_CHECKING(whether Objective C compiler supports blocks) old_OBJCFLAGS="$OBJCFLAGS" OBJCFLAGS="$OBJCFLAGS -fblocks" AC_TRY_COMPILE([], [ int (^foo)(int bar); Index: src/OFApplication.m ================================================================== --- src/OFApplication.m +++ src/OFApplication.m @@ -21,19 +21,11 @@ #include #include #include -#ifdef HAVE_UNISTD_H -# ifdef __GLIBC__ -# undef __USE_XOPEN /* Needed to avoid old glibc using __block */ -# endif -# include -# ifdef __GLIBC__ -# define __USE_XOPEN 1 -# endif -#endif +#include "unistd_wrapper.h" #import "OFApplication.h" #import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -19,19 +19,11 @@ #include #ifdef HAVE_FCNTL_H # include #endif -#ifdef HAVE_UNISTD_H -# ifdef __GLIBC__ -# undef __USE_XOPEN /* Needed to avoid old glibc using __block */ -# endif -# include -# ifdef __GLIBC__ -# define __USE_XOPEN 1 -# endif -#endif +#include "unistd_wrapper.h" #include "platform.h" #ifdef OF_WII # define BOOL OGC_BOOL Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -19,19 +19,11 @@ #include #ifdef HAVE_DIRENT_H # include #endif -#ifdef HAVE_UNISTD_H -# ifdef __GLIBC__ -# undef __USE_XOPEN /* Needed to avoid old glibc using __block */ -# endif -# include -# ifdef __GLIBC__ -# define __USE_XOPEN 1 -# endif -#endif +#include "unistd_wrapper.h" #ifdef HAVE_PWD_H # include #endif #ifdef HAVE_GRP_H Index: src/OFKernelEventObserver_epoll.m ================================================================== --- src/OFKernelEventObserver_epoll.m +++ src/OFKernelEventObserver_epoll.m @@ -20,19 +20,11 @@ #include #ifdef HAVE_FCNTL_H # include #endif -#ifdef HAVE_UNISTD_H -# ifdef __GLIBC__ -# undef __USE_XOPEN /* Needed to avoid old glibc using __block */ -# endif -# include -# ifdef __GLIBC__ -# define __USE_XOPEN 1 -# endif -#endif +#include "unistd_wrapper.h" #include #import "OFKernelEventObserver.h" #import "OFKernelEventObserver+Private.h" Index: src/OFKernelEventObserver_kqueue.m ================================================================== --- src/OFKernelEventObserver_kqueue.m +++ src/OFKernelEventObserver_kqueue.m @@ -21,13 +21,11 @@ #include #ifdef HAVE_FCNTL_H # include #endif -#ifdef HAVE_UNISTD_H -# include -#endif +#include "unistd_wrapper.h" #include #include #include Index: src/OFProcess.m ================================================================== --- src/OFProcess.m +++ src/OFProcess.m @@ -19,24 +19,15 @@ #include #include #include -#ifdef HAVE_UNISTD_H -# ifdef __GLIBC__ -# undef __USE_XOPEN /* Needed to avoid old glibc using __block */ -# endif -# include -# ifdef __GLIBC__ -# define __USE_XOPEN 1 -# endif -#endif - #ifdef HAVE_SYS_WAIT_H # include #endif +#include "unistd_wrapper.h" #ifdef HAVE_SPAWN_H # include #endif #import "OFProcess.h" Index: src/OFStdIOStream.m ================================================================== --- src/OFStdIOStream.m +++ src/OFStdIOStream.m @@ -16,19 +16,11 @@ #include "config.h" #include -#ifdef HAVE_UNISTD_H -# ifdef __GLIBC__ -# undef __USE_XOPEN /* Needed to avoid old glibc using __block */ -# endif -# include -# ifdef __GLIBC__ -# define __USE_XOPEN 1 -# endif -#endif +#include "unistd_wrapper.h" #ifdef HAVE_SYS_IOCTL_H # include #endif #ifdef HAVE_SYS_TTYCOM_H Index: src/OFSystemInfo.m ================================================================== --- src/OFSystemInfo.m +++ src/OFSystemInfo.m @@ -18,19 +18,11 @@ #include "config.h" #include /* include any libc header to get the libc defines */ -#ifdef HAVE_UNISTD_H -# ifdef __GLIBC__ -# undef __USE_XOPEN /* Needed to avoid old glibc using __block */ -# endif -# include -# ifdef __GLIBC__ -# define __USE_XOPEN 1 -# endif -#endif +#include "unistd_wrapper.h" #include "platform.h" #ifdef OF_MACOS # include Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -22,23 +22,14 @@ #include #include #include -#ifdef HAVE_UNISTD_H -# ifdef __GLIBC__ -# undef __USE_XOPEN /* Needed to avoid old glibc using __block */ -# endif -# include -# ifdef __GLIBC__ -# define __USE_XOPEN 1 -# endif -#endif - #ifdef OF_HAVE_SCHED_YIELD # include #endif +#include "unistd_wrapper.h" #include "platform.h" #ifdef OF_WII # define BOOL OGC_BOOL Index: src/socket_helpers.h ================================================================== --- src/socket_helpers.h +++ src/socket_helpers.h @@ -14,21 +14,11 @@ * file. */ #include "config.h" -#include /* include any libc header to get the libc defines */ - -#ifdef HAVE_UNISTD_H -# ifdef __GLIBC__ -# undef __USE_XOPEN /* Needed to avoid old glibc using __block */ -# endif -# include -# ifdef __GLIBC__ -# define __USE_XOPEN 1 -# endif -#endif +#include "unistd_wrapper.h" #ifdef HAVE_ARPA_INET_H # include #endif #ifdef HAVE_NETDB_H ADDED src/unistd_wrapper.h Index: src/unistd_wrapper.h ================================================================== --- src/unistd_wrapper.h +++ src/unistd_wrapper.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 + * Jonathan Schleifer * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include /* Make sure we have any libc include */ + +#ifdef HAVE_UNISTD_H +# ifdef __GLIBC__ +# undef __USE_XOPEN /* Needed to avoid old glibc using __block */ +# endif +# include +# ifdef __GLIBC__ +# define __USE_XOPEN 1 +# endif +#endif