Apache Portable Runtime
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif /* __cplusplus */
53 
54 /**
55  * @defgroup apr_portabile Portability Routines
56  * @ingroup APR
57  * @{
58  */
59 
60 #ifdef WIN32
61 /* The primitives for Windows types */
62 typedef HANDLE apr_os_file_t;
63 typedef HANDLE apr_os_dir_t;
64 typedef SOCKET apr_os_sock_t;
65 typedef HANDLE apr_os_proc_mutex_t;
66 typedef HANDLE apr_os_thread_t;
67 typedef HANDLE apr_os_proc_t;
68 typedef DWORD apr_os_threadkey_t;
69 typedef FILETIME apr_os_imp_time_t;
70 typedef SYSTEMTIME apr_os_exp_time_t;
71 typedef HANDLE apr_os_dso_handle_t;
72 typedef HANDLE apr_os_shm_t;
73 
74 #elif defined(OS2)
75 typedef HFILE apr_os_file_t;
76 typedef HDIR apr_os_dir_t;
77 typedef int apr_os_sock_t;
78 typedef HMTX apr_os_proc_mutex_t;
79 typedef TID apr_os_thread_t;
80 typedef PID apr_os_proc_t;
81 typedef PULONG apr_os_threadkey_t;
82 typedef struct timeval apr_os_imp_time_t;
83 typedef struct tm apr_os_exp_time_t;
84 typedef HMODULE apr_os_dso_handle_t;
85 typedef void* apr_os_shm_t;
86 
87 #elif defined(__BEOS__)
88 #include <kernel/OS.h>
89 #include <kernel/image.h>
90 
91 struct apr_os_proc_mutex_t {
92  sem_id sem;
93  int32 ben;
94 };
95 
96 typedef int apr_os_file_t;
97 typedef DIR apr_os_dir_t;
98 typedef int apr_os_sock_t;
99 typedef struct apr_os_proc_mutex_t apr_os_proc_mutex_t;
100 typedef thread_id apr_os_thread_t;
101 typedef thread_id apr_os_proc_t;
102 typedef int apr_os_threadkey_t;
103 typedef struct timeval apr_os_imp_time_t;
104 typedef struct tm apr_os_exp_time_t;
105 typedef image_id apr_os_dso_handle_t;
106 typedef void* apr_os_shm_t;
107 
108 #elif defined(NETWARE)
109 typedef int apr_os_file_t;
110 typedef DIR apr_os_dir_t;
111 typedef int apr_os_sock_t;
112 typedef NXMutex_t apr_os_proc_mutex_t;
113 typedef NXThreadId_t apr_os_thread_t;
114 typedef long apr_os_proc_t;
115 typedef NXKey_t apr_os_threadkey_t;
116 typedef struct timeval apr_os_imp_time_t;
117 typedef struct tm apr_os_exp_time_t;
118 typedef void * apr_os_dso_handle_t;
119 typedef void* apr_os_shm_t;
120 
121 #else
122 /* Any other OS should go above this one. This is the lowest common
123  * denominator typedefs for all UNIX-like systems. :)
124  */
125 
126 /** Basic OS process mutex structure. */
127 struct apr_os_proc_mutex_t {
128 #if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
129  /** Value used for SYS V Semaphore, FCNTL and FLOCK serialization */
130  int crossproc;
131 #endif
132 #if APR_HAS_PROC_PTHREAD_SERIALIZE
133  /** Value used for PTHREAD serialization */
134  pthread_mutex_t *pthread_interproc;
135 #endif
136 #if APR_HAS_THREADS
137  /* If no threads, no need for thread locks */
138 #if APR_USE_PTHREAD_SERIALIZE
139  /** This value is currently unused within APR and Apache */
140  pthread_mutex_t *intraproc;
141 #endif
142 #endif
143 };
144 
145 typedef int apr_os_file_t; /**< native file */
146 typedef DIR apr_os_dir_t; /**< native dir */
147 typedef int apr_os_sock_t; /**< native dir */
148 typedef 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
152 typedef pthread_t apr_os_thread_t; /**< native thread */
153 typedef pthread_key_t apr_os_threadkey_t; /**< native thread address
154  * space */
155 #endif
156 typedef pid_t apr_os_proc_t; /**< native pid */
157 typedef struct timeval apr_os_imp_time_t; /**< native timeval */
158 typedef 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>
164 typedef shl_t apr_os_dso_handle_t;
165 #elif defined(DARWIN)
166 #include <mach-o/dyld.h>
167 typedef NSModule apr_os_dso_handle_t;
168 #else
169 typedef void * apr_os_dso_handle_t;
170 #endif
171 typedef 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-independenteclass="keyword">struct apr_os_proc_mutex_t apr_os_proc_mutex_t;
100 typedef thread_id apr_os_thread_t;
101 typedef thread_id apr_os_proc_t;
102 typedef int apr_os_threadkey_t;
103 typedef struct timeval apr_os_imp_time_t;
104 typedef struct tm apr_os_exp_time_t;
105 typedef image_id apr_os_dso_handle_t;
106 typedef void* apr_os_shm_t;
107 
108 #elif defined(NETWARE)
109 typedef int apr_os_file_t;
110 typedef DIR apr_os_dir_t;
111 typedef int apr_os_sock_t;
112 typedef NXMutex_t apr_os_proc_mutex_t;
113 typedef NXThreadId_t apr_os_thread_t;
114 typedef long apr_os_proc_t;
115 typedef NXKey_t apr_os_threadkey_t;
116 typedef struct timeval apr_os_imp_time_t;
117 typedef struct tm apr_os_exp_time_t;
118 typedef void * apr_os_dso_handle_t;
119 typedef void* apr_os_shm_t;
120 
121 #else
122 /* Any other OS should go above this one. This is the lowest common
123  * denominator typedefs for all UNIX-like systems. :)
124  */
125 
126 /** Basic OS process mutex structure. */
127 struct apr_os_proc_mutex_t {
128 #if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
129  /** Value used for SYS V Semaphore, FCNTL and FLOCK serialization */
130  int crossproc;
131 #endif
132 #if APR_HAS_PROC_PTHREAD_SERIALIZE
133  /** Value used for PTHREAD serialization */
134  pthread_mutex_t *pthread_interproc;
135 #endif
136 #if APR_HAS_THREADS
137  /* If no threads, no need for thread locks */
138 #if APR_USE_PTHREAD_SERIALIZE
139  /** This value is currently unused within APR and Apache */
140  pthread_mutex_t *intraproc;
141 #endif
142 #endif
143 };
144 
145 typedef int apr_os_file_t; /**< native file */
146 typedef DIR apr_os_dir_t; /**< native dir */
147 typedef int apr_os_sock_t; /**< native dir */
148 typedef 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
152 typedef pthread_t apr_os_thread_t; /**< native thread */
153 typedef pthread_key_t apr_os_threadkey_t; /**< native thread address
154  * space */
155 #endif
156 typedef pid_t apr_os_proc_t; /**< native pid */
157 typedef struct timeval apr_os_imp_time_t; /**< native timeval */
158 typedef 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>
164 typedef shl_t apr_os_dso_handle_t;
165 #elif defined(DARWIN)
166 #include <mach-o/dyld.h>
167 typedef NSModule apr_os_dso_handle_t;
168 #else
169 typedef void * apr_os_dso_handle_t;
170 #endif
171 typedef 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-independenteclass="keyword">struct apr_os_proc_mutex_t apr_os_proc_mutex_t;
100 typedef thread_id apr_os_thread_t;
101 typedef thread_id apr_os_proc_t;
102 typedef int apr_os_threadkey_t;
103 typedef struct timeval apr_os_imp_time_t;
104 typedef struct tm apr_os_exp_time_t;
105 typedef image_id apr_os_dso_handle_t;
106 typedef void* apr_os_shm_t;
107 
108 #elif defined(NETWARE)
109 typedef int apr_os_file_t;
110 typedef DIR apr_os_dir_t;
111 typedef int apr_os_sock_t;
112 typedef NXMutex_t apr_os_proc_mutex_t;
113 typedef NXThreadId_t apr_os_thread_t;
114 typedef long apr_os_proc_t;
115 typedef NXKey_t apr_os_threadkey_t;
116 typedef struct timeval apr_os_imp_time_t;
117 typedef struct tm apr_os_exp_time_t;
118 typedef void * apr_os_dso_handle_t;
119 typedef void* apr_os_shm_t;
120 
121 #else
122 /* Any other OS should go above this one. This is the lowest common
123  * denominator typedefs for all UNIX-like systems. :)
124  */
125 
126 /** Basic OS process mutex structure. */
127 struct apr_os_proc_mutex_t {
128 #if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
129  /** Value used for SYS V Semaphore, FCNTL and FLOCK serialization */
130  int crossproc;
131 #endif
132 #if APR_HAS_PROC_PTHREAD_SERIALIZE
133  /** Value used for PTHREAD serialization */
134  pthread_mutex_t *pthread_interproc;
135 #endif
136 #if APR_HAS_THREADS
137  /* If no threads, no need for thread locks */
138 #if APR_USE_PTHREAD_SERIALIZE
139  /** This value is currently unused within APR and Apache */
140  pthread_mutex_t *intraproc;
141 #endif
142 #endif
143 };
144 
145 typedef int apr_os_file_t; /**< native file */
146 typedef DIR apr_os_dir_t; /**< native dir */
147 typedef int apr_os_sock_t; /**< native dir */
148 typedef 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
152 typedef pthread_t apr_os_thread_t; /**< native thread */
153 typedef pthread_key_t apr_os_threadkey_t; /**< native thread address
154  * space */
155 #endif
156 typedef pid_t apr_os_proc_t; /**< native pid */
157 typedef struct timeval apr_os_imp_time_t; /**< native timeval */
158 typedef 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>
164 typedef shl_t apr_os_dso_handle_t;
165 #elif defined(DARWIN)
166 #include <mach-o/dyld.h>
167 typedef NSModule apr_os_dso_handle_t;
168 #else
169 typedef void * apr_os_dso_handle_t;
170 #endif
171 typedef 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-independenteclass="keyword">struct apr_os_proc_mutex_t apr_os_proc_mutex_t;
100 typedef thread_id apr_os_thread_t;
101 typedef thread_id apr_os_proc_t;
102 typedef int apr_os_threadkey_t;
103 typedef struct timeval apr_os_imp_time_t;
104 typedef struct tm apr_os_exp_time_t;
105 typedef image_id apr_os_dso_handle_t;
106 typedef void* apr_os_shm_t;
107 
108 #elif defined(NETWARE)
109 typedef int apr_os_file_t;
110 typedef DIR apr_os_dir_t;
111 typedef int apr_os_sock_t;
112 typedef NXMutex_t apr_os_proc_mutex_t;
113 typedef NXThreadId_t apr_os_thread_t;
114 typedef long apr_os_proc_t;
115 typedef NXKey_t apr_os_threadkey_t;
116 typedef struct timeval apr_os_imp_time_t;
117 typedef struct tm apr_os_exp_time_t;
118 typedef void * apr_os_dso_handle_t;
119 typedef void* apr_os_shm_t;
120 
121 #else
122 /* Any other OS should go above this one. This is the lowest common
123  * denominator typedefs for all UNIX-like systems. :)
124  */
125 
126 /** Basic OS process mutex structure. */
127 struct apr_os_proc_mutex_t {
128 #if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
129  /** Value used for SYS V Semaphore, FCNTL and FLOCK serialization */
130  int crossproc;
131 #endif
132 #if APR_HAS_PROC_PTHREAD_SERIALIZE
133  /** Value used for PTHREAD serialization */
134  pthread_mutex_t *pthread_interproc;
135 #endif
136 #if APR_HAS_THREADS
137  /* If no threads, no need for thread locks */
138 #if APR_USE_PTHREAD_SERIALIZE
139  /** This value is currently unused within APR and Apache */
140  pthread_mutex_t *intraproc;
141 #endif
142 #endif
143 };
144 
145 typedef int apr_os_file_t; /**< native file */
146 typedef DIR apr_os_dir_t; /**< native dir */
147 typedef int apr_os_sock_t; /**< native dir */
148 typedef 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
152 typedef pthread_t apr_os_thread_t; /**< native thread */
153 typedef pthread_key_t apr_os_threadkey_t; /**< native thread address
154  * space */
155 #endif
156 typedef pid_t apr_os_proc_t; /**< native pid */
157 typedef struct timeval apr_os_imp_time_t; /**< native timeval */
158 typedef 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>
164 typedef shl_t apr_os_dso_handle_t;
165 #elif defined(DARWIN)
166 #include <mach-o/dyld.h>
167 typedef NSModule apr_os_dso_handle_t;
168 #else
169 typedef void * apr_os_dso_handle_t;
170 #endif
171 typedef 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-independenteclass="keyword">struct apr_os_proc_mutex_t apr_os_proc_mutex_t;
100 typedef thread_id apr_os_thread_t;
101 typedef thread_id apr_os_proc_t;
102 typedef int apr_os_threadkey_t;
103 typedef struct timeval apr_os_imp_time_t;
104 typedef struct tm apr_os_exp_time_t;
105 typedef image_id apr_os_dso_handle_t;
106 typedef void* apr_os_shm_t;
107 
108 #elif defined(NETWARE)
109 typedef int apr_os_file_t;
110 typedef DIR apr_os_dir_t;
111 typedef int apr_os_sock_t;
112 typedef NXMutex_t apr_os_proc_mutex_t;
113 typedef NXThreadId_t apr_os_thread_t;
114 typedef long apr_os_proc_t;
115 typedef NXKey_t apr_os_threadkey_t;
116 typedef struct timeval apr_os_imp_time_t;
117 typedef struct tm apr_os_exp_time_t;
118 typedef void * apr_os_dso_handle_t;
119 typedef void* apr_os_shm_t;
120 
121 #else
122 /* Any other OS should go above this one. This is the lowest common
123  * denominator typedefs for all UNIX-like systems. :)
124  */
125 
126 /** Basic OS process mutex structure. */
127 struct apr_os_proc_mutex_t {
128 #if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
129  /** Value used for SYS V Semaphore, FCNTL and FLOCK serialization */
130  int crossproc;
131 #endif
132 #if APR_HAS_PROC_PTHREAD_SERIALIZE
133  /** Value used for PTHREAD serialization */
134  pthread_mutex_t *pthread_interproc;
135 #endif
136 #if APR_HAS_THREADS
137  /* If no threads, no need for thread locks */
138 #if APR_USE_PTHREAD_SERIALIZE
139  /** This value is currently unused within APR and Apache */
140  pthread_mutex_t *intraproc;
141 #endif
142 #endif
143 };
144 
145 typedef int apr_os_file_t; /**< native file */
146 typedef DIR apr_os_dir_t; /**< native dir */
147 typedef int apr_os_sock_t; /**< native dir */
148 typedef 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
152 typedef pthread_t apr_os_thread_t; /**< native thread */
153 typedef pthread_key_t apr_os_threadkey_t; /**< native thread address
154  * space */
155 #endif
156 typedef pid_t apr_os_proc_t; /**< native pid */
157 typedef struct timeval apr_os_imp_time_t; /**< native timeval */
158 typedef struct tm ap