daemon/Win32: provide htonl, htons, ntohl, ntohs functions.
authorRichard Jones <rjones@redhat.com>
Thu, 26 Nov 2009 11:26:40 +0000 (11:26 +0000)
committerRichard Jones <rjones@redhat.com>
Thu, 26 Nov 2009 11:52:44 +0000 (11:52 +0000)
These functions are not available on Windows.

daemon/.gitignore
daemon/Makefile.am
daemon/configure.ac
daemon/htonl.c [new file with mode: 0644]
daemon/m4/gnulib-cache.m4

index ac1b47b..0d9dac7 100644 (file)
@@ -4,6 +4,7 @@ link-warning.h
 m4/00gnulib.m4
 m4/alloca.m4
 m4/arpa_inet_h.m4
 m4/00gnulib.m4
 m4/alloca.m4
 m4/arpa_inet_h.m4
+m4/byteswap.m4
 m4/canonicalize-lgpl.m4
 m4/chdir-long.m4
 m4/chown.m4
 m4/canonicalize-lgpl.m4
 m4/chdir-long.m4
 m4/chown.m4
index 103e49d..2f43448 100644 (file)
@@ -91,6 +91,7 @@ guestfsd_SOURCES = \
        guestfsd.c \
        headtail.c \
        hexdump.c \
        guestfsd.c \
        headtail.c \
        hexdump.c \
+       htonl.c \
        initrd.c \
        inotify.c \
        link.c \
        initrd.c \
        inotify.c \
        link.c \
index bd0bdbe..1d335b1 100644 (file)
@@ -171,6 +171,8 @@ AC_CHECK_LIB([portablexdr],[xdrmem_create],[],[
 dnl Functions which may not be available in older distributions.
 AC_CHECK_FUNCS([\
         getxattr \
 dnl Functions which may not be available in older distributions.
 AC_CHECK_FUNCS([\
         getxattr \
+        htonl \
+        htons \
         inotify_init1 \
         lgetxattr \
         listxattr \
         inotify_init1 \
         lgetxattr \
         listxattr \
@@ -178,6 +180,8 @@ AC_CHECK_FUNCS([\
         lsetxattr \
         lremovexattr \
         mknod \
         lsetxattr \
         lremovexattr \
         mknod \
+        ntohl \
+        ntohs \
         posix_fallocate \
         removexattr \
         setxattr \
         posix_fallocate \
         removexattr \
         setxattr \
diff --git a/daemon/htonl.c b/daemon/htonl.c
new file mode 100644 (file)
index 0000000..c9f1af0
--- /dev/null
@@ -0,0 +1,82 @@
+/* Copyright (C) 1993,97,2002 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+/* Windows lacks htonl, htons, ntohl, ntohs.  It defines them in
+ * header files, but doesn't have them in any library.  However
+ * because it defined them we can end up with conflicting
+ * definitions, which is why here we are careful to avoid
+ * including any Windows header file.
+ */
+
+#include <config.h>
+
+#include <stdint.h>
+#include <sys/param.h>
+#include <byteswap.h>
+
+#ifndef HAVE_NTOHL
+
+#undef htonl
+#undef ntohl
+
+uint32_t
+htonl (x)
+     uint32_t x;
+{
+#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
+#if BYTE_ORDER == BIG_ENDIAN
+  return x;
+#elif BYTE_ORDER == LITTLE_ENDIAN
+  return bswap_32 (x);
+#else
+# error "What kind of system is this?"
+#endif
+#else
+#error "BYTE_ORDER/BIG_ENDIAN/LITTLE_ENDIAN are not defined"
+#endif
+}
+
+uint32_t ntohl (uint32_t x) { return htonl (x); }
+
+#endif /* !HAVE_NTOHL */
+
+#ifndef HAVE_NTOHS
+
+#undef htons
+#undef ntohs
+
+uint16_t
+htons (x)
+     uint16_t x;
+{
+#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
+#if BYTE_ORDER == BIG_ENDIAN
+  return x;
+#elif BYTE_ORDER == LITTLE_ENDIAN
+  return bswap_16 (x);
+#else
+# error "What kind of system is this?"
+#endif
+#else
+#error "BYTE_ORDER/BIG_ENDIAN/LITTLE_ENDIAN are not defined"
+#endif
+}
+
+uint16_t ntohs (uint16_t x) { return htons (x); }
+
+#endif /* !HAVE_NTOHS */
index 01da897..e8b9edf 100644 (file)
 
 
 # Specification in the form of a command-line invocation:
 
 
 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --with-tests --no-libtool --macro-prefix=gl c-ctype fsusage futimens getaddrinfo getline glob hash ignore-value manywarnings mkdtemp netdb openat perror pread readlink select sleep strchrnul strndup sys_select sys_wait vasprintf warnings
+#   gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --with-tests --no-libtool --macro-prefix=gl byteswap c-ctype fsusage futimens getaddrinfo getline glob hash ignore-value manywarnings mkdtemp netdb openat perror pread readlink select sleep strchrnul strndup sys_select sys_wait vasprintf warnings
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([])
 gl_MODULES([
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([])
 gl_MODULES([
+  byteswap
   c-ctype
   fsusage
   futimens
   c-ctype
   fsusage
   futimens