-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform.h
113 lines (97 loc) · 2.39 KB
/
platform.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// platform.h
// FireFly server platform abstraction macros
#ifndef FIREFLY_PLATFORM_H
#define FIREFLY_PLATFORM_H
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN // strip down windows headers
#define _CRT_SECURE_NO_WARNINGS
#pragma warning( disable : 4786 )
#endif
// define this to include crypt() in unistd.h on RedHat 6.2
#define _XOPEN_SOURCE
#ifdef __CYGWIN__
// use cygwin's crypt implementation if available
#include <crypt.h>
#else
#if defined WIN32 || defined __APPLE__
// use a dummy implementation (no encryption)
// #define crypt(str,salt) (str)
// use Eric Young's crypt implementation from libdes-l
// see also related stuff at the top of main.cpp
#define HEADER_DES_LOCL_H // for correct crypt() prototype
#include "libdes-l/des.h"
#endif
#endif
#include <stdlib.h>
#include <stdio.h> // printf
#include <memory.h>
#include <string.h>
#include <time.h>
#include <math.h> // floor
#include <fcntl.h> // fcntl
#include <sys/types.h> // sockets, select
#ifdef WIN32
#include <signal.h> // signal, SIGTERM, SIGPIPE
#else
//#include <bsd/signal.h> // documented but does not exist
#include <signal.h>
#endif
#ifdef WIN32
#define CDECL __cdecl
#else
#define CDECL
#endif
#ifdef WIN32
#include <io.h>
#include <sys/stat.h> // _S_IREAD, _S_IWRITE
#define S_IRUSR _S_IREAD
#define S_IWUSR _S_IWRITE
#else
#include <unistd.h> // read, write, close, fcntl, select
#include <sys/stat.h>
#endif
#ifdef WIN32
#include <winsock.h>
#else
#include <sys/time.h> // timeval
#include <sys/types.h>
#include <sys/socket.h> // AF
#include <netinet/in.h> // INADDR_ANY
#define SOCKET int
#define INVALID_SOCKET -1
#endif
// Silly Win32 does text conversion unless this is used
// So just define as 0 for all other platforms
#ifndef O_BINARY
#define O_BINARY 0
#endif
// Reserved port number for Windows file ports
#define FILE_PORT_FLAG -1
// Required for Bison under Win32
#ifdef WIN32
#include <malloc.h>
#endif
#define MALLOC malloc
#define REALLOC realloc
#define FREE free
#define MEMCPY memcpy
#define MEMMOVE memmove
#define MEMCMP memcmp
#define MEMCLEAR(X,Y) memset((X), 0, (Y))
#define STRLEN strlen
#define STRCMP strcmp
#define STRCPY strcpy
#ifdef WIN32
#define OPEN _open
#define READ _read
#define WRITE _write
#define CLOSE _close
#define UNLINK _unlink
#else
#define OPEN open
#define READ read
#define WRITE write
#define CLOSE close
#define UNLINK unlink
#endif
#endif // FIREFLY_PLATFORM_H