Crossfire Server, Trunk  R20513
win32.h
Go to the documentation of this file.
1 #ifndef WIN32_H
2 #define WIN32_H
3 
12 #if !defined(AFX_STDAFX_H__31666CA1_2474_11D5_AE6C_F07569C10000__INCLUDED_)
13 #define AFX_STDAFX_H__31666CA1_2474_11D5_AE6C_F07569C10000__INCLUDED_
14 
15 /* Define the version here. In Unixland, it's defined on the command line now. */
16 #define VERSION "1.9.1 (trunk) snapshot 20061229"
17 
18 #pragma warning(disable: 4761) /* integral size mismatch in argument; conversion supplied */
19 
20 #if _MSC_VER > 1000
21 #pragma once
22 #endif /* _MSC_VER > 1000 */
23 
24 #endif /* !defined(AFX_STDAFX_H__31666CA1_2474_11D5_AE6C_F07569C10000__INCLUDED_) */
25 
26 #define WIN32_LEAN_AND_MEAN
27 #include <windows.h>
28 #include <windowsx.h>
29 #include <mmsystem.h>
30 #include <winsock2.h>
31 #include <time.h>
32 #include <direct.h>
33 #include <math.h>
34 
35 #include <sys/stat.h> /* somewhat odd, but you don't get stat here with __STDC__ */
36 
37 #include <io.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <sys/types.h>
41 #include <process.h>
42 
43 #define __STDC__ 1 /* something odd, CF want this, but don'T include it */
44  /* before the standard includes */
45 
46 #define snprintf _snprintf
47 
48 /* include all needed autoconfig.h defines */
49 #define CS_LOGSTATS
50 #define MAXPATHLEN 256
51 #define HAVE_STRTOL
52 #define HAVE_STRERROR
53 
54 /* Many defines to redirect unix functions or fake standard unix values */
55 #define inline __inline
56 #define unlink(__a) _unlink(__a)
57 #define mkdir(__a, __b) mkdir(__a)
58 #define getpid() _getpid()
59 #define popen(__a, __b) _popen(__a, __b)
60 #define pclose(__a) _pclose(__a)
61 #define vsnprintf _vsnprintf
62 #define strtok_r(x, y, z) strtok(x, y)
63 
64 #define R_OK 6 /* for __access() */
65 #define F_OK 6
66 
67 #define PREFIXDIR ""
68 
69 #define S_ISDIR(x) (((x)&S_IFMT) == S_IFDIR)
70 #define S_ISREG(x) (((x)&S_IFMT) == S_IFREG)
71 
72 #ifndef S_ISGID
73 #define S_ISGID 0002000
74 #endif
75 #ifndef S_IWOTH
76 #define S_IWOTH 0000200
77 #endif
78 #ifndef S_IWGRP
79 #define S_IWGRP 0000020
80 #endif
81 #ifndef S_IWUSR
82 #define S_IWUSR 0000002
83 #endif
84 #ifndef S_IROTH
85 #define S_IROTH 0000400
86 #endif
87 #ifndef S_IRGRP
88 #define S_IRGRP 0000040
89 #endif
90 #ifndef S_IRUSR
91 #define S_IRUSR 0000004
92 #endif
93 
94 #define WIFEXITED(x) 1
95 #define WEXITSTATUS(x) x
96 
97 /* Location of read-only machine independent data */
98 #define DATADIR "share"
99 #define LIBDIR "share"
100 #define CONFDIR "share"
101 
102 /* Location of changeable single system data (temp maps, hiscore, etc) */
103 #define LOCALDIR "var"
104 
105 /* Suffix for libraries */
106 #define PLUGIN_SUFFIX ".dll"
107 
108 /* struct dirent - same as Unix */
109 
110 typedef struct dirent {
111  long d_ino; /* inode (always 1 in WIN32) */
112  off_t d_off; /* offset to this dirent */
113  unsigned short d_reclen; /* length of d_name */
114  char d_name[_MAX_FNAME+1]; /* filename (null terminated) */
115 }dirent;
116 
117 #define NAMLEN(dirent) strlen((dirent)->d_name)
118 
119 /* typedef DIR - not the same as Unix */
120 typedef struct {
121  long handle; /* _findfirst/_findnext handle */
122  short offset; /* offset into directory */
123  short finished; /* 1 if there are not more files */
124  struct _finddata_t fileinfo; /* from _findfirst/_findnext */
125  char *dir; /* the dir we are reading */
126  struct dirent dent; /* the dirent to return */
127 } DIR;
128 
129 #ifndef socklen_t
130 #define socklen_t int /* Doesn't exist, just a plain int */
131 #endif
132 
133 /* Function prototypes */
134 extern DIR *opendir(const char *);
135 extern struct dirent *readdir(DIR *);
136 extern int closedir(DIR *);
137 extern void rewinddir(DIR *);
138 extern int strncasecmp(const char *s1, const char *s2, int n);
139 extern int strcasecmp(const char *s1, const char *s2);
140 extern void service_register();
141 extern void service_unregister();
142 extern void service_handle();
143 
144 #define HAVE_LIBCURL
145 
146 /* For Win32 service */
147 extern int bRunning;
148 
149 /* Win32's Sleep takes milliseconds, not seconds. */
150 #define sleep(x) Sleep(x*1000)
151 
158 typedef signed char int8_t;
159 typedef signed int int32_t;
160 typedef signed short int16_t;
161 typedef unsigned char uint8_t;
162 typedef unsigned int uint32_t;
163 typedef unsigned short uint16_t;
164 
165 /* Python plugin stuff defines SIZEOF_LONG_LONG as 8, and besides __int64 is a 64b type on MSVC...
166  * So let's force the typedef */
167 typedef unsigned __int64 uint64_t;
168 typedef signed __int64 int64_t;
169 /* Needed for experience */
170 #define atoll _atoi64
171 
172 #define FMT64 "I64d"
173 #define FMT64U "I64u"
174 
175 /* To reduce number of warnings */
176 #pragma warning(disable: 4244) /* conversion from 'xxx' to 'yyy', possible loss of data */
177 #pragma warning(disable: 4305) /* initializing float f = 0.05; instead of f = 0.05f; */
178 
179 #endif /* WIN32_H */
unsigned char uint8_t
Definition: win32.h:161
unsigned short d_reclen
Definition: win32.h:113
short finished
Definition: win32.h:123
char * dir
Definition: win32.h:125
DIR * opendir(const char *)
Opens a directory for reading.
Definition: win32.c:37
long handle
Definition: win32.h:121
Definition: win32.h:110
short offset
Definition: win32.h:122
Definition: win32.h:120
signed short int16_t
Definition: win32.h:160
void service_unregister()
Removes the Crossfire service from the service manager.
Definition: win32.c:225
int strcasecmp(const char *s1, const char *s2)
Case-insensitive comparaison of strings.
Definition: porting.c:256
long d_ino
Definition: win32.h:111
void rewinddir(DIR *)
Restart a directory listing from the beginning.
Definition: win32.c:124
int bRunning
Will be set to FALSE when the server should stop running because the service is turned off...
Definition: win32.c:159
char d_name[_MAX_FNAME+1]
Definition: win32.h:114
unsigned __int64 uint64_t
Definition: win32.h:167
int strncasecmp(const char *s1, const char *s2, int n)
Case-insensitive comparaison of strings.
Definition: porting.c:224
unsigned short uint16_t
Definition: win32.h:163
signed __int64 int64_t
Definition: win32.h:168
unsigned int uint32_t
Definition: win32.h:162
signed char int8_t
Type definitions for fixed-size integer types.
Definition: win32.h:158
struct dirent dirent
void service_handle()
Service entry point.
Definition: win32.c:343
struct dirent * readdir(DIR *)
Returns the next file/directory for specified directory handle, obtained through a call to opendir()...
Definition: win32.c:75
signed int int32_t
Definition: win32.h:159
void service_register()
Registers the server to the service manager.
Definition: win32.c:180
int closedir(DIR *)
Dispose of a directory handle.
Definition: win32.c:108
off_t d_off
Definition: win32.h:112