compat.h revision 0066c4346f1ebf4dae0862538b596dca6fb8b1ba
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#ifndef __COMPAT_H
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#define __COMPAT_H
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch/* well, this is obviously wrong since it assumes it's 64bit, but older
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch GCCs don't define it and we really want it. */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#ifndef LLONG_MAX
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch# define LLONG_MAX 9223372036854775807LL
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#endif
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#if defined (UOFF_T_INT)
009217abb57a24a4076092e8e4e165545747839eStephan Boschtypedef unsigned int uoff_t;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#elif defined (UOFF_T_LONG)
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschtypedef unsigned long uoff_t;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#elif defined (UOFF_T_LONG_LONG)
6541da94741ea43514cdac3dd2ebbcf839ffb783Stephan Boschtypedef unsigned long long uoff_t;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen#else
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch# error uoff_t size not set
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#endif
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
#ifndef HAVE_UINTMAX_T
# if SIZEOF_LONG_LONG > 0
typedef unsigned long long uintmax_t;
# else
typedef unsigned long uintmax_t;
# endif
#endif
#ifndef HAVE_SOCKLEN_T
typedef int socklen_t;
#endif
#ifdef HAVE_SYS_SYSMACROS_H
# include <sys/sysmacros.h>
# define CMP_DEV_T(a, b) (major(a) == major(b) && minor(a) == minor(b))
#elif !defined (DEV_T_STRUCT)
# define CMP_DEV_T(a, b) ((a) == (b))
#else
# error I do not know how to compare dev_t
#endif
/* memmove() */
#ifndef HAVE_MEMMOVE
# define memmove my_memmove
void *my_memmove(void *dest, const void *src, size_t n);
#endif
/* strcasecmp(), strncasecmp() */
#ifndef HAVE_STRCASECMP
# ifdef HAVE_STRICMP
# define strcasecmp stricmp
# define strncasecmp strnicmp
# else
# define strcasecmp my_strcasecmp
# define strncasecmp my_strncasecmp
int my_strcasecmp(const char *s1, const char *s2);
int my_strncasecmp(const char *s1, const char *s2, size_t max_chars);
# endif
#endif
#ifndef HAVE_INET_ATON
# include <sys/socket.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# define inet_aton my_inet_aton
int my_inet_aton(const char *cp, struct in_addr *inp);
#endif
#ifndef HAVE_VSYSLOG
# define vsyslog my_vsyslog
void my_vsyslog(int priority, const char *format, va_list args);
#endif
#ifndef HAVE_GETPAGESIZE
# define getpagesize my_getpagesize
int my_getpagesize(void);
#endif
#ifndef HAVE_FDATASYNC
# define fdatasync fsync
#endif
#ifndef HAVE_STRUCT_IOVEC
struct iovec {
void *iov_base;
size_t iov_len;
};
#endif
#ifndef HAVE_WRITEV
# define writev my_writev
struct iovec;
ssize_t my_writev(int fd, const struct iovec *iov, size_t iov_len);
#endif
/* ctype.h isn't safe with signed chars,
use our own instead if really needed */
#define i_toupper(x) ((char) toupper((int) (unsigned char) (x)))
#define i_tolower(x) ((char) tolower((int) (unsigned char) (x)))
#define i_isalnum(x) isalnum((int) (unsigned char) (x))
#define i_isalpha(x) isalpha((int) (unsigned char) (x))
#define i_isascii(x) isascii((int) (unsigned char) (x))
#define i_isblank(x) isblank((int) (unsigned char) (x))
#define i_iscntrl(x) iscntrl((int) (unsigned char) (x))
#define i_isdigit(x) isdigit((int) (unsigned char) (x))
#define i_isgraph(x) isgraph((int) (unsigned char) (x))
#define i_islower(x) islower((int) (unsigned char) (x))
#define i_isprint(x) isprint((int) (unsigned char) (x))
#define i_ispunct(x) ispunct((int) (unsigned char) (x))
#define i_isspace(x) isspace((int) (unsigned char) (x))
#define i_isupper(x) isupper((int) (unsigned char) (x))
#define i_isxdigit(x) isxdigit((int) (unsigned char) (x))
#ifndef EOVERFLOW
# define EOVERFLOW EINVAL
#endif
#endif