/* Copyright (c) 2001, 2004 Alex Leigh, All Rights Reserved      
 *
 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ALEX LEIGH
 * The copyright notice above does not evidence any
 * actual or intended publication of such source code.
 *
 * Use, disclosure, copying, distribution, or transmission of
 * this code without express permission is prohibited.
 */

#ifndef CSYS_H
#define CSYS_H

#ifdef __cplusplus
extern "C" {
#endif

#ifdef WIN32
#include "cwin32.h"
#else

/* It is important that this comes first, because on Solaris
   it's required to make 64-bit work properly. */
#include <stdlib.h>

#include "config.h"

/* If we don't have pthread_rwlock_init() then we probably don't have
 * pthread_rwlock() support. This is true on old OSX systems that we 
 * basically don't support, but also Solaris 2.6; rwlocks weren't implemented
 * until Solaris 7 
 */

#ifndef HAVE_PTHREAD_RWLOCK_INIT
#define pthread_rwlock_t pthread_mutex_t
#define PTHREAD_RWLOCK_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#define pthread_rwlock_init pthread_mutex_init
#define pthread_rwlock_rdlock pthread_mutex_lock
#define pthread_rwlock_wrlock pthread_mutex_lock
#define pthread_rwlock_unlock pthread_mutex_unlock
#define pthread_rwlock_destory pthread_mutex_destroy
#endif

#include <stdio.h>
#include <unistd.h>
#include <math.h>

/* Colliding namespace on OSX with Tcl */
#include <sys/mman.h>

#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>
#include <assert.h>
#include <signal.h>
#include <pwd.h>

#ifdef HAVE_SYS_LOCK_H
#include <sys/lock.h>
#endif

#include <ctype.h>

#ifdef HAVE_STRING_H
#include <string.h>
#endif

#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif

#include <fcntl.h>
#include <errno.h>
#include <limits.h>
#include <stdarg.h>

#ifdef HAVE_STDINT_H
#ifndef __USE_MISC
#define __USE_MISC
#endif
#include <stdint.h> /* LINUX */
#endif

#ifdef LINUX
#include <netinet/tcp.h> /* TCP_NODELAY */
#include <sys/poll.h>

/* There is something wonky with this on my platform;
   it's not included in unistd.h unless __USE_BSD or something
   bizarre is defined, so I am just putting it here to get the
   compiler to shut up. */
extern int gethostname (char *__name, size_t __len);

#endif

#ifdef FREEBSD
#include <netinet/tcp.h>
#endif

#include <netdb.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#include <assert.h>

#ifdef SOLARIS
#include <arpa/nameser.h> // Required on 2.6 for MAXDNAME
#include <resolv.h>
#include <sys/xti_inet.h>
#include <sys/uio.h>
#endif

#ifdef DARWIN
#include <sys/uio.h>
#endif

#if defined(SOLARIS)
#define _Bool char
#define bool _Bool
#define true 1
#define false 0
#define __bool_true_false_are_defined 1
#endif

#if defined(LINUX) || defined(DARWIN)
#include <stdbool.h>
#endif


#endif /* WIN32 */

#ifdef __cplusplus
};
#endif

#endif
