|
|
/*-----------------------------------------------------------------------------
|
|
|
platform_def.h 操作系统相关定义 zl 2002.11.5
|
|
|
|
|
|
本文件定义所有和操作系统平台相关的常量、类型、宏及头文件引用
|
|
|
-----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
|
|
条件编译常量定义约定:
|
|
|
|
|
|
(1) Windows操作系统: OS_WINDOWS
|
|
|
|
|
|
(2) Unix(统称)操作系统: OS_UNIX
|
|
|
(3) Linux操作系统: _OS_UNIX_LINUX_
|
|
|
(4) True64操作系统: _OS_UNIX_TRUR64_
|
|
|
(5) Solaris操作系统: _OS_UNIX_SOLARIS_
|
|
|
|
|
|
(6) 64位操作系统: _OS_64BIT_
|
|
|
|
|
|
(7) Windows字节顺序: _OS_WINDOWS_BYTEORDER_
|
|
|
(8) Solaris字节顺序: _OS_SOLARIS_BYTEORDER_
|
|
|
|
|
|
[说明]:
|
|
|
|
|
|
a. 64位操作系统主要有:DEC True64, solaris(有时可能是32位系统,可以通过测试sizeof
|
|
|
(long)是否=8来判断)
|
|
|
|
|
|
b. windows, linux, true64 等操作系统的字节顺序和solaris相反,因此分别以Windows
|
|
|
和solaris为代表定义不同的字节顺序
|
|
|
|
|
|
c. Unix操作系统种类繁多,每个变种有一定的差别,因此为常见的unix系统每种定义一个
|
|
|
条件编译常量
|
|
|
|
|
|
-----------------------------------------------------------------------------*/
|
|
|
|
|
|
#ifndef PLATFORM_DEF_H
|
|
|
#define PLATFORM_DEF_H
|
|
|
|
|
|
/*------------------------------------ 头文件引用 --------------------------------*/
|
|
|
|
|
|
#ifdef OS_WINDOWS //windows
|
|
|
#include <windows.h>
|
|
|
#include <dos.h>
|
|
|
#include <direct.h>
|
|
|
#include <time.h>
|
|
|
#endif
|
|
|
|
|
|
#ifdef OS_UNIX //unix
|
|
|
#include <sys/types.h>
|
|
|
#include <sys/ipc.h>
|
|
|
#include <sys/sem.h>
|
|
|
#include <sys/msg.h>
|
|
|
#include <sys/shm.h>
|
|
|
#include <sys/time.h>
|
|
|
#include <sys/select.h>
|
|
|
#include <sys/socket.h>
|
|
|
#include <sys/stat.h>
|
|
|
#include <arpa/inet.h> //inet地址族的所有结构和常量定义都在这里
|
|
|
#include <netinet/in.h>
|
|
|
#include <errno.h>
|
|
|
#include <stropts.h>
|
|
|
#include <stddef.h>
|
|
|
#include <stdlib.h>
|
|
|
#include <stdio.h>
|
|
|
#include <unistd.h>
|
|
|
#include <fcntl.h>
|
|
|
#include <signal.h>
|
|
|
#include <pthread.h>
|
|
|
#include <string.h>
|
|
|
// #include <time.h>
|
|
|
#include <netdb.h> //定义bsd socket的gethostbyname()函数
|
|
|
#endif
|
|
|
|
|
|
/*------------------------------------ 名字定义 --------------------------------*/
|
|
|
|
|
|
//全局名字替换名字,为减少移植时大量修改结构及函数名的工作量而设置
|
|
|
|
|
|
#ifdef OS_UNIX
|
|
|
#define SYSTEMTIME QSYSTEMTIME
|
|
|
#define GetLocalTime QGetLocalTime
|
|
|
#define SetLocalTime QSetLocalTime
|
|
|
|
|
|
#define GetPrivateProfileString QGetPrivateProfileString
|
|
|
#define GetPrivateProfileInt QGetPrivateProfileInt
|
|
|
#define WritePrivateProfileString QWritePrivateProfileString
|
|
|
|
|
|
#define closesocket close //winsock中关闭socket用closesocket(),而bsd socket中用close()
|
|
|
#endif
|
|
|
|
|
|
/*-------------------------------- 类型定义 ------------------------------------*/
|
|
|
|
|
|
#ifdef OS_UNIX
|
|
|
|
|
|
typedef unsigned char BYTE;
|
|
|
typedef unsigned char u_char;
|
|
|
typedef unsigned char UCHAR;
|
|
|
|
|
|
typedef unsigned long DWORD;
|
|
|
typedef unsigned short WORD;
|
|
|
typedef unsigned short u_short;
|
|
|
typedef unsigned short USHORT;
|
|
|
|
|
|
typedef int BOOL;
|
|
|
typedef int INT;
|
|
|
|
|
|
typedef unsigned int u_int;
|
|
|
typedef unsigned int UINT;
|
|
|
typedef unsigned int SOCKET; //为编译通过而临时从Winsock.h中提取的类型定义
|
|
|
|
|
|
typedef unsigned long u_long;
|
|
|
typedef unsigned long ULONG;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef _OS_64BIT_
|
|
|
typedef int i_32; //固定长度为4个字节的有符号整数类型
|
|
|
typedef unsigned int u_32; //固定长度为4个字节的无符号整数类型
|
|
|
|
|
|
typedef long _int64; //Vc中64位整数_int64在64位unix下对应long(8个字节), dnp30.cpp中引用
|
|
|
#else
|
|
|
typedef long i_32;
|
|
|
typedef unsigned long u_32;
|
|
|
|
|
|
#ifdef OS_UNIX
|
|
|
typedef int64_t _int64; //Vc中64位整数_int64在32位unix下对应int64_t,在sys/types.h中定义
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
#ifdef OS_UNIX
|
|
|
typedef u_32 DWORD; //DWORD为固定长度4个字节的无符号整数
|
|
|
#endif
|
|
|
|
|
|
/*----------------------------------- 常数定义 ----------------------------------*/
|
|
|
|
|
|
#ifdef OS_UNIX
|
|
|
#define TRUE 1
|
|
|
#define FALSE 0
|
|
|
#define NULL 0
|
|
|
|
|
|
#define INVALID_SOCKET (SOCKET)(~0) //为编译通过而临时从Winsock.h中提取的类型定义
|
|
|
#define SOCKET_ERROR (-1)
|
|
|
#define INADDR_NONE 0xffffffff
|
|
|
#endif
|
|
|
|
|
|
/*------------------------------------ 宏定义 -----------------------------------*/
|
|
|
|
|
|
#ifdef OS_UNIX
|
|
|
#define MAKEWORD(a, b) ((WORD)(((BYTE)(a)) | ((WORD)((BYTE)(b))) << 8))
|
|
|
#define MAKELONG(a, b) ((LONG)(((WORD)(a)) | ((DWORD)((WORD)(b))) << 16))
|
|
|
#define LOWORD(l) ((WORD)(l))
|
|
|
#define HIWORD(l) ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
|
|
|
#define LOBYTE(w) ((BYTE)(w))
|
|
|
#define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))
|
|
|
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
|
|
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
|
|
#endif
|
|
|
|
|
|
/*-------------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
#endif //PLATFORM_DEF_H
|