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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "apr_inherit.h"
22 #define APR_INHERIT (1 << 24) /* Must not conflict with other bits */
24 #if APR_HAS_UNICODE_FS && APR_HAS_ANSI_FS
25 /* !defined(_WIN32_WCE) is implicit here */
27 #define APR_IMPLEMENT_INHERIT_SET(name, flag, pool, cleanup) \
28 APR_DECLARE(apr_status_t) apr_##name##_inherit_set(apr_##name##_t *the##name) \
30 IF_WIN_OS_IS_UNICODE \
32 /* if (!SetHandleInformation(the##name->filehand, \
33 * HANDLE_FLAG_INHERIT, \
34 * HANDLE_FLAG_INHERIT)) \
35 * return apr_get_os_error(); \
39 HANDLE temp, hproc = GetCurrentProcess(); \
40 if (!DuplicateHandle(hproc, the##name->filehand, \
41 hproc, &temp, 0, TRUE, \
42 DUPLICATE_SAME_ACCESS)) \
43 return apr_get_os_error(); \
44 CloseHandle(the##name->filehand); \
45 the##name->filehand = temp; \
50 #define APR_IMPLEMENT_INHERIT_UNSET(name, flag, pool, cleanup) \
51 APR_DECLARE(apr_status_t) apr_##name##_inherit_unset(apr_##name##_t *the##name)\
53 IF_WIN_OS_IS_UNICODE \
55 /* if (!SetHandleInformation(the##name->filehand, \
56 * HANDLE_FLAG_INHERIT, 0)) \
57 * return apr_get_os_error(); \
61 HANDLE temp, hproc = GetCurrentProcess(); \
62 if (!DuplicateHandle(hproc, the##name->filehand, \
63 hproc, &temp, 0, FALSE, \
64 DUPLICATE_SAME_ACCESS)) \
65 return apr_get_os_error(); \
66 CloseHandle(the##name->filehand); \
67 the##name->filehand = temp; \
72 #elif APR_HAS_ANSI_FS || defined(_WIN32_WCE)
74 #define APR_IMPLEMENT_INHERIT_SET(name, flag, pool, cleanup) \
75 APR_DECLARE(apr_status_t) apr_##name##_inherit_set(apr_##name##_t *the##name) \
77 HANDLE temp, hproc = GetCurrentProcess(); \
78 if (!DuplicateHandle(hproc, the##name->filehand, \
79 hproc, &temp, 0, TRUE, \
80 DUPLICATE_SAME_ACCESS)) \
81 return apr_get_os_error(); \
82 CloseHandle(the##name->filehand); \
83 the##name->filehand = temp; \
87 #define APR_IMPLEMENT_INHERIT_UNSET(name, flag, pool, cleanup) \
88 APR_DECLARE(apr_status_t) apr_##name##_inherit_unset(apr_##name##_t *the##name)\
90 HANDLE temp, hproc = GetCurrentProcess(); \
91 if (!DuplicateHandle(hproc, the##name->filehand, \
92 hproc, &temp, 0, FALSE, \
93 DUPLICATE_SAME_ACCESS)) \
94 return apr_get_os_error(); \
95 CloseHandle(the##name->filehand); \
96 the##name->filehand = temp; \
100 #else /* APR_HAS_UNICODE_FS && !APR_HAS_ANSI_FS && !defined(_WIN32_WCE) */
102 #define APR_IMPLEMENT_INHERIT_SET(name, flag, pool, cleanup) \
103 APR_DECLARE(apr_status_t) apr_##name##_inherit_set(apr_##name##_t *the##name) \
105 /* if (!SetHandleInformation(the##name->filehand, \
106 * HANDLE_FLAG_INHERIT, \
107 * HANDLE_FLAG_INHERIT)) \
108 * return apr_get_os_error(); \
109 */ return APR_SUCCESS; \
112 #define APR_IMPLEMENT_INHERIT_UNSET(name, flag, pool, cleanup) \
113 APR_DECLARE(apr_status_t) apr_##name##_inherit_unset(apr_##name##_t *the##name)\
115 /* if (!SetHandleInformation(the##name->filehand, \
116 * HANDLE_FLAG_INHERIT, 0)) \
117 * return apr_get_os_error(); \
118 */ return APR_SUCCESS; \
121 #endif /* defined(APR_HAS_UNICODE_FS) */
123 #endif /* ! INHERIT_H */