]> git.pond.sub.org Git - empserver/blob - include/misc.h
(main): Don't use access() before mkdir() to check whether the
[empserver] / include / misc.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  misc.h: Misc. definitions which don't really belong anywhere,
29  *          but have to go somewhere!
30  * 
31  *  Known contributors to this file:
32  *       Doug Hay, 1998
33  */
34
35 #ifndef MISC_H
36 #define MISC_H
37
38 #include <ctype.h>
39 #include <string.h>
40 #include <sys/types.h>
41
42 #define MAX(a,b) ((a) > (b) ? (a) : (b))
43 #define MIN(a,b) ((a) < (b) ? (a) : (b))
44
45 #if defined(_WIN32)
46 typedef unsigned char u_char;
47 typedef unsigned short u_short;
48 typedef unsigned int u_int;
49 typedef long ssize_t;
50
51 /* integral mismatch, due to misuse of sector short */
52 #ifndef __GNUC__
53 #pragma warning (disable : 4761 )
54 #endif
55
56 #include <io.h>
57
58 #define random rand
59 #define srandom srand
60
61 #define strncasecmp(s1, s2, s3) _strnicmp(s1, s2, s3)
62 #define mkdir(dir,perm) _mkdir((dir))
63
64 typedef int pid_t;
65 #define vsnprintf _vsnprintf
66
67 #endif /* _WIN32 */
68
69 /* This is the structure we use to keep track of the global mobility
70    things, such as when the server is supposed to start/stop updating
71    mobility and the timestamp of when the game was last up.  These
72    times are in seconds. */
73 struct mob_acc_globals {
74     time_t timestamp;           /* Last timestamp of when the game was up */
75     time_t starttime;           /* When we should start updating mobility again. */
76 };
77
78 #ifdef __GNUC__
79 #define ATTRIBUTE(attrs) __attribute__ (attrs)
80 #else
81 #define ATTRIBUTE(attrs)
82 #endif
83
84 /* This uses a lot of thread stack with some versions of GNU libc,
85    which can lead to nasty heap smashes (observed with 2.2.93).
86    Disabled for now, until we readjust thread stack sizes.  */
87 #if 0
88 #define RESOLVE_IPADDRESS       /* resolve ip addresses into hostnames */
89 #endif
90
91 typedef u_char natid;           /* NSC_NATID must match this */
92
93 /*
94  * TODO s_char has to go.  Use plain char for characters and strings,
95  * signed char for small integers.
96  */
97 #ifdef __CHAR_UNSIGNED__
98 typedef signed char s_char;
99 #else
100 typedef char s_char;
101 #endif
102
103 typedef short coord;
104
105 #ifndef bit
106 #define bit(x)          (1<<(x))
107 #endif
108
109 #define minutes(x)      (60*(x))
110 #define hours(x)        (60*60*(x))
111 #define days(x)         (60*60*24*(x))
112
113 extern int debug;
114 extern int daemonize;
115
116 /*
117  * If EXPR is true, an internal error occured.
118  * Return EXPR != 0.
119  * Usage: if (CANT_HAPPEN(...)) recovery_code();
120  */
121 #define CANT_HAPPEN(expr) ((expr) ? oops(#expr, __FILE__, __LINE__) : 0)
122 extern int oops(char *, char *, int);
123
124         /* return codes from command routines */
125 #define RET_OK          0       /* command completed sucessfully */
126 #define RET_FAIL        1       /* command completed unsucessfully [?] */
127 #define RET_SYN         2       /* syntax error in command */
128 #define RET_SYS         3       /* system error (missing file, etc) */
129
130 extern char *getstarg(char *input, char *prompt, char buf[]);
131 extern char *getstring(char *prompt, char buf[]);
132 extern char *ugetstring(char *prompt, char buf[]);
133              
134 extern char *prbuf(char *format, ...)
135     ATTRIBUTE((format (printf, 1, 2)));
136
137 #define AGREE_FREE      0
138 #define AGREE_PROPOSED  1
139 #define AGREE_SIGNED    2
140
141 #endif