RE: Exiv2 and hard links ยป GetFileInformationByHandleDynamicLoad.patch
basicio.cpp (working copy) | ||
---|---|---|
61 | 61 |
# include <unistd.h> // for getpid, stat |
62 | 62 |
#endif |
63 | 63 | |
64 |
// MSVC doesn't provide mode_t |
|
64 |
// MSVC doesn't provide mode_t, nlink_t
|
|
65 | 65 |
#ifdef _MSC_VER |
66 | 66 |
typedef unsigned short mode_t; |
67 |
typedef short nlink_t; |
|
67 | 68 |
#endif |
68 | 69 | |
69 | 70 |
#if defined WIN32 && !defined __CYGWIN__ |
... | ... | |
246 | 247 |
buf.st_nlink = st.st_nlink; |
247 | 248 |
} |
248 | 249 |
} |
250 | ||
251 |
#if defined WIN32 && !defined __CYGWIN__ |
|
252 |
// Windows implementation to determine st_nlink (on NTFS) |
|
253 |
HANDLE hFd = (HANDLE)_get_osfhandle(fileno(fp_)); |
|
254 |
if (hFd != INVALID_HANDLE_VALUE) { |
|
255 |
typedef BOOL (WINAPI * GetFileInformationByHandle_t)(HANDLE, LPBY_HANDLE_FILE_INFORMATION); |
|
256 |
HMODULE hKernel = LoadLibrary("kernel32.dll"); |
|
257 |
if (hKernel) { |
|
258 |
GetFileInformationByHandle_t pfcn_GetFileInformationByHandle = (GetFileInformationByHandle_t)GetProcAddress(hKernel, "GetFileInformationByHandle"); |
|
259 |
if (pfcn_GetFileInformationByHandle) { |
|
260 |
BY_HANDLE_FILE_INFORMATION fi = {0}; |
|
261 |
if (pfcn_GetFileInformationByHandle(hFd, &fi)) { |
|
262 |
if (fi.nNumberOfLinks > 1) { |
|
263 |
buf.st_nlink = static_cast<nlink_t>(fi.nNumberOfLinks); |
|
264 |
} |
|
265 |
} |
|
266 |
#ifdef DEBUG |
|
267 |
else EXV_DEBUG << "GetFileInformationByHandle failed\n"; |
|
268 |
#endif |
|
269 |
} |
|
270 |
FreeLibrary(hKernel); |
|
271 |
} |
|
272 |
} |
|
273 |
#ifdef DEBUG |
|
274 |
else EXV_DEBUG << "_get_osfhandle failed: INVALID_HANDLE_VALUE\n"; |
|
275 |
#endif |
|
276 |
#endif // defined WIN32 && !defined __CYGWIN__ |
|
277 | ||
249 | 278 |
return ret; |
250 | 279 |
} // FileIo::Impl::stat |
251 | 280 |