From 9b12e023ab1e4e9a9f976d0980f4aa0b351c4be6 Mon Sep 17 00:00:00 2001 From: Joran Dirk Greef Date: Fri, 6 Sep 2019 22:50:26 +0200 Subject: [PATCH] unix: fix UV_FS_O_DIRECT definition on Linux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to http://man7.org/linux/man-pages/man2/open.2.html, the O_DIRECT flag is Linux-specific. One must define _GNU_SOURCE to obtain the correct definition. However, defining _GNU_SOURCE in the headers is unhygienic and affects the libuv consumer. On Linux, we now define UV_FS_O_DIRECT explicitly according to architecture, only falling back to O_DIRECT if defined, or 0 if not. Fixes: https://github.com/libuv/libuv/issues/2420 PR-URL: https://github.com/libuv/libuv/pull/2441 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: Saúl Ibarra Corretgé --- include/uv/unix.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/include/uv/unix.h b/include/uv/unix.h index 9080352d..3a131638 100644 --- a/include/uv/unix.h +++ b/include/uv/unix.h @@ -405,11 +405,25 @@ typedef struct { #else # define UV_FS_O_CREAT 0 #endif -#if defined(O_DIRECT) + +#if defined(__linux__) && defined(__arm__) +# define UV_FS_O_DIRECT 0x10000 +#elif defined(__linux__) && defined(__m68k__) +# define UV_FS_O_DIRECT 0x10000 +#elif defined(__linux__) && defined(__mips__) +# define UV_FS_O_DIRECT 0x08000 +#elif defined(__linux__) && defined(__powerpc__) +# define UV_FS_O_DIRECT 0x20000 +#elif defined(__linux__) && defined(__s390x__) +# define UV_FS_O_DIRECT 0x04000 +#elif defined(__linux__) && defined(__x86_64__) +# define UV_FS_O_DIRECT 0x04000 +#elif defined(O_DIRECT) # define UV_FS_O_DIRECT O_DIRECT #else # define UV_FS_O_DIRECT 0 #endif + #if defined(O_DIRECTORY) # define UV_FS_O_DIRECTORY O_DIRECTORY #else