You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
5.1 KiB
C

2 years ago
/*-----------------------------------------------------------------------------
platform_def.h zl 2002.11.5
2 years ago
2 years ago
-----------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------
2 years ago
(1) Windows: OS_WINDOWS
2 years ago
(2) Unix(): OS_UNIX
(3) Linux: _OS_UNIX_LINUX_
(4) True64: _OS_UNIX_TRUR64_
(5) Solaris: _OS_UNIX_SOLARIS_
2 years ago
(6) 64: _OS_64BIT_
2 years ago
(7) Windows: _OS_WINDOWS_BYTEORDER_
(8) Solaris: _OS_SOLARIS_BYTEORDER_
2 years ago
[]
2 years ago
a. 64DEC True64, solaris(32,sizeof
(long)=8)
2 years ago
b. windows, linux, true64 solaris,Windows
solaris
2 years ago
c. Unixunix
2 years ago
-----------------------------------------------------------------------------*/
#ifndef PLATFORM_DEF_H
#define PLATFORM_DEF_H
/*------------------------------------ 头文件引用 --------------------------------*/
2 years ago
#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地址族的所有结构和常量定义都在这里
2 years ago
#include <netinet/in.h>
#include <errno.h>
// #include <stropts.h>
2 years ago
#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()函数
2 years ago
#endif
/*------------------------------------ 名字定义 --------------------------------*/
2 years ago
//全局名字替换名字,为减少移植时大量修改结构及函数名的工作量而设置
2 years ago
#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()
#define _strdup strdup
#define lstrcpyn strncpy
#define _getcwd getcwd
2 years ago
#endif
/*-------------------------------- 类型定义 ------------------------------------*/
2 years ago
#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中提取的类型定义
2 years ago
typedef unsigned long u_long;
typedef unsigned long ULONG;
#endif
#ifdef _OS_64BIT_
typedef int i_32; //固定长度为4个字节的有符号整数类型
typedef unsigned int u_32; //固定长度为4个字节的无符号整数类型
2 years ago
typedef long _int64; //Vc中64位整数_int64在64位unix下对应long(8个字节), dnp30.cpp中引用
2 years ago
#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中定义
2 years ago
#endif
#endif
#ifdef OS_UNIX
typedef u_32 DWORD; //DWORD为固定长度4个字节的无符号整数
2 years ago
#endif
/*----------------------------------- 常数定义 ----------------------------------*/
2 years ago
#ifdef OS_UNIX
#define TRUE 1
#define FALSE 0
#define NULL 0
#define INVALID_SOCKET (SOCKET)(~0) //为编译通过而临时从Winsock.h中提取的类型定义
2 years ago
#define SOCKET_ERROR (-1)
#define INADDR_NONE 0xffffffff
#endif
/*------------------------------------ 宏定义 -----------------------------------*/
2 years ago
#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