Apache Portable Runtime
Loading...
Searching...
No Matches
apr_portable.h
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* This header file is where you should put ANY platform specific information.
18 * This should be the only header file that programs need to include that
19 * actually has platform dependent code which refers to the .
20 */
21#ifndef APR_PORTABLE_H
22#define APR_PORTABLE_H
23/**
24 * @file apr_portable.h
25 * @brief APR Portability Routines
26 */
27
28#include "apr.h"
29#include "apr_pools.h"
30#include "apr_thread_proc.h"
31#include "apr_file_io.h"
32#include "apr_network_io.h"
33#include "apr_errno.h"
34#include "apr_global_mutex.h"
35#include "apr_proc_mutex.h"
36#include "apr_time.h"
37#include "apr_dso.h"
38#include "apr_shm.h"
39
40#if APR_HAVE_DIRENT_H
41#include <dirent.h>
42#endif
43#if APR_HAVE_FCNTL_H
44#include <fcntl.h>
45#endif
46#if APR_HAVE_PTHREAD_H
47#include <pthread.h>
48#endif
49#if APR_HAVE_SEMAPHORE_H
50#include <semaphore.h>
51#endif
52
53#ifdef __cplusplus
54extern "C" {
55#endif /* __cplusplus */
56
57/**
58 * @defgroup apr_portabile Portability Routines
59 * @ingroup APR
60 * @{
61 */
62
63#ifdef WIN32
64/* The primitives for Windows types */
65typedef HANDLE apr_os_file_t;
66typedef HANDLE apr_os_dir_t;
67typedef SOCKET apr_os_sock_t;
68typedef HANDLE apr_os_proc_mutex_t;
69typedef HANDLE apr_os_thread_t;
70typedef HANDLE apr_os_proc_t;
71typedef DWORD apr_os_threadkey_t;
72typedef FILETIME apr_os_imp_time_t;
73typedef SYSTEMTIME apr_os_exp_time_t;
74typedef HANDLE apr_os_dso_handle_t;
75typedef HANDLE apr_os_shm_t;
76
77#elif defined(OS2)
78typedef HFILE apr_os_file_t;
79typedef HDIR apr_os_dir_t;
80typedef int apr_os_sock_t;
81typedef HMTX apr_os_proc_mutex_t;
82typedef TID apr_os_thread_t;
83typedef PID apr_os_proc_t;
84typedef PULONG apr_os_threadkey_t;
85typedef struct timeval apr_os_imp_time_t;
86typedef struct tm apr_os_exp_time_t;
87typedef HMODULE apr_os_dso_handle_t;
88typedef void* apr_os_shm_t;
89
90#elif defined(__BEOS__)
91#include <kernel/OS.h>
92#include <kernel/image.h>
93
95 sem_id sem;
96 int32 ben;
97};
98
99typedef int apr_os_file_t;
100typedef DIR apr_os_dir_t;
101typedef int apr_os_sock_t;
103typedef thread_id apr_os_thread_t;
104typedef thread_id apr_os_proc_t;
105typedef int apr_os_threadkey_t;
106typedef struct timeval apr_os_imp_time_t;
107typedef struct tm apr_os_exp_time_t;
108typedef image_id apr_os_dso_handle_t;
109typedef void* apr_os_shm_t;
110
111#elif defined(NETWARE)
112typedef int apr_os_file_t;
113typedef DIR apr_os_dir_t;
114typedef int apr_os_sock_t;
115typedef NXMutex_t * apr_os_proc_mutex_t;
116typedef NXThreadId_t apr_os_thread_t;
117typedef long apr_os_proc_t;
118typedef NXKey_t apr_os_threadkey_t;
119typedef struct timeval apr_os_imp_time_t;
120typedef struct tm apr_os_exp_time_t;
121typedef void * apr_os_dso_handle_t;
122typedef void* apr_os_shm_t;
123
124#else
125/* Any other OS should go above this one. This is the lowest common
126 * denominator typedefs for all UNIX-like systems. :)
127 */
128
129/** Basic OS process mutex structure. */
131#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
132 /** Value used for SYS V Semaphore, FCNTL and FLOCK serialization */
133 int crossproc;
134#endif
135#if APR_HAS_PROC_PTHREAD_SERIALIZE
136 /** Value used for PTHREAD serialization */
137 pthread_mutex_t *pthread_interproc;
138#endif
139#if APR_HAS_POSIXSEM_SERIALIZE
140 /** Value used for POSIX semaphores serialization */
141 sem_t *psem_interproc;
142#endif
143};
144
145typedef int apr_os_file_t; /**< native file */
146typedef DIR apr_os_dir_t; /**< native dir */
147typedef int apr_os_sock_t; /**< native dir */
148typedef struct apr_os_proc_mutex_t apr_os_proc_mutex_t; /**< native process
149 * mutex
150 */
151#if APR_HAS_THREADS && APR_HAVE_PTHREAD_H
152typedef pthread_t apr_os_thread_t; /**< native thread */
153typedef pthread_key_t apr_os_threadkey_t; /**< native thread address
154 * space */
155#endif
156typedef pid_t apr_os_proc_t; /**< native pid */
157typedef struct timeval apr_os_imp_time_t; /**< native timeval */
158typedef struct tm apr_os_exp_time_t; /**< native tm */
159/** @var apr_os_dso_handle_t
160 * native dso types
161 */
162#if defined(HPUX) || defined(HPUX10) || defined(HPUX11)
163#include <dl.h>
164typedef shl_t apr_os_dso_handle_t;
165#elif defined(DARWIN)
166#include <mach-o/dyld.h>
167typedef NSModule apr_os_dso_handle_t;
168#else
169typedef void * apr_os_dso_handle_t;
170#endif
171typedef void* apr_os_shm_t; /**< native SHM */
172
173#endif
174
175/**
176 * @typedef apr_os_sock_info_t
177 * @brief alias for local OS socket
178 */
179/**
180 * everything APR needs to know about an active socket to construct
181 * an APR socket from it; currently, this is platform-independent
182 */
184 apr_os_sock_t *os_sock; /**< always required */
185 struct sockaddr *local; /**< NULL if not yet bound */
186 struct sockaddr *remote; /**< NULL if not connected */
187 int family; /**< always required (APR_INET, APR_INET6, etc.) */
188 int type; /**< always required (SOCK_STREAM, SOCK_DGRAM, etc.) */
189 int protocol; /**< 0 or actual protocol (APR_PROTO_SCTP, APR_PROTO_TCP, etc.) */
190};
191
193
194#if APR_PROC_MUTEX_IS_GLOBAL || defined(DOXYGEN)
195/** Opaque global mutex type */
196#define apr_os_global_mutex_t apr_os_proc_mutex_t
197/** @return apr_os_global_mutex */
198#define apr_os_global_mutex_get apr_os_proc_mutex_get
199#else
200 /** Thread and process mutex for those platforms where process mutexes
201 * are not held in threads.
202 */
203 struct apr_os_global_mutex_t {
204 apr_pool_t *pool;
205 apr_proc_mutex_t *proc_mutex;
206#if APR_HAS_THREADS
207 apr_thread_mutex_t *thread_mutex;
208#endif /* APR_HAS_THREADS */
209 };
211
213 apr_global_mutex_t *pmutex);
214#endif
215
216
217/**
218 * convert the file from apr type to os specific type.
219 * @param thefile The os specific file we are converting to
220 * @param file The apr file to convert.
221 * @remark On Unix, it is only possible to get a file descriptor from
222 * an apr file type.
223 */
225 apr_file_t *file);
226
227/**
228 * convert the dir from apr type to os specific type.
229 * @param thedir The os specific dir we are converting to
230 * @param dir The apr dir to convert.
231 */
233 apr_dir_t *dir);
234
235/**
236 * Convert the socket from an apr type to an OS specific socket
237 * @param thesock The socket to convert.
238 * @param sock The os specific equivalent of the apr socket..
239 */
241 apr_socket_t *sock);
242
243/**
244 * Convert the proc mutex from apr type to os specific type
245 * @param ospmutex The os specific proc mutex we are converting to.
246 * @param pmutex The apr proc mutex to convert.
247 */
249 apr_proc_mutex_t *pmutex);
250
251/**
252 * Convert the proc mutex from apr type to os specific type, also
253 * providing the mechanism used by the apr mutex.
254 * @param ospmutex The os specific proc mutex we are converting to.
255 * @param pmutex The apr proc mutex to convert.
256 * @param mech The mechanism used by the apr proc mutex (if not NULL).
257 * @remark Allows for disambiguation for platforms with multiple mechanisms
258 * available.
259 */
261 apr_proc_mutex_t *pmutex,
262 apr_lockmech_e *mech);
263
264/**
265 * Get the exploded time in the platforms native format.
266 * @param ostime the native time format
267 * @param aprtime the time to convert
268 */
270 apr_time_exp_t *aprtime);
271
272/**
273 * Get the imploded time in the platforms native format.
274 * @param ostime the native time format
275 * @param aprtime the time to convert
276 */
278 apr_time_t *aprtime);
279
280/**
281 * convert the shm from apr type to os specific type.
282 * @param osshm The os specific shm representation
283 * @param shm The apr shm to convert.
284 */
286 apr_shm_t *shm);
287
288#if APR_HAS_THREADS || defined(DOXYGEN)
289/**
290 * @defgroup apr_os_thread Thread portability Routines
291 * @{
292 */
293/**
294 * convert the thread to os specific type from apr type.
295 * @param thethd The apr thread to convert
296 * @param thd The os specific thread we are converting to
297 */
299 apr_thread_t *thd);
300
301/**
302 * convert the thread private memory key to os specific type from an apr type.
303 * @param thekey The apr handle we are converting from.
304 * @param key The os specific handle we are converting to.
305 */
307 apr_threadkey_t *key);
308
309/**
310 * convert the thread from os specific type to apr type.
311 * @param thd The apr thread we are converting to.
312 * @param thethd The os specific thread to convert
313 * @param cont The pool to use if it is needed.
314 */
316 apr_os_thread_t *thethd,
317 apr_pool_t *cont);
318
319/**
320 * convert the thread private memory key from os specific type to apr type.
321 * @param key The apr handle we are converting to.
322 * @param thekey The os specific handle to convert
323 * @param cont The pool to use if it is needed.
324 */
326 apr_os_threadkey_t *thekey,
327 apr_pool_t *cont);
328/**
329 * Get the thread ID
330 */
331APR_DECLARE(apr_os_thread_t) apr_os_thread_current(void);
332
333/**
334 * Compare two thread id's
335 * @param tid1 1st Thread ID to compare
336 * @param tid2 2nd Thread ID to compare
337 * @return non-zero if the two threads are equal, zero otherwise
338 */
339APR_DECLARE(int) apr_os_thread_equal(apr_os_thread_t tid1,
340 apr_os_thread_t tid2);
341
342/** @} */
343#endif /* APR_HAS_THREADS */
344
345/**
346 * convert the file from os specific type to apr type.
347 * @param file The apr file we are converting to.
348 * @param thefile The os specific file to convert
349 * @param flags The flags that were used to open this file.
350 * @param cont The pool to use if it is needed.
351 * @remark On Unix, it is only possible to put a file descriptor into
352 * an apr file type.
353 */
355 apr_os_file_t *thefile,
356 apr_int32_t flags, apr_pool_t *cont);
357
358/**
359 * convert the file from os specific type to apr type.
360 * @param file The apr file we are converting to.
361 * @param thefile The os specific pipe to convert
362 * @param cont The pool to use if it is needed.
363 * @remark On Unix, it is only possible to put a file descriptor into
364 * an apr file type.
365 */
367 apr_os_file_t *thefile,
368 apr_pool_t *cont);
369
370/**
371 * convert the file from os specific type to apr type.
372 * @param file The apr file we are converting to.
373 * @param thefile The os specific pipe to convert
374 * @param register_cleanup A cleanup will be registered on the apr_file_t
375 * to issue apr_file_close().
376 * @param cont The pool to use if it is needed.
377 * @remark On Unix, it is only possible to put a file descriptor into
378 * an apr file type.
379 */
381 apr_os_file_t *thefile,
382 int register_cleanup,
383 apr_pool_t *cont);
384
385/**
386 * convert the dir from os specific type to apr type.
387 * @param dir The apr dir we are converting to.
388 * @param thedir The os specific dir to convert
389 * @param cont The pool to use when creating to apr directory.
390 */
392 apr_os_dir_t *thedir,
393 apr_pool_t *cont);
394
395/**
396 * Convert a socket from the os specific type to the APR type. If
397 * sock points to NULL, a socket will be created from the pool
398 * provided. If **sock does not point to NULL, the structure pointed
399 * to by sock will be reused and updated with the given socket.
400 * @param sock The pool to use.
401 * @param thesock The socket to convert to.
402 * @param cont The socket we are converting to an apr type.
403 * @remark If it is a true socket, it is best to call apr_os_sock_make()
404 * and provide APR with more information about the socket.
405 */
407 apr_os_sock_t *thesock,
408 apr_pool_t *cont);
409
410/**
411 * Create a socket from an existing descriptor and local and remote
412 * socket addresses.
413 * @param apr_sock The new socket that has been set up
414 * @param os_sock_info The os representation of the socket handle and
415 * other characteristics of the socket
416 * @param cont The pool to use
417 * @remark If you only know the descriptor/handle or if it isn't really
418 * a true socket, use apr_os_sock_put() instead.
419 */
421 apr_os_sock_info_t *os_sock_info,
422 apr_pool_t *cont);
423
424/**
425 * Convert the proc mutex from os specific type to apr type
426 * @param pmutex The apr proc mutex we are converting to.
427 * @param ospmutex The os specific proc mutex to convert.
428 * @param cont The pool to use if it is needed.
429 */
431 apr_os_proc_mutex_t *ospmutex,
432 apr_pool_t *cont);
433
434/**
435 * Convert the proc mutex from os specific type to apr type, using the
436 * specified mechanism.
437 * @param pmutex The apr proc mutex we are converting to.
438 * @param ospmutex The os specific proc mutex to convert.
439 * @param mech The apr mutex locking mechanism
440 * @param register_cleanup Whether to destroy the os mutex with the apr
441 * one (either on explicit destroy or pool cleanup).
442 * @param cont The pool to use if it is needed.
443 * @remark Allows for disambiguation for platforms with multiple mechanisms
444 * available.
445 */
447 apr_os_proc_mutex_t *ospmutex,
448 apr_lockmech_e mech,
449 int register_cleanup,
450 apr_pool_t *cont);
451
452/**
453 * Put the imploded time in the APR format.
454 * @param aprtime the APR time format
455 * @param ostime the time to convert
456 * @param cont the pool to use if necessary
457 */
459 apr_os_imp_time_t **ostime,
460 apr_pool_t *cont);
461
462/**
463 * Put the exploded time in the APR format.
464 * @param aprtime the APR time format
465 * @param ostime the time to convert
466 * @param cont the pool to use if necessary
467 */
469 apr_os_exp_time_t **ostime,
470 apr_pool_t *cont);
471
472/**
473 * convert the shared memory from os specific type to apr type.
474 * @param shm The apr shm representation of osshm
475 * @param osshm The os specific shm identity
476 * @param cont The pool to use if it is needed.
477 * @remark On fork()ed architectures, this is typically nothing more than
478 * the memory block mapped. On non-fork architectures, this is typically
479 * some internal handle to pass the mapping from process to process.
480 */
482 apr_os_shm_t *osshm,
483 apr_pool_t *cont);
484
485
486#if APR_HAS_DSO || defined(DOXYGEN)
487/**
488 * @defgroup apr_os_dso DSO (Dynamic Loading) Portability Routines
489 * @{
490 */
491/**
492 * convert the dso handle from os specific to apr
493 * @param dso The apr handle we are converting to
494 * @param thedso the os specific handle to convert
495 * @param pool the pool to use if it is needed
496 */
498 apr_os_dso_handle_t thedso,
499 apr_pool_t *pool);
500
501/**
502 * convert the apr dso handle into an os specific one
503 * @param aprdso The apr dso handle to convert
504 * @param dso The os specific dso to return
505 */
507 apr_dso_handle_t *aprdso);
508
509/** @} */
510#endif /* APR_HAS_DSO */
511
512
513#if APR_HAS_OS_UUID
514/**
515 * Private: apr-util's apr_uuid module when supported by the platform
516 */
517APR_DECLARE(apr_status_t) apr_os_uuid_get(unsigned char *uuid_data);
518#endif
519
520
521/**
522 * Get the name of the system default character set.
523 * @param pool the pool to allocate the name from, if needed
524 */
526
527
528/**
529 * Get the name of the current locale character set.
530 * @param pool the pool to allocate the name from, if needed
531 * @remark Defers to apr_os_default_encoding() if the current locale's
532 * data can't be retrieved on this system.
533 */
535
536/** @} */
537
538#ifdef __cplusplus
539}
540#endif
541
542#endif /* ! APR_PORTABLE_H */
APR Platform Definitions.
APR Dynamic Object Handling Routines.
APR Error Codes.
APR File I/O Handling.
APR Global Locking Routines.
APR Network library.
APR memory allocation.
APR Process Locking Routines.
APR Shared Memory Routines.
APR Thread and Process Library.
APR Time Library.
struct apr_global_mutex_t apr_global_mutex_t
Definition apr_global_mutex.h:47
struct apr_dso_handle_t apr_dso_handle_t
Definition apr_dso.h:44
int apr_status_t
Definition apr_errno.h:44
struct apr_dir_t apr_dir_t
Definition apr_file_info.h:121
struct apr_file_t apr_file_t
Definition apr_file_io.h:195
struct apr_socket_t apr_socket_t
Definition apr_network_io.h:219
apr_status_t apr_os_dso_handle_get(apr_os_dso_handle_t *dso, apr_dso_handle_t *aprdso)
apr_status_t apr_os_dso_handle_put(apr_dso_handle_t **dso, apr_os_dso_handle_t thedso, apr_pool_t *pool)
apr_status_t apr_os_threadkey_get(apr_os_threadkey_t *thekey, apr_threadkey_t *key)
apr_status_t apr_os_threadkey_put(apr_threadkey_t **key, apr_os_threadkey_t *thekey, apr_pool_t *cont)
apr_os_thread_t apr_os_thread_current(void)
apr_status_t apr_os_thread_put(apr_thread_t **thd, apr_os_thread_t *thethd, apr_pool_t *cont)
int apr_os_thread_equal(apr_os_thread_t tid1, apr_os_thread_t tid2)
apr_status_t apr_os_thread_get(apr_os_thread_t **thethd, apr_thread_t *thd)
#define APR_DECLARE(type)
Definition apr.h:523
struct apr_pool_t apr_pool_t
Definition apr_pools.h:60
apr_status_t apr_os_sock_get(apr_os_sock_t *thesock, apr_socket_t *sock)
struct tm apr_os_exp_time_t
Definition apr_portable.h:158
apr_status_t apr_os_file_put(apr_file_t **file, apr_os_file_t *thefile, apr_int32_t flags, apr_pool_t *cont)
apr_status_t apr_os_file_get(apr_os_file_t *thefile, apr_file_t *file)
apr_status_t apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex, apr_proc_mutex_t *pmutex)
int apr_os_sock_t
Definition apr_portable.h:147
pid_t apr_os_proc_t
Definition apr_portable.h:156
apr_status_t apr_os_proc_mutex_put_ex(apr_proc_mutex_t **pmutex, apr_os_proc_mutex_t *ospmutex, apr_lockmech_e mech, int register_cleanup, apr_pool_t *cont)
apr_status_t apr_os_imp_time_get(apr_os_imp_time_t **ostime, apr_time_t *aprtime)
apr_status_t apr_os_dir_put(apr_dir_t **dir, apr_os_dir_t *thedir, apr_pool_t *cont)
void * apr_os_dso_handle_t
Definition apr_portable.h:169
apr_status_t apr_os_exp_time_put(apr_time_exp_t *aprtime, apr_os_exp_time_t **ostime, apr_pool_t *cont)
apr_status_t apr_os_sock_make(apr_socket_t **apr_sock, apr_os_sock_info_t *os_sock_info, apr_pool_t *cont)
struct timeval apr_os_imp_time_t
Definition apr_portable.h:157
apr_status_t apr_os_sock_put(apr_socket_t **sock, apr_os_sock_t *thesock, apr_pool_t *cont)
void * apr_os_shm_t
Definition apr_portable.h:171
apr_status_t apr_os_shm_get(apr_os_shm_t *osshm, apr_shm_t *shm)
const char * apr_os_locale_encoding(apr_pool_t *pool)
int apr_os_file_t
Definition apr_portable.h:145
apr_status_t apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex, apr_os_proc_mutex_t *ospmutex, apr_pool_t *cont)
apr_status_t apr_os_pipe_put(apr_file_t **file, apr_os_file_t *thefile, apr_pool_t *cont)
apr_status_t apr_os_imp_time_put(apr_time_t *aprtime, apr_os_imp_time_t **ostime, apr_pool_t *cont)
const char * apr_os_default_encoding(apr_pool_t *pool)
apr_status_t apr_os_exp_time_get(apr_os_exp_time_t **ostime, apr_time_exp_t *aprtime)
apr_status_t apr_os_dir_get(apr_os_dir_t **thedir, apr_dir_t *dir)
apr_status_t apr_os_pipe_put_ex(apr_file_t **file, apr_os_file_t *thefile, int register_cleanup, apr_pool_t *cont)
apr_status_t apr_os_shm_put(apr_shm_t **shm, apr_os_shm_t *osshm, apr_pool_t *cont)
apr_status_t apr_os_proc_mutex_get_ex(apr_os_proc_mutex_t *ospmutex, apr_proc_mutex_t *pmutex, apr_lockmech_e *mech)
DIR apr_os_dir_t
Definition apr_portable.h:146
#define apr_os_global_mutex_t
Definition apr_portable.h:196
#define apr_os_global_mutex_get
Definition apr_portable.h:198
struct apr_proc_mutex_t apr_proc_mutex_t
Definition apr_proc_mutex.h:57
apr_lockmech_e
Definition apr_proc_mutex.h:46
struct apr_shm_t apr_shm_t
Definition apr_shm.h:44
struct apr_thread_mutex_t apr_thread_mutex_t
Definition apr_thread_mutex.h:41
struct apr_threadkey_t apr_threadkey_t
Definition apr_thread_proc.h:190
struct apr_thread_t apr_thread_t
Definition apr_thread_proc.h:178
apr_int64_t apr_time_t
Definition apr_time.h:45
Definition apr_portable.h:130
Definition apr_portable.h:183
int protocol
Definition apr_portable.h:189
int type
Definition apr_portable.h:188
apr_os_sock_t * os_sock
Definition apr_portable.h:184
int family
Definition apr_portable.h:187
struct sockaddr * remote
Definition apr_portable.h:186
struct sockaddr * local
Definition apr_portable.h:185
Definition apr_time.h:97