#include <sys/types.h>
#include <sys/stat.h>
#ifdef STAT_MACROS_BROKEN
#undef S_ISBLK
#undef S_ISCHR
#undef S_ISDIR
#undef S_ISREG
#undef S_ISFIFO
#undef S_ISLNK
#undef S_ISSOCK
#undef S_ISMPB
#undef S_ISMPC
#undef S_ISNWK
#endif
#if !defined(S_ISBLK) && defined(S_IFBLK)
# if defined(S_IFMT)
# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
# else
# define S_ISBLK(m) ((m) & S_IFBLK)
# endif
#endif
#if !defined(S_ISCHR) && defined(S_IFCHR)
# if defined(S_IFMT)
# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
# else
# define S_ISCHR(m) ((m) & S_IFCHR)
# endif
#endif
#if !defined(S_ISDIR) && defined(S_IFDIR)
# if defined(S_IFMT)
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
# else
# define S_ISDIR(m) ((m) & S_IFDIR)
# endif
#endif
#if !defined(S_ISREG) && defined(S_IFREG)
# if defined(S_IFMT)
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
# else
# define S_ISREG(m) ((m) & S_IFREG)
# endif
#endif
#if !defined(S_ISFIFO) && defined(S_IFIFO)
# if defined(S_IFMT)
# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
# else
# define S_ISFIFO(m) ((m) & S_IFIFO)
# endif
#endif
#if !defined(S_ISLNK) && defined(S_IFLNK)
# if defined(S_IFMT)
# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
# else
# define S_ISLNK(m) ((m) & S_IFLNK)
# endif
#endif
#if !defined(S_ISSOCK) && defined(S_IFSOCK)
# if defined(S_IFMT)
# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
# else
# define S_ISSOCK(m) ((m) & S_IFSOCK)
# endif
#endif
#if !defined(S_ISMPB) && defined(S_IFMPB)
# if defined(S_IFMT)
# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
# else
# define S_ISMPB(m) ((m) & S_IFMPB)
# define S_ISMPC(m) ((m) & S_IFMPC)
# endif
#endif
#if !defined(S_ISNWK) && defined(S_IFNWK)
# if defined(S_IFMT)
# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
# else
# define S_ISNWK(m) ((m) & S_IFNWK)
# endif
#endif
#ifdef NEED_DECOY_PERMISSIONS
#define S_IRUSR S_IREAD
#define S_IWUSR S_IWRITE
#define S_IXUSR S_IEXEC
#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
#define S_IRGRP S_IREAD
#define S_IWGRP S_IWRITE
#define S_IXGRP S_IEXEC
#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
#define S_IROTH S_IREAD
#define S_IWOTH S_IWRITE
#define S_IXOTH S_IEXEC
#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
#else
#ifndef S_IRUSR
#define S_IRUSR 0400
#define S_IWUSR 0200
#define S_IXUSR 0100
#define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR)
#define S_IRGRP (S_IRUSR >> 3)
#define S_IWGRP (S_IWUSR >> 3)
#define S_IXGRP (S_IXUSR >> 3)
#define S_IRWXG (S_IRWXU >> 3)
#define S_IROTH (S_IRGRP >> 3)
#define S_IWOTH (S_IWGRP >> 3)
#define S_IXOTH (S_IXGRP >> 3)
#define S_IRWXO (S_IRWXG >> 3)
#endif
#endif
#if defined(POSIX) || defined(HAVE_UNISTD_H)
#include <unistd.h>
#include <limits.h>
#else
off_t lseek ();
char *getcwd ();
#endif
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif
#ifdef HAVE_IO_H
#include <io.h>
#endif
#ifdef HAVE_DIRECT_H
#include <direct.h>
#endif
#ifdef timezone
#undef timezone
#endif
#ifdef HAVE_SYS_TIMEB_H
#include <sys/timeb.h>
#else
struct timeb {
time_t time;
unsigned short millitm;
short timezone;
short dstflag;
};
#endif
#if !defined(HAVE_FTIME) && !defined(HAVE_TIMEZONE)
#if !defined(timezone)
extern long timezone;
#endif
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifndef PATH_MAX
# ifdef MAXPATHLEN
# define PATH_MAX MAXPATHLEN
# else
# include <limits.h>
# ifndef PATH_MAX
# ifdef PATHSIZE
# define PATH_MAX PATHSIZE
# else
# ifdef _POSIX_PATH_MAX
# define PATH_MAX _POSIX_PATH_MAX
# else
# define PATH_MAX 1024
# endif
# endif
# endif
# endif
#endif
#if defined (HAVE_UTIME_H) && !defined (NeXT)
# include <utime.h>
#else
# if defined (HAVE_SYS_UTIME_H)
# include <sys/utime.h>
# else
# ifndef ALTOS
struct utimbuf
{
long actime;
long modtime;
};
# endif
int utime ();
# endif
#endif
#include <string.h>
#ifndef ERRNO_H_MISSING
#include <errno.h>
#endif
#ifdef ENOTEXIST
# ifdef EOS2ERR
# define existence_error(x) \
(((x) == ENOTEXIST) || ((x) == ENOENT) || ((x) == EOS2ERR))
# else
# define existence_error(x) \
(((x) == ENOTEXIST) || ((x) == ENOENT))
# endif
#else
# ifdef EVMSERR
# define existence_error(x) \
((x) == ENOENT || (x) == EINVAL || (x) == EVMSERR)
# else
# define existence_error(x) ((x) == ENOENT)
# endif
#endif
#ifdef STDC_HEADERS
#include <stdlib.h>
#else
char *getenv ();
char *malloc ();
char *realloc ();
char *calloc ();
extern int errno;
#endif
#ifndef EXIT_FAILURE
#define EXIT_FAILURE 1
#endif
#if defined(HAVE_SIGACTION) && defined(HAVE_SIGPROCMASK)
# define POSIX_SIGNALS
#endif
#if defined(_MINIX)
# undef POSIX_SIGNALS
#endif
#if !defined(POSIX_SIGNALS)
# if defined(HAVE_SIGVEC) && defined(HAVE_SIGSETMASK) && defined(HAVE_SIGBLOCK)
# define BSD_SIGNALS
# endif
#endif
#ifdef USE_OWN_TCPIP_H
#include "tcpip.h"
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#else
#include <sys/file.h>
#endif
#ifndef SEEK_SET
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
#endif
#ifndef F_OK
#define F_OK 0
#define X_OK 1
#define W_OK 2
#define R_OK 4
#endif
#if HAVE_DIRENT_H
# include <dirent.h>
# define NAMLEN(dirent) strlen((dirent)->d_name)
#else
# define dirent direct
# define NAMLEN(dirent) (dirent)->d_namlen
# if HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif
# if HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif
# if HAVE_NDIR_H
# include <ndir.h>
# endif
#endif
#define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b))
#ifndef S_ISLNK
#define lstat stat
#endif
#ifndef S_IWRITE
#define S_IWRITE 0000200
#endif
#ifndef S_IWGRP
#define S_IWGRP 0000020
#endif
#ifndef S_IWOTH
#define S_IWOTH 0000002
#endif
#ifndef CVS_ACCESS
#define CVS_ACCESS access
#endif
#ifndef CVS_CHDIR
#define CVS_CHDIR chdir
#endif
#ifndef CVS_CREAT
#define CVS_CREAT creat
#endif
#ifndef CVS_FOPEN
#define CVS_FOPEN fopen
#endif
#ifndef CVS_MKDIR
#define CVS_MKDIR mkdir
#endif
#ifndef CVS_OPEN
#define CVS_OPEN open
#endif
#ifndef CVS_OPENDIR
#define CVS_OPENDIR opendir
#endif
#ifndef CVS_RENAME
#define CVS_RENAME rename
#endif
#ifndef CVS_RMDIR
#define CVS_RMDIR rmdir
#endif
#ifndef CVS_STAT
#define CVS_STAT stat
#endif
#ifndef CVS_LSTAT
#define CVS_LSTAT lstat
#endif
#ifndef CVS_UNLINK
#define CVS_UNLINK unlink
#endif
#ifndef CVS_FNMATCH
#define CVS_FNMATCH fnmatch
#endif
#if defined (__CYGWIN32__) || defined (WIN32)
#define FOLD_FN_CHAR(c) (WNT_filename_classes[(unsigned char) (c)])
extern unsigned char WNT_filename_classes[];
#define FILENAMES_CASE_INSENSITIVE 1
#define ISDIRSEP(c) (FOLD_FN_CHAR(c) == '/')
extern int fncmp (const char *n1, const char *n2);
extern void fnfold (char *FILENAME);
#endif
#ifndef FOLD_FN_CHAR
#define FOLD_FN_CHAR(c) (c)
#define fnfold(filename) (filename)
#define fncmp strcmp
#endif
#ifndef ISDIRSEP
#define ISDIRSEP(c) ((c) == '/')
#endif
#define FOPEN_BINARY_READ ("rb")
#define FOPEN_BINARY_WRITE ("wb")
#ifdef O_BINARY
#define OPEN_BINARY (O_BINARY)
#else
#define OPEN_BINARY (0)
#endif