root/cherokee/trunk/cherokee/common-internal.h

Revision 2523, 5.0 kB (checked in by alo, 2 days ago)

--

Line 
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Cherokee
4  *
5  * Authors:
6  *      Alvaro Lopez Ortega <alvaro@alobbs.com>
7  *
8  * Copyright (C) 2001-2008 Alvaro Lopez Ortega
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of version 2 of the GNU General Public
12  * License as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22  * USA
23  */
24
25 #ifndef CHEROKEE_COMMON_INTERNAL_H
26 #define CHEROKEE_COMMON_INTERNAL_H
27
28 #include <config.h>
29 #include <constants.h>
30
31 #ifdef _WIN32
32 # include "unix4win32.h"
33 # include "win32_misc.h"
34 #endif
35
36 #include "common.h"
37
38 #ifndef _WIN32
39 # if defined HAVE_ENDIAN_H
40 #  include <endian.h>
41 # elif defined HAVE_MACHINE_ENDIAN_H
42 #  include <machine/endian.h>
43 # elif defined HAVE_SYS_ENDIAN_H
44 #  include <sys/endian.h>
45 # elif defined HAVE_SYS_MACHINE_H
46 #  include <sys/machine.h>
47 # elif defined HAVE_SYS_ISA_DEFS_H
48 #  include <sys/isa_defs.h>
49 # else
50 #  error "Can not include endian.h"
51 # endif
52 #endif
53
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <string.h>
57
58 #ifdef HAVE_SYS_VARARGS
59 # include <sys/varargs.h>
60 #endif
61
62 #ifdef HAVE_FCNTL_H
63 # include <fcntl.h>
64 #endif
65
66 #ifdef HAVE_SYS_FCNTL_H
67 # include <sys/fcntl.h>
68 #endif
69
70 #ifdef HAVE_DLFCN_H
71 # include <dlfcn.h>
72 #endif
73
74 #ifdef HAVE_INTTYPES_H
75 # include <inttypes.h>
76 #elif HAVE_STDINT_H
77 # include <stdint.h>
78 #else
79 # error "Can not include inttypes or stdint"
80 #endif
81
82
83 #ifdef HAVE_PTHREAD
84 # include <pthread.h>
85 #endif
86
87 #ifdef HAVE_INLINE
88 # define INLINE inline
89 #endif
90
91 #ifndef O_BINARY
92 # define O_BINARY 0
93 #endif
94
95 #ifdef HAVE_PTHREAD
96 # define CHEROKEE_MUTEX_T(n)          pthread_mutex_t n
97 # define CHEROKEE_RWLOCK_T(n)         pthread_rwlock_t n
98 # define CHEROKEE_THREAD_JOIN(t)      pthread_join(t,NULL)
99 # define CHEROKEE_THREAD_SELF         pthread_self()
100
101 # define CHEROKEE_MUTEX_LOCK(m)       pthread_mutex_lock(m)
102 # define CHEROKEE_MUTEX_UNLOCK(m)     pthread_mutex_unlock(m)
103 # define CHEROKEE_MUTEX_INIT(m,n)     pthread_mutex_init(m,n)
104 # define CHEROKEE_MUTEX_DESTROY(m)    pthread_mutex_destroy(m)
105 # define CHEROKEE_MUTEX_TRY_LOCK(m)   pthread_mutex_trylock(m)
106
107 # define CHEROKEE_RWLOCK_INIT(m,n)    pthread_rwlock_init(m,n)
108 # define CHEROKEE_RWLOCK_READER(m)    pthread_rwlock_rdlock(m)
109 # define CHEROKEE_RWLOCK_WRITER(m)    pthread_rwlock_wrlock(m)
110 # define CHEROKEE_RWLOCK_TRYREADER(m) pthread_rwlock_tryrdlock(m)
111 # define CHEROKEE_RWLOCK_TRYWRITER(m) pthread_rwlock_trywrlock(m)
112 # define CHEROKEE_RWLOCK_UNLOCK(m)    pthread_rwlock_unlock(m)
113 # define CHEROKEE_RWLOCK_DESTROY(m)   pthread_rwlock_destroy(m)
114 #else
115 # define CHEROKEE_MUTEX_T(n)         
116 # define CHEROKEE_RWLOCK_T(n)         
117 # define CHEROKEE_THREAD_JOIN(t)
118 # define CHEROKEE_THREAD_SELF         0
119
120 # define CHEROKEE_MUTEX_LOCK(m)
121 # define CHEROKEE_MUTEX_UNLOCK(m)
122 # define CHEROKEE_MUTEX_INIT(m,n) 
123 # define CHEROKEE_MUTEX_DESTROY(m)
124 # define CHEROKEE_MUTEX_TRY_LOCK(m)   0
125
126 # define CHEROKEE_RWLOCK_INIT(m,n)
127 # define CHEROKEE_RWLOCK_READER(m)
128 # define CHEROKEE_RWLOCK_WRITER(m)
129 # define CHEROKEE_RWLOCK_TRYREADER(m) 0
130 # define CHEROKEE_RWLOCK_TRYWRITER(m) 0
131 # define CHEROKEE_RWLOCK_UNLOCK(m)
132 # define CHEROKEE_RWLOCK_DESTROY(m)
133 #endif
134
135 #ifdef _WIN32
136 # define SOCK_ERRNO()      WSAGetLastError()
137 #else
138 # define SOCK_ERRNO()      errno
139 #endif
140
141
142 /* IMPORTANT:
143  * Cross compilers should define BYTE_ORDER in CFLAGS
144  */
145 #ifndef BYTE_ORDER
146
147 /* Definitions for byte order, according to byte significance from low
148  * address to high.
149  */
150 # ifndef  LITTLE_ENDIAN
151 #  define LITTLE_ENDIAN  1234    /* LSB first: i386, vax */
152 # endif
153 # ifndef BIG_ENDIAN
154 #  define BIG_ENDIAN     4321    /* MSB first: 68000, ibm, net */
155 # endif
156 # ifndef PDP_ENDIAN
157 #  define PDP_ENDIAN     3412    /* LSB first in word, MSW first in long */
158 # endif
159
160 /* It assumes autoconf's AC_C_BIGENDIAN has been ran.
161  * If it hasn't, we assume the order is LITTLE ENDIAN.
162  */
163 # ifdef WORDS_BIGENDIAN
164 #   define BYTE_ORDER  BIG_ENDIAN
165 # else
166 #   define BYTE_ORDER  LITTLE_ENDIAN
167 # endif
168
169 #endif
170
171 /* String missing prototypes:
172  * Implemented in util.c, can't move prototype there though
173  */
174 #ifndef HAVE_STRSEP
175 char *strsep(char **str, const char *delims);
176 #endif
177
178 #ifndef HAVE_STRCASESTR
179 char *strcasestr(char *s, char *find);
180 #endif
181
182 /* Int limit
183  */
184 #ifndef INT_MAX
185 # if (SIZEOF_INT == 4)
186 #  define INT_MAX 0x7fffffffL          /* 2^32 - 1 */
187 # elif (SIZEOF_INT == 8)
188 #  define INT_MAX 0x7fffffffffffffffL  /* 2^64 - 1 */
189 # else
190 #  error "Can't define INT_MAX"
191 # endif
192 #endif
193
194 /* Depend on fcntl.h
195  */
196 #ifndef O_NOFOLLOW
197 # define O_NOFOLLOW 0
198 #endif
199
200 #ifndef O_LARGEFILE
201 # define O_LARGEFILE 0
202 #endif
203
204 #ifndef S_ISLNK
205 # define S_ISLNK(i) (0)
206 #endif
207
208 #endif /* CHEROKEE_COMMON_INTERNAL_H */
Note: See TracBrowser for help on using the browser.