src: fix _XOPEN_SOURCE redefinition warning
authorBen Noordhuis <info@bnoordhuis.nl>
Tue, 13 May 2014 11:45:21 +0000 (13:45 +0200)
committerFedor Indutny <fedor@indutny.com>
Wed, 14 May 2014 11:33:18 +0000 (15:33 +0400)
Fix the following compiler warning on systems where _XOPEN_SOURCE is
defined by default:

    ../src/node_constants.cc:35:0: warning: "_XOPEN_SOURCE" redefined
     #define _XOPEN_SOURCE 500

Move the (re)definition of _XOPEN_SOURCE to the top of the file while
we're here.  Commit 00890e4 adds a `#define _XOPEN_SOURCE 500` in order
to make <fcntl.h> expose O_NONBLOCK but it does so after other system
headers have been included.  If those headers include <fcntl.h>, then
the #include in node_constants.cc will be a no-op and O_NONBLOCK won't
be visible.

Signed-off-by: Fedor Indutny <fedor@indutny.com>
src/node_constants.cc

index d364fb2..adb6f28 100644 (file)
 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 // USE OR OTHER DEALINGS IN THE SOFTWARE.
 
+// O_NONBLOCK is not exported unless _XOPEN_SOURCE >= 500.
+#if defined(_XOPEN_SOURCE) && _XOPEN_SOURCE < 500
+#undef _XOPEN_SOURCE
+#endif
+
+#if !defined(_XOPEN_SOURCE)
+#define _XOPEN_SOURCE 500
+#endif
+
 #include "node_constants.h"
 
 #include "uv.h"
 
 #include <errno.h>
+#include <fcntl.h>
 #if !defined(_MSC_VER)
 #include <unistd.h>
 #endif
 #include <sys/types.h>
 #include <sys/stat.h>
 
-// O_NONBLOCK is not exported, unless _XOPEN_SOURCE is set
-#define _XOPEN_SOURCE 500
-#include <fcntl.h>
-
 #if HAVE_OPENSSL
 # include <openssl/ssl.h>
 #endif