// Copyright 1997-1998 Omni Development, Inc.  All rights reserved.
//
// $Header: /LocalDeveloper/Source/CVS/OmniGroup/OmniBase/system.h,v 1.10 1998/01/12 06:53:13 kc Exp $
//
// This file contains stuff that isn't necessarily portable between operating systems.

#if defined(sun)

//
// Solaris (PDO or OpenStep)
//

#import <sys/types.h>
#import <sys/errno.h>
#import <unistd.h>
#import <alloca.h>
#import <stdlib.h>

#import <sys/socket.h>
#import <netinet/in.h>
#import <arpa/inet.h>
#import <arpa/nameser.h>
#import <netdb.h>
#import <resolv.h>

#import <dirent.h>
#import <sys/stat.h>

#import <string.h>
#import <ctype.h>
#import <values.h>  // for MAXINT, MAXDOUBLE, etc

#import <sys/uio.h>
#import <sys/file.h>
#import <fcntl.h>

#import <objc/Protocol.h>

#ifdef __cplusplus
extern "C" {
#endif
extern int res_init(void);
extern int gethostname(char *name, int namelen);
#ifdef __cplusplus
}
#endif

#import <math.h>

// These are defined in a really funky place in Solaris.
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif

#elif defined(WINNT)

//
// Windows NT (OpenStep)
//

#import <ansi/ansi.h>
#import <winnt-pdo.h>
#import <winsock.h>
#import <fcntl.h>
#import <malloc.h>

// Sockets
#define OBSocketRead(socketFD, buffer, byteCount) recv(socketFD, buffer, byteCount, 0)
#define OBSocketWrite(socketFD, buffer, byteCount) send(socketFD, buffer, byteCount, 0)
#define OBSocketClose(socketFD) closesocket(socketFD)

// WinSock has these defined, but puts an #if 0 around them.
#define ETIMEDOUT    WSAETIMEDOUT
#define ECONNREFUSED WSAECONNREFUSED
#define ENETDOWN     WSAENETDOWN
#define ENETUNREACH  WSAENETUNREACH
#define EHOSTDOWN    WSAEHOSTDOWN
#define EHOSTUNREACH WSAEHOSTUNREACH

// Don't find these anywhere in NT.
#define MAXHOSTNAMELEN (256)
#define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
#define IN_MULTICAST(i) IN_CLASSD(i)

// Misc

#define random() rand()
#define srandom(seed) srand(seed)

#undef alloca

#elif NeXT

//
// NeXT-derived platform, e.g. OPENSTEP/Mach or Rhapsody
//

#if (NS_TARGET_MAJOR > 4) || ((NS_TARGET_MAJOR == 4) && (NS_TARGET_MINOR > 1))
#ifndef RHAPSODY
#define RHAPSODY
#endif
    // This define is intended to allow one to distinguish between Rhapsody and OPENSTEP for the purposes of conditional code, since Apple has not yet provided an equivalent.
#endif
#ifdef RHAPSODY
    // This will need to change in the future, since Rhapsody can also run on Intel.  If Apple doesn't provide a proper PLATFORM_OS definition, we can use OmniMake goop.

//
// Rhapsody
//

#import <bsd/libc.h>
#import <bsd/stddef.h>
#import <bsd/arpa/nameser.h>
#import <bsd/resolv.h>
#import <bsd/netdb.h>
#import <bsd/sys/types.h>
#import <bsd/sys/dir.h>
#import <bsd/sys/errno.h>
#import <bsd/sys/stat.h>
#import <bsd/sys/uio.h>
#import <bsd/sys/file.h>
#import <bsd/fcntl.h>
#import <bsd/c.h> // For MIN()

#else

//
// OPENSTEP/Mach
//

#import <ansi/ansi.h>
#import <bsd/libc.h>
#import <bsd/arpa/nameser.h>
#import <bsd/resolv.h>
#import <bsd/netdb.h>
#import <bsd/sys/types.h>
#import <bsd/sys/dir.h>
#import <bsd/sys/errno.h>
#import <bsd/sys/stat.h>
#import <bsd/sys/uio.h>
#import <bsd/sys/file.h>
#import <bsd/fcntl.h>
#import <bsd/c.h> // For MIN()

#import <mach/mach_error.h>

#import <objc/Protocol.h>

#endif

#else

//
// Unknown system
//

#error Unknown system!

#endif

// Default to using BSD socket API.

#ifndef OBSocketRead
#define OBSocketRead(socketFD, buffer, byteCount) read(socketFD, buffer, byteCount)
#endif
#ifndef OBSocketWrite
#define OBSocketWrite(socketFD, buffer, byteCount) write(socketFD, buffer, byteCount)
#endif
#ifndef OBSocketClose
#define OBSocketClose(socketFD) close(socketFD)
#endif
