Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
apr_arch_inherit.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 #ifndef INHERIT_H
18 #define INHERIT_H
19 
20 #include "apr_inherit.h"
21 
22 #define APR_INHERIT (1 << 24) /* Must not conflict with other bits */
23 
24 #if APR_HAS_UNICODE_FS && APR_HAS_ANSI_FS
25 /* !defined(_WIN32_WCE) is implicit here */
26 
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) \
29 { \
30  IF_WIN_OS_IS_UNICODE \
31  { \
32 /* if (!SetHandleInformation(the##name->filehand, \
33  * HANDLE_FLAG_INHERIT, \
34  * HANDLE_FLAG_INHERIT)) \
35  * return apr_get_os_error(); \
36  */ } \
37  ELSE_WIN_OS_IS_ANSI \
38  { \
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; \
46  } \
47  return APR_SUCCESS; \
48 }
49 
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)\
52 { \
53  IF_WIN_OS_IS_UNICODE \
54  { \
55 /* if (!SetHandleInformation(the##name->filehand, \
56  * HANDLE_FLAG_INHERIT, 0)) \
57  * return apr_get_os_error(); \
58  */ } \
59  ELSE_WIN_OS_IS_ANSI \
60  { \
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; \
68  } \
69  return APR_SUCCESS; \
70 }
71 
72 #elif APR_HAS_ANSI_FS || defined(_WIN32_WCE)
73 
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) \
76 { \
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; \
84  return APR_SUCCESS; \
85 }
86 
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)\
89 { \
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; \
97  return APR_SUCCESS; \
98 }
99 
100 #else /* APR_HAS_UNICODE_FS && !APR_HAS_ANSI_FS && !defined(_WIN32_WCE) */
101 
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) \
104 { \
105 /* if (!SetHandleInformation(the##name->filehand, \
106  * HANDLE_FLAG_INHERIT, \
107  * HANDLE_FLAG_INHERIT)) \
108  * return apr_get_os_error(); \
109  */ return APR_SUCCESS; \
110 }
111 
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)\
114 { \
115 /* if (!SetHandleInformation(the##name->filehand, \
116  * HANDLE_FLAG_INHERIT, 0)) \
117  * return apr_get_os_error(); \
118  */ return APR_SUCCESS; \
119 }
120 
121 #endif /* defined(APR_HAS_UNICODE_FS) */
122 
123 #endif /* ! INHERIT_H */
APR File Handle Inheritance Helpers.