aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2014-01-07 14:43:08 +0000
committerRon Yorston <rmy@pobox.com>2014-01-07 14:43:08 +0000
commit94150aba92d308e417aa552a1b3a957be264b423 (patch)
treed9b570e2641188c68917e85d7cb387fe0bbfbecc /win32
parent63b71e4a6f8c65a4bef7617efb50a2b473e388b3 (diff)
downloadbusybox-w32-94150aba92d308e417aa552a1b3a957be264b423.tar.gz
busybox-w32-94150aba92d308e417aa552a1b3a957be264b423.tar.bz2
busybox-w32-94150aba92d308e417aa552a1b3a957be264b423.zip
Revise mingw_stat to minimise changes from upstream BusyBox
Diffstat (limited to 'win32')
-rw-r--r--win32/mingw.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index 7dda6cd1b..b9f720e1a 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -212,7 +212,7 @@ static inline int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fd
212 * If follow is true then act like stat() and report on the link 212 * If follow is true then act like stat() and report on the link
213 * target. Otherwise report on the link itself. 213 * target. Otherwise report on the link itself.
214 */ 214 */
215static int do_lstat(int follow, const char *file_name, struct stat *buf) 215static int do_lstat(int follow, const char *file_name, struct mingw_stat *buf)
216{ 216{
217 int err; 217 int err;
218 WIN32_FILE_ATTRIBUTE_DATA fdata; 218 WIN32_FILE_ATTRIBUTE_DATA fdata;
@@ -253,6 +253,13 @@ static int do_lstat(int follow, const char *file_name, struct stat *buf)
253 FindClose(handle); 253 FindClose(handle);
254 } 254 }
255 } 255 }
256
257 /*
258 * Assume a block is 4096 bytes and calculate number of 512 byte
259 * sectors.
260 */
261 buf->st_blksize = 4096;
262 buf->st_blocks = ((buf->st_size+4095)>>12)<<3;
256 return 0; 263 return 0;
257 } 264 }
258 errno = err; 265 errno = err;
@@ -265,7 +272,7 @@ static int do_lstat(int follow, const char *file_name, struct stat *buf)
265 * complete. Note that Git stat()s are redirected to mingw_lstat() 272 * complete. Note that Git stat()s are redirected to mingw_lstat()
266 * too, since Windows doesn't really handle symlinks that well. 273 * too, since Windows doesn't really handle symlinks that well.
267 */ 274 */
268static int do_stat_internal(int follow, const char *file_name, struct stat *buf) 275static int do_stat_internal(int follow, const char *file_name, struct mingw_stat *buf)
269{ 276{
270 int namelen; 277 int namelen;
271 static char alt_name[PATH_MAX]; 278 static char alt_name[PATH_MAX];
@@ -292,17 +299,16 @@ static int do_stat_internal(int follow, const char *file_name, struct stat *buf)
292 return do_lstat(follow, alt_name, buf); 299 return do_lstat(follow, alt_name, buf);
293} 300}
294 301
295int mingw_lstat(const char *file_name, struct stat *buf) 302int mingw_lstat(const char *file_name, struct mingw_stat *buf)
296{ 303{
297 return do_stat_internal(0, file_name, buf); 304 return do_stat_internal(0, file_name, buf);
298} 305}
299int mingw_stat(const char *file_name, struct stat *buf) 306int mingw_stat(const char *file_name, struct mingw_stat *buf)
300{ 307{
301 return do_stat_internal(1, file_name, buf); 308 return do_stat_internal(1, file_name, buf);
302} 309}
303 310
304#undef fstat 311int mingw_fstat(int fd, struct mingw_stat *buf)
305int mingw_fstat(int fd, struct stat *buf)
306{ 312{
307 HANDLE fh = (HANDLE)_get_osfhandle(fd); 313 HANDLE fh = (HANDLE)_get_osfhandle(fd);
308 BY_HANDLE_FILE_INFORMATION fdata; 314 BY_HANDLE_FILE_INFORMATION fdata;
@@ -312,8 +318,26 @@ int mingw_fstat(int fd, struct stat *buf)
312 return -1; 318 return -1;
313 } 319 }
314 /* direct non-file handles to MS's fstat() */ 320 /* direct non-file handles to MS's fstat() */
315 if (GetFileType(fh) != FILE_TYPE_DISK) 321 if (GetFileType(fh) != FILE_TYPE_DISK) {
316 return _fstati64(fd, buf); 322 struct _stati64 buf64;
323
324 if ( _fstati64(fd, &buf64) != 0 ) {
325 return -1;
326 }
327 buf->st_dev = 0;
328 buf->st_ino = 0;
329 buf->st_mode = S_IREAD|S_IWRITE;
330 buf->st_nlink = 1;
331 buf->st_uid = 0;
332 buf->st_gid = 0;
333 buf->st_rdev = 0;
334 buf->st_size = buf64.st_size;
335 buf->st_atime = buf64.st_atime;
336 buf->st_mtime = buf64.st_mtime;
337 buf->st_ctime = buf64.st_ctime;
338 buf->st_blksize = 4096;
339 buf->st_blocks = ((buf64.st_size+4095)>>12)<<3;
340 }
317 341
318 if (GetFileInformationByHandle(fh, &fdata)) { 342 if (GetFileInformationByHandle(fh, &fdata)) {
319 buf->st_ino = 0; 343 buf->st_ino = 0;
@@ -327,6 +351,8 @@ int mingw_fstat(int fd, struct stat *buf)
327 buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime)); 351 buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
328 buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime)); 352 buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
329 buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime)); 353 buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime));
354 buf->st_blksize = 4096;
355 buf->st_blocks = ((buf->st_size+4095)>>12)<<3;
330 return 0; 356 return 0;
331 } 357 }
332 errno = EBADF; 358 errno = EBADF;