fspr_arch_inherit.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #ifndef INHERIT_H
  17. #define INHERIT_H
  18. #include "fspr_inherit.h"
  19. #define APR_INHERIT (1 << 24) /* Must not conflict with other bits */
  20. #define APR_IMPLEMENT_INHERIT_SET(name, flag, pool, cleanup) \
  21. APR_DECLARE(fspr_status_t) fspr_##name##_inherit_set(fspr_##name##_t *the##name) \
  22. { \
  23. IF_WIN_OS_IS_UNICODE \
  24. { \
  25. if (!SetHandleInformation(the##name->filehand, \
  26. HANDLE_FLAG_INHERIT, \
  27. HANDLE_FLAG_INHERIT)) \
  28. return fspr_get_os_error(); \
  29. } \
  30. ELSE_WIN_OS_IS_ANSI \
  31. { \
  32. HANDLE temp, hproc = GetCurrentProcess(); \
  33. if (!DuplicateHandle(hproc, the##name->filehand, \
  34. hproc, &temp, 0, TRUE, \
  35. DUPLICATE_SAME_ACCESS)) \
  36. return fspr_get_os_error(); \
  37. CloseHandle(the##name->filehand); \
  38. the##name->filehand = temp; \
  39. } \
  40. return APR_SUCCESS; \
  41. }
  42. #define APR_IMPLEMENT_INHERIT_UNSET(name, flag, pool, cleanup) \
  43. APR_DECLARE(fspr_status_t) fspr_##name##_inherit_unset(fspr_##name##_t *the##name)\
  44. { \
  45. IF_WIN_OS_IS_UNICODE \
  46. { \
  47. if (!SetHandleInformation(the##name->filehand, \
  48. HANDLE_FLAG_INHERIT, 0)) \
  49. return fspr_get_os_error(); \
  50. } \
  51. ELSE_WIN_OS_IS_ANSI \
  52. { \
  53. HANDLE temp, hproc = GetCurrentProcess(); \
  54. if (!DuplicateHandle(hproc, the##name->filehand, \
  55. hproc, &temp, 0, FALSE, \
  56. DUPLICATE_SAME_ACCESS)) \
  57. return fspr_get_os_error(); \
  58. CloseHandle(the##name->filehand); \
  59. the##name->filehand = temp; \
  60. } \
  61. return APR_SUCCESS; \
  62. }
  63. #endif /* ! INHERIT_H */