added create_hard_link()
@@ -51,6 +51,13 @@ | ||
51 | 51 | return ::SetFileAttributesA(ph, dwFileAttributes); |
52 | 52 | } |
53 | 53 | |
54 | +#if (_WIN32_WINNT >= 0x500) | |
55 | +inline BOOL create_hard_link(const char* from_ph, const char* to_ph) | |
56 | +{ | |
57 | + return ::CreateHardLinkA(from_ph, to_ph, 0); | |
58 | +} | |
59 | +#endif | |
60 | + | |
54 | 61 | } } } // End namespaces detail, filesystem, hamigaki. |
55 | 62 | |
56 | 63 | #endif // HAMIGAKI_FILESYSTEM_WINDOWS_NARROW_FUNCTIONS_HPP |
@@ -52,6 +52,13 @@ | ||
52 | 52 | return ::SetFileAttributesW(ph, dwFileAttributes); |
53 | 53 | } |
54 | 54 | |
55 | +#if (_WIN32_WINNT >= 0x500) | |
56 | +inline BOOL create_hard_link(const wchar_t* from_ph, const wchar_t* to_ph) | |
57 | +{ | |
58 | + return ::CreateHardLinkW(from_ph, to_ph, 0); | |
59 | +} | |
60 | +#endif | |
61 | + | |
55 | 62 | } } } // End namespaces detail, filesystem, hamigaki. |
56 | 63 | |
57 | 64 | #endif // HAMIGAKI_FILESYSTEM_WINDOWS_WIDE_FUNCTIONS_HPP |
@@ -302,6 +302,20 @@ | ||
302 | 302 | |
303 | 303 | template<class String> |
304 | 304 | inline error_code |
305 | +create_hard_link_template(const String& to_ph, const String& from_ph) | |
306 | +{ | |
307 | +#if (_WIN32_WINNT >= 0x500) | |
308 | + if (detail::create_hard_link(from_ph.c_str(), to_ph.c_str())) | |
309 | + return error_code(); | |
310 | + else | |
311 | + return last_error(); | |
312 | +#else | |
313 | + return make_error_code(ERROR_NOT_SUPPORTED); | |
314 | +#endif | |
315 | +} | |
316 | + | |
317 | +template<class String> | |
318 | +inline error_code | |
305 | 319 | create_file_symlink_template(const String& to_ph, const String& from_ph) |
306 | 320 | { |
307 | 321 | #if defined(HAMIGAKI_FILESYSTEM_USE_REPARSE_POINT) |
@@ -66,6 +66,9 @@ | ||
66 | 66 | |
67 | 67 | |
68 | 68 | HAMIGAKI_FILESYSTEM_DECL error_code |
69 | +create_hard_link_api(const std::wstring& to_ph, const std::wstring& from_ph); | |
70 | + | |
71 | +HAMIGAKI_FILESYSTEM_DECL error_code | |
69 | 72 | create_file_symlink_api(const std::wstring& to_ph, const std::wstring& from_ph); |
70 | 73 | |
71 | 74 | HAMIGAKI_FILESYSTEM_DECL error_code |
@@ -118,6 +121,9 @@ | ||
118 | 121 | |
119 | 122 | |
120 | 123 | HAMIGAKI_FILESYSTEM_DECL error_code |
124 | +create_hard_link_api(const std::string& to_ph, const std::string& from_ph); | |
125 | + | |
126 | +HAMIGAKI_FILESYSTEM_DECL error_code | |
121 | 127 | create_file_symlink_api(const std::string& to_ph, const std::string& from_ph); |
122 | 128 | |
123 | 129 | HAMIGAKI_FILESYSTEM_DECL error_code |
@@ -238,6 +244,26 @@ | ||
238 | 244 | |
239 | 245 | |
240 | 246 | HAMIGAKI_FS_FUNC(void) |
247 | +create_hard_link(const Path& to_ph, const Path& from_ph) | |
248 | +{ | |
249 | + const error_code& ec = detail::create_hard_link_api( | |
250 | + to_ph.external_file_string(), from_ph.external_file_string()); | |
251 | + if (ec) | |
252 | + { | |
253 | + throw boost::filesystem::basic_filesystem_error<Path>( | |
254 | + "hamigaki::filesystem::create_hard_link", to_ph, from_ph, ec); | |
255 | + } | |
256 | +} | |
257 | + | |
258 | +HAMIGAKI_FS_FUNC(error_code) | |
259 | +create_hard_link(const Path& to_ph, const Path& from_ph, error_code& ec) | |
260 | +{ | |
261 | + ec = detail::create_hard_link_api( | |
262 | + to_ph.external_file_string(), from_ph.external_file_string()); | |
263 | + return ec; | |
264 | +} | |
265 | + | |
266 | +HAMIGAKI_FS_FUNC(void) | |
241 | 267 | create_file_symlink(const Path& to_ph, const Path& from_ph) |
242 | 268 | { |
243 | 269 | const error_code& ec = detail::create_file_symlink_api( |
@@ -245,8 +271,7 @@ | ||
245 | 271 | if (ec) |
246 | 272 | { |
247 | 273 | throw boost::filesystem::basic_filesystem_error<Path>( |
248 | - "hamigaki::filesystem::create_file_symlink", | |
249 | - to_ph, from_ph, ec); | |
274 | + "hamigaki::filesystem::create_file_symlink", to_ph, from_ph, ec); | |
250 | 275 | } |
251 | 276 | } |
252 | 277 |
@@ -475,6 +500,26 @@ | ||
475 | 500 | } |
476 | 501 | |
477 | 502 | |
503 | +inline void create_hard_link(const path& to_ph, const path& from_ph) | |
504 | +{ | |
505 | + hamigaki::filesystem::create_hard_link<path>(to_ph, from_ph); | |
506 | +} | |
507 | +inline void create_hard_link(const wpath& to_ph, const wpath& from_ph) | |
508 | +{ | |
509 | + hamigaki::filesystem::create_hard_link<wpath>(to_ph, from_ph); | |
510 | +} | |
511 | + | |
512 | +inline error_code | |
513 | +create_hard_link(const path& to_ph, const path& from_ph, error_code& ec) | |
514 | +{ | |
515 | + return hamigaki::filesystem::create_hard_link<path>(to_ph, from_ph, ec); | |
516 | +} | |
517 | +inline error_code | |
518 | +create_hard_link(const wpath& to_ph, const wpath& from_ph, error_code& ec) | |
519 | +{ | |
520 | + return hamigaki::filesystem::create_hard_link<wpath>(to_ph, from_ph, ec); | |
521 | +} | |
522 | + | |
478 | 523 | inline void create_file_symlink(const path& to_ph, const path& from_ph) |
479 | 524 | { |
480 | 525 | hamigaki::filesystem::create_file_symlink<path>(to_ph, from_ph); |