Skip to content

Commit c594704

Browse files
committed
[Issue #62] Replace pgwin32_safestat with fio_safestat
1 parent 84c6fd4 commit c594704

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/utils/file.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,41 @@ static bool fio_is_remote_fd(int fd)
5151
}
5252

5353
#ifdef WIN32
54+
55+
#undef stat
56+
57+
/*
58+
* The stat() function in win32 is not guaranteed to update the st_size
59+
* field when run. So we define our own version that uses the Win32 API
60+
* to update this field.
61+
*/
62+
static int
63+
fio_safestat(const char *path, struct stat *buf)
64+
{
65+
int r;
66+
WIN32_FILE_ATTRIBUTE_DATA attr;
67+
68+
r = stat(path, buf);
69+
if (r < 0)
70+
return r;
71+
72+
if (!GetFileAttributesEx(path, GetFileExInfoStandard, &attr))
73+
{
74+
errno = ENOENT;
75+
return -1;
76+
}
77+
78+
/*
79+
* XXX no support for large files here, but we don't do that in general on
80+
* Win32 yet.
81+
*/
82+
buf->st_size = attr.nFileSizeLow;
83+
84+
return 0;
85+
}
86+
87+
#define stat(x) fio_safestat(x)
88+
5489
static ssize_t pread(int fd, void* buf, size_t size, off_t off)
5590
{
5691
off_t rc = lseek(fd, off, SEEK_SET);

0 commit comments

Comments
 (0)