Project

General

Profile

RE: Exiv2 and hard links ยป GetFileInformationByHandle.patch

Andreas Huggel, 09 Feb 2012 08:11

View differences:

src/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
            BY_HANDLE_FILE_INFORMATION fi;
256
            if (GetFileInformationByHandle(hFd, &fi)) {
257
                if (fi.nNumberOfLinks > 1) {
258
                    buf.st_nlink = static_cast<nlink_t>(fi.nNumberOfLinks);
259
                }
260
            }
261
#ifdef DEBUG
262
            else EXV_DEBUG << "GetFileInformationByHandle failed\n";
263
#endif
264
        }
265
#ifdef DEBUG
266
        else EXV_DEBUG << "_get_osfhandle failed: INVALID_HANDLE_VALUE\n";
267
#endif
268
#endif // defined WIN32 && !defined __CYGWIN__
269

  
249 270
        return ret;
250 271
    } // FileIo::Impl::stat
251 272

  
    (1-1/1)