Richard W.M. Jones
2009-Nov-26 11:31 UTC
[Libguestfs] [PATCH] daemon/Win32: provide htonl, htons, ntohl, ntohs functions.
This is another candidate for gnulib ... Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw -------------- next part -------------->From c47bf70af3222dabd8f966c15f2cc11787f25b86 Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at redhat.com> Date: Thu, 26 Nov 2009 11:26:40 +0000 Subject: [PATCH 2/2] daemon/Win32: provide htonl, htons, ntohl, ntohs functions. These functions are not available on Windows. --- daemon/.gitignore | 1 + daemon/Makefile.am | 1 + daemon/configure.ac | 4 ++ daemon/htonl.c | 82 +++++++++++++++++++++++++++++++++++++++++++++ daemon/m4/gnulib-cache.m4 | 3 +- 5 files changed, 90 insertions(+), 1 deletions(-) create mode 100644 daemon/htonl.c diff --git a/daemon/.gitignore b/daemon/.gitignore index ac1b47b..0d9dac7 100644 --- a/daemon/.gitignore +++ b/daemon/.gitignore @@ -4,6 +4,7 @@ link-warning.h 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 diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 103e49d..2f43448 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -91,6 +91,7 @@ guestfsd_SOURCES = \ guestfsd.c \ headtail.c \ hexdump.c \ + htonl.c \ initrd.c \ inotify.c \ link.c \ diff --git a/daemon/configure.ac b/daemon/configure.ac index bd0bdbe..1d335b1 100644 --- a/daemon/configure.ac +++ b/daemon/configure.ac @@ -171,6 +171,8 @@ AC_CHECK_LIB([portablexdr],[xdrmem_create],[],[ dnl Functions which may not be available in older distributions. AC_CHECK_FUNCS([\ getxattr \ + htonl \ + htons \ inotify_init1 \ lgetxattr \ listxattr \ @@ -178,6 +180,8 @@ AC_CHECK_FUNCS([\ lsetxattr \ lremovexattr \ mknod \ + ntohl \ + ntohs \ posix_fallocate \ removexattr \ setxattr \ diff --git a/daemon/htonl.c b/daemon/htonl.c new file mode 100644 index 0000000..784b2bd --- /dev/null +++ b/daemon/htonl.c @@ -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 + +static inline 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 +} + +#define ntohl htonl + +#endif /* HAVE_NTOHL */ + +#ifndef HAVE_NTOHS + +#undef htons +#undef ntohs + +static inline 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 +} + +#define ntohs htons + +#endif /* HAVE_NTOHS */ diff --git a/daemon/m4/gnulib-cache.m4 b/daemon/m4/gnulib-cache.m4 index 01da897..e8b9edf 100644 --- a/daemon/m4/gnulib-cache.m4 +++ b/daemon/m4/gnulib-cache.m4 @@ -15,11 +15,12 @@ # 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([ + byteswap c-ctype fsusage futimens -- 1.6.5.2
Jim Meyering
2009-Nov-26 11:41 UTC
[Libguestfs] [PATCH] daemon/Win32: provide htonl, htons, ntohl, ntohs functions.
Richard W.M. Jones wrote:> This is another candidate for gnulib ...Yes, indeed. ...> +static inline uint16_t > +htons (x) > + uint16_t x; > +{Using old-style function definitions like this is odd, but then I realized this was probably copied from glibc. Did you have to make any changes? ACK.
Apparently Analagous Threads
- [PATCH] daemon/Win32: Don't bother blocking SIGPIPE on Win32.
- [PATCH] daemon/Win32: Windows replacement for umask.
- [LLVMdev] [PATCH] compiler-rt patch for clean build on Solaris 10 / x86
- [PATCH 0/2] Two small fixes to command*() functions in the daemon
- Notes: Building the daemon on Windows