Skip to content

Commit 180964f

Browse files
Johannes Sixtgitster
authored andcommitted
Revert "Windows: Use a customized struct stat that also has the st_blocks member."
This reverts commit fc2ded5. As we do not need the member in struct stat, we do not need to have a custom "struct mingw_stat" anymore. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent fdb2a2a commit 180964f

File tree

2 files changed

+11
-32
lines changed

2 files changed

+11
-32
lines changed

compat/mingw.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ static int do_lstat(const char *file_name, struct stat *buf)
5252
buf->st_ino = 0;
5353
buf->st_gid = 0;
5454
buf->st_uid = 0;
55+
buf->st_nlink = 1;
5556
buf->st_mode = fMode;
5657
buf->st_size = fdata.nFileSizeLow; /* Can't use nFileSizeHigh, since it's not a stat64 */
57-
buf->st_dev = _getdrive() - 1;
58+
buf->st_dev = buf->st_rdev = (_getdrive() - 1);
5859
buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
5960
buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
6061
buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime));
@@ -88,7 +89,7 @@ static int do_lstat(const char *file_name, struct stat *buf)
8889
* complete. Note that Git stat()s are redirected to mingw_lstat()
8990
* too, since Windows doesn't really handle symlinks that well.
9091
*/
91-
int mingw_lstat(const char *file_name, struct mingw_stat *buf)
92+
int mingw_lstat(const char *file_name, struct stat *buf)
9293
{
9394
int namelen;
9495
static char alt_name[PATH_MAX];
@@ -116,8 +117,7 @@ int mingw_lstat(const char *file_name, struct mingw_stat *buf)
116117
}
117118

118119
#undef fstat
119-
#undef stat
120-
int mingw_fstat(int fd, struct mingw_stat *buf)
120+
int mingw_fstat(int fd, struct stat *buf)
121121
{
122122
HANDLE fh = (HANDLE)_get_osfhandle(fd);
123123
BY_HANDLE_FILE_INFORMATION fdata;
@@ -127,21 +127,8 @@ int mingw_fstat(int fd, struct mingw_stat *buf)
127127
return -1;
128128
}
129129
/* direct non-file handles to MS's fstat() */
130-
if (GetFileType(fh) != FILE_TYPE_DISK) {
131-
struct stat st;
132-
if (fstat(fd, &st))
133-
return -1;
134-
buf->st_ino = st.st_ino;
135-
buf->st_gid = st.st_gid;
136-
buf->st_uid = st.st_uid;
137-
buf->st_mode = st.st_mode;
138-
buf->st_size = st.st_size;
139-
buf->st_dev = st.st_dev;
140-
buf->st_atime = st.st_atime;
141-
buf->st_mtime = st.st_mtime;
142-
buf->st_ctime = st.st_ctime;
143-
return 0;
144-
}
130+
if (GetFileType(fh) != FILE_TYPE_DISK)
131+
return fstat(fd, buf);
145132

146133
if (GetFileInformationByHandle(fh, &fdata)) {
147134
int fMode = S_IREAD;
@@ -155,9 +142,10 @@ int mingw_fstat(int fd, struct mingw_stat *buf)
155142
buf->st_ino = 0;
156143
buf->st_gid = 0;
157144
buf->st_uid = 0;
145+
buf->st_nlink = 1;
158146
buf->st_mode = fMode;
159147
buf->st_size = fdata.nFileSizeLow; /* Can't use nFileSizeHigh, since it's not a stat64 */
160-
buf->st_dev = _getdrive() - 1;
148+
buf->st_dev = buf->st_rdev = (_getdrive() - 1);
161149
buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
162150
buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
163151
buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime));

compat/mingw.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,12 @@ int mingw_rename(const char*, const char*);
162162

163163
/* Use mingw_lstat() instead of lstat()/stat() and
164164
* mingw_fstat() instead of fstat() on Windows.
165-
* struct stat is redefined because it lacks the st_blocks member.
166165
*/
167-
struct mingw_stat {
168-
unsigned st_mode;
169-
time_t st_mtime, st_atime, st_ctime;
170-
unsigned st_dev, st_ino, st_uid, st_gid;
171-
size_t st_size;
172-
};
173-
int mingw_lstat(const char *file_name, struct mingw_stat *buf);
174-
int mingw_fstat(int fd, struct mingw_stat *buf);
166+
int mingw_lstat(const char *file_name, struct stat *buf);
167+
int mingw_fstat(int fd, struct stat *buf);
175168
#define fstat mingw_fstat
176169
#define lstat mingw_lstat
177-
#define stat mingw_stat
178-
static inline int mingw_stat(const char *file_name, struct mingw_stat *buf)
179-
{ return mingw_lstat(file_name, buf); }
170+
#define stat(x,y) mingw_lstat(x,y)
180171

181172
int mingw_utime(const char *file_name, const struct utimbuf *times);
182173
#define utime mingw_utime

0 commit comments

Comments
 (0)