]> git.pond.sub.org Git - empserver/blob - include/misc.h
4384a8183b51144a19abc4152fd107a5e686013a
[empserver] / include / misc.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2007, 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 #define MAX(a,b) ((a) > (b) ? (a) : (b))
39 #define MIN(a,b) ((a) < (b) ? (a) : (b))
40
41 #ifdef _WIN32
42 #ifndef __GNUC__
43
44 typedef long ssize_t;
45
46 /* integral mismatch, due to misuse of sector short */
47 #pragma warning (disable : 4761 )
48
49 #define strncasecmp(s1, s2, s3) _strnicmp((s1), (s2), (s3))
50
51 typedef int pid_t;
52 #define vsnprintf _vsnprintf
53 #define snprintf _snprintf
54
55 #endif /* !__GNUC__ */
56
57 #define mkdir(dir,perm) _mkdir((dir))
58 #define random rand
59 #define srandom srand
60 #ifndef S_IRUSR
61 #define S_IRUSR     _S_IREAD
62 #define S_IWUSR     _S_IWRITE
63 #define S_IXUSR     _S_IEXEC
64 #define S_IRWXU     S_IRUSR | S_IWUSR | S_IXUSR
65 #endif
66 #ifndef S_IRGRP
67 #define S_IRGRP     0
68 #define S_IWGRP     0
69 #define S_IXGRP     0
70 #define S_IRWXG     S_IRGRP | S_IWGRP | S_IXGRP
71 #endif
72 #ifndef S_IROTH
73 #define S_IROTH     0
74 #define S_IWOTH     0
75 #define S_IXOTH     0
76 #define S_IRWXO     S_IROTH | S_IWOTH | S_IXOTH
77 #endif
78 #endif /* _WIN32 */
79
80 #ifndef S_IRWUG
81 #define S_IRWUG     S_IRGRP | S_IWGRP | S_IRUSR | S_IWUSR
82 #endif
83
84 #ifdef __GNUC__
85 #define ATTRIBUTE(attrs) __attribute__ (attrs)
86 #else
87 #define ATTRIBUTE(attrs)
88 #endif
89
90 /*
91  * This uses a lot of thread stack with some versions of GNU libc,
92  * which can lead to nasty heap smashes (observed with 2.2.93).
93  * Disabled for now, until we readjust thread stack sizes.
94  */
95 #if 0
96 #define RESOLVE_IPADDRESS       /* resolve ip addresses into hostnames */
97 #endif
98
99 #ifndef bit
100 #define bit(x)          (1<<(x))
101 #endif
102
103 #define minutes(x)      (60*(x))
104 #define hours(x)        (60*60*(x))
105 #define days(x)         (60*60*24*(x))
106
107 extern int debug;
108
109 /*
110  * If EXPR is true, an internal error occured.
111  * Return EXPR != 0.
112  * Usage: if (CANT_HAPPEN(...)) <recovery code>;
113  */
114 #define CANT_HAPPEN(expr) ((expr) ? oops(#expr, __FILE__, __LINE__) : 0)
115
116 /*
117  * Report internal error.
118  * Usage: CANT_REACH(); <recovery code>;
119  */
120 #define CANT_REACH() (void)oops(NULL, __FILE__, __LINE__)
121
122 extern int oops(char *, char *, int);
123
124 void exit_nomem(void) ATTRIBUTE((noreturn));
125
126         /* return codes from command routines */
127 #define RET_OK          0       /* command completed sucessfully */
128 #define RET_FAIL        1       /* command completed unsucessfully [?] */
129 #define RET_SYN         2       /* syntax error in command */
130 #define RET_SYS         3       /* system error (missing file, etc) */
131
132 extern char *getstarg(char *input, char *prompt, char buf[]);
133 extern char *getstring(char *prompt, char buf[]);
134 extern char *ugetstring(char *prompt, char buf[]);
135              
136 extern char *prbuf(char *format, ...)
137     ATTRIBUTE((format (printf, 1, 2)));
138
139 #define AGREE_FREE      0
140 #define AGREE_PROPOSED  1
141 #define AGREE_SIGNED    2
142
143 #endif