+#ifndef ACCESSPERMS
+#define ACCESSPERMS 0777
+#endif
+
+#ifndef S_ISVTX
+#define S_ISVTX 0
+#endif
+
+#define CHMOD_BITS (S_ISUID | S_ISGID | S_ISVTX | ACCESSPERMS)
+
+#ifndef _S_IFMT
+#define _S_IFMT 0170000
+#endif
+
+#ifndef _S_IFLNK
+#define _S_IFLNK 0120000
+#endif
+
+#ifndef S_ISLNK
+#define S_ISLNK(mode) (((mode) & (_S_IFMT)) == (_S_IFLNK))
+#endif
+
+#ifndef S_ISBLK
+#define S_ISBLK(mode) (((mode) & (_S_IFMT)) == (_S_IFBLK))
+#endif
+
+#ifndef S_ISCHR
+#define S_ISCHR(mode) (((mode) & (_S_IFMT)) == (_S_IFCHR))
+#endif
+
+#ifndef S_ISSOCK
+#ifdef _S_IFSOCK
+#define S_ISSOCK(mode) (((mode) & (_S_IFMT)) == (_S_IFSOCK))
+#else
+#define S_ISSOCK(mode) (0)
+#endif
+#endif
+
+#ifndef S_ISFIFO
+#ifdef _S_IFIFO
+#define S_ISFIFO(mode) (((mode) & (_S_IFMT)) == (_S_IFIFO))
+#else
+#define S_ISFIFO(mode) (0)
+#endif
+#endif
+
+#ifndef S_ISDIR
+#define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
+#endif
+
+#ifndef S_ISREG
+#define S_ISREG(mode) (((mode) & (_S_IFMT)) == (_S_IFREG))
+#endif
+
+/* work out what fcntl flag to use for non-blocking */
+#ifdef O_NONBLOCK
+# define NONBLOCK_FLAG O_NONBLOCK
+#elif defined SYSV
+# define NONBLOCK_FLAG O_NDELAY
+#else
+# define NONBLOCK_FLAG FNDELAY
+#endif
+
+#ifndef INADDR_LOOPBACK
+#define INADDR_LOOPBACK 0x7f000001
+#endif
+
+#ifndef INADDR_NONE
+#define INADDR_NONE 0xffffffff
+#endif
+
+#define IS_DEVICE(mode) (S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) || S_ISFIFO(mode))
+
+/* Initial mask on permissions given to temporary files. Mask off setuid
+ bits and group access because of potential race-condition security
+ holes, and mask other access because mode 707 is bizarre */
+#define INITACCESSPERMS 0700
+
+/* handler for null strings in printf format */
+#define NS(s) ((s)?safe_fname(s):"<NULL>")
+
+#if !defined __GNUC__ || defined __APPLE__
+/* Apparently the OS X port of gcc gags on __attribute__.
+ *
+ * <http://www.opensource.apple.com/bugs/X/gcc/2512150.html> */
+#define __attribute__(x)
+
+#endif
+
+/* Convenient wrappers for malloc and realloc. Use them. */
+#define new(type) ((type *)malloc(sizeof(type)))
+#define new_array(type, num) ((type *)_new_array(sizeof(type), (num)))
+#define realloc_array(ptr, type, num) ((type *)_realloc_array((ptr), sizeof(type), (num)))
+
+/* use magic gcc attributes to catch format errors */
+ void rprintf(enum logcode , const char *, ...)
+ __attribute__((format (printf, 2, 3)))
+;
+
+/* This is just like rprintf, but it also tries to print some
+ * representation of the error code. Normally errcode = errno. */
+void rsyserr(enum logcode, int, const char *, ...)
+ __attribute__((format (printf, 3, 4)))
+ ;
+
+#ifdef REPLACE_INET_NTOA
+#define inet_ntoa rep_inet_ntoa
+#endif
+
+/* Make sure that the O_BINARY flag is defined. */
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+#ifndef HAVE_STRLCPY
+size_t strlcpy(char *d, const char *s, size_t bufsize);
+#endif
+
+#ifndef HAVE_STRLCAT
+size_t strlcat(char *d, const char *s, size_t bufsize);
+#endif
+
+#ifndef WEXITSTATUS
+#define WEXITSTATUS(stat) ((int)(((stat)>>8)&0xFF))
+#endif
+
+#define exit_cleanup(code) _exit_cleanup(code, __FILE__, __LINE__)
+
+#ifdef HAVE_GETEUID
+#define MY_UID() geteuid()
+#else
+#define MY_UID() getuid()
+#endif
+
+#ifdef HAVE_GETEGID
+#define MY_GID() getegid()
+#else
+#define MY_GID() getgid()
+#endif
+
+extern int verbose;
+
+#ifndef HAVE_INET_NTOP
+const char *inet_ntop(int af, const void *src, char *dst, size_t size);
+#endif
+
+#ifndef HAVE_INET_PTON
+int inet_pton(int af, const char *src, void *dst);
+#endif
+
+#ifdef MAINTAINER_MODE
+const char *get_panic_action(void);
+#endif
+
+#define UNUSED(x) x __attribute__((__unused__))