You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

194 lines
6.3 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/filesystem/file_creation_functions.h
  3. *
  4. * Purpose: File creation functions.
  5. *
  6. * Created: 12th September 2005
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2005-2009, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file winstl/filesystem/file_creation_functions.h
  40. *
  41. * \brief [C, C++] File creation functions
  42. * (\ref group__library__filesystem "File System" Library).
  43. */
  44. #ifndef WINSTL_INCL_WINSTL_H_FILE_CREATION_FUNCTIONS
  45. #define WINSTL_INCL_WINSTL_H_FILE_CREATION_FUNCTIONS
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define WINSTL_VER_WINSTL_H_FILE_CREATION_FUNCTIONS_MAJOR 2
  48. # define WINSTL_VER_WINSTL_H_FILE_CREATION_FUNCTIONS_MINOR 0
  49. # define WINSTL_VER_WINSTL_H_FILE_CREATION_FUNCTIONS_REVISION 1
  50. # define WINSTL_VER_WINSTL_H_FILE_CREATION_FUNCTIONS_EDIT 13
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Includes
  54. */
  55. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  56. # include <winstl/winstl.h>
  57. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  58. /* /////////////////////////////////////////////////////////////////////////
  59. * Namespace
  60. */
  61. #if !defined(_WINSTL_NO_NAMESPACE) && \
  62. !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  63. # if defined(_STLSOFT_NO_NAMESPACE)
  64. /* There is no stlsoft namespace, so must define ::winstl */
  65. namespace winstl
  66. {
  67. # else
  68. /* Define stlsoft::winstl_project */
  69. namespace stlsoft
  70. {
  71. namespace winstl_project
  72. {
  73. # endif /* _STLSOFT_NO_NAMESPACE */
  74. #endif /* !_WINSTL_NO_NAMESPACE */
  75. /* /////////////////////////////////////////////////////////////////////////
  76. * C functions
  77. */
  78. /** \brief Opens an existing file for shared read access.
  79. *
  80. * \ingroup group__library__filesystem
  81. */
  82. STLSOFT_INLINE HANDLE winstl__open_file_read_shared_a(ws_char_a_t const* fileName, DWORD dwShareMode)
  83. {
  84. return STLSOFT_NS_GLOBAL(CreateFileA)(fileName, GENERIC_READ, dwShareMode, NULL, OPEN_ALWAYS, 0, NULL);
  85. }
  86. /** \brief Opens an existing file for shared read access.
  87. *
  88. * \ingroup group__library__filesystem
  89. */
  90. STLSOFT_INLINE HANDLE winstl__open_file_read_shared_w(ws_char_w_t const* fileName, DWORD dwShareMode)
  91. {
  92. return STLSOFT_NS_GLOBAL(CreateFileW)(fileName, GENERIC_READ, dwShareMode, NULL, OPEN_ALWAYS, 0, NULL);
  93. }
  94. /** \brief Opens an existing file for exclusive read access.
  95. *
  96. * \ingroup group__library__filesystem
  97. */
  98. STLSOFT_INLINE HANDLE winstl__open_file_exclusive_a(ws_char_a_t const* fileName)
  99. {
  100. return STLSOFT_NS_GLOBAL(CreateFileA)(fileName, GENERIC_READ, 0, NULL, OPEN_ALWAYS, 0, NULL);
  101. }
  102. /** \brief Opens an existing file for exclusive read access.
  103. *
  104. * \ingroup group__library__filesystem
  105. */
  106. STLSOFT_INLINE HANDLE winstl__open_file_exclusive_w(ws_char_w_t const* fileName)
  107. {
  108. return STLSOFT_NS_GLOBAL(CreateFileW)(fileName, GENERIC_READ, 0, NULL, OPEN_ALWAYS, 0, NULL);
  109. }
  110. /* /////////////////////////////////////////////////////////////////////////
  111. * Namespace
  112. */
  113. #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
  114. namespace winstl
  115. {
  116. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  117. /* /////////////////////////////////////////////////////////////////////////
  118. * C++ functions
  119. */
  120. #ifdef __cplusplus
  121. /** \brief Opens an existing file for shared read access.
  122. *
  123. * \ingroup group__library__filesystem
  124. */
  125. inline HANDLE open_file_read_shared(ws_char_a_t const* fileName, DWORD dwShareMode)
  126. {
  127. return winstl__open_file_read_shared_a(fileName, dwShareMode);
  128. }
  129. /** \brief Opens an existing file for shared read access.
  130. *
  131. * \ingroup group__library__filesystem
  132. */
  133. inline HANDLE open_file_read_shared(ws_char_w_t const* fileName, DWORD dwShareMode)
  134. {
  135. return winstl__open_file_read_shared_w(fileName, dwShareMode);
  136. }
  137. /** \brief Opens an existing file for exclusive read access.
  138. *
  139. * \ingroup group__library__filesystem
  140. */
  141. inline HANDLE open_file_exclusive(ws_char_a_t const* fileName)
  142. {
  143. return winstl__open_file_exclusive_a(fileName);
  144. }
  145. /** \brief Opens an existing file for exclusive read access.
  146. *
  147. * \ingroup group__library__filesystem
  148. */
  149. inline HANDLE open_file_exclusive(ws_char_w_t const* fileName)
  150. {
  151. return winstl__open_file_exclusive_w(fileName);
  152. }
  153. #endif /* __cplusplus */
  154. /* ////////////////////////////////////////////////////////////////////// */
  155. #ifndef _WINSTL_NO_NAMESPACE
  156. # if defined(_STLSOFT_NO_NAMESPACE) || \
  157. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  158. } /* namespace winstl */
  159. # else
  160. } /* namespace winstl_project */
  161. } /* namespace stlsoft */
  162. # endif /* _STLSOFT_NO_NAMESPACE */
  163. #endif /* !_WINSTL_NO_NAMESPACE */
  164. /* ////////////////////////////////////////////////////////////////////// */
  165. #endif /* WINSTL_INCL_WINSTL_H_FILE_CREATION_FUNCTIONS */
  166. /* ///////////////////////////// end of file //////////////////////////// */