Whamcloud - gitweb
lib, misc: eliminate dependency on Winsock
authorEric Biggers <ebiggers@google.com>
Sat, 21 Jan 2023 20:31:58 +0000 (12:31 -0800)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 27 Jan 2023 17:33:59 +0000 (12:33 -0500)
Currently Windows builds of e2fsprogs rely on the Windows Socket API
(Winsock) to provide htonl() and ntohl().  For this to actually work,
though, HAVE_WINSOCK_H needs to be defined, and the binaries need to be
linked to -lws2_32.  The Android.bp files do this; however, the
autotools-based build system does not.

Since htonl() and ntohl() are trivial, let's instead just add a file
include/mingw/arpa/inet.h with definitions for these.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
include/mingw/arpa/inet.h [new file with mode: 0644]
lib/e2p/Android.bp
lib/ext2fs/Android.bp
lib/ext2fs/jfs_compat.h
misc/Android.bp
util/android_config.h

diff --git a/include/mingw/arpa/inet.h b/include/mingw/arpa/inet.h
new file mode 100644 (file)
index 0000000..55dfa36
--- /dev/null
@@ -0,0 +1,5 @@
+#pragma once
+
+/* Windows is always little endian. */
+#define htonl  __builtin_bswap32
+#define ntohl  __builtin_bswap32
index 6f0620a..050d869 100644 (file)
@@ -59,10 +59,6 @@ cc_library {
                 "-Wno-unused-variable",
                 "-Wno-error=typedef-redefinition",
             ],
-
-            host_ldlibs: [
-                "-lws2_32",
-            ],
         },
     },
 
index 365ca70..eb4482d 100644 (file)
@@ -126,8 +126,6 @@ cc_library {
                 "-Wno-unused-variable",
                 "-Wno-error=typedef-redefinition",
             ],
-
-            host_ldlibs: ["-lws2_32"],
         },
     },
 
index e11cf49..0e96b56 100644 (file)
@@ -7,11 +7,7 @@
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
-#ifdef HAVE_WINSOCK_H
-#include <winsock.h>
-#else
 #include <arpa/inet.h>
-#endif
 #include <stdbool.h>
 
 #define printk printf
index 78e18e4..2baeac2 100644 (file)
@@ -91,7 +91,6 @@ cc_binary {
                 "-Wno-error"
             ],
             ldflags: ["-static"],
-            host_ldlibs: ["-lws2_32"],
             enabled: true
         },
         android: {
index 6ac16fe..90b8f8a 100644 (file)
@@ -36,7 +36,6 @@
 
 #if defined(_WIN32)
 # define HAVE_LINUX_TYPES_H 1
-# define HAVE_WINSOCK_H 1
 #endif
 #if defined(__APPLE__) || defined(__linux__)
 # define HAVE_FCNTL 1