mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
daemon/Win32: provide htonl, htons, ntohl, ntohs functions.
These functions are not available on Windows.
This commit is contained in:
1
daemon/.gitignore
vendored
1
daemon/.gitignore
vendored
@@ -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
|
||||
|
||||
@@ -91,6 +91,7 @@ guestfsd_SOURCES = \
|
||||
guestfsd.c \
|
||||
headtail.c \
|
||||
hexdump.c \
|
||||
htonl.c \
|
||||
initrd.c \
|
||||
inotify.c \
|
||||
link.c \
|
||||
|
||||
@@ -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 \
|
||||
|
||||
82
daemon/htonl.c
Normal file
82
daemon/htonl.c
Normal file
@@ -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 */
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user