diff --git a/contrib/win32/win32compat/fileio.c b/contrib/win32/win32compat/fileio.c index 4c01f6c..14521fa 100644 --- a/contrib/win32/win32compat/fileio.c +++ b/contrib/win32/win32compat/fileio.c @@ -487,10 +487,7 @@ fileio_write(struct w32_io* pio, const void *buf, unsigned int max) { /* fstat() implemetation */ int -fileio_fstat(struct w32_io* pio, struct stat *buf) { - - errno = ENOTSUP; - return -1; +fileio_fstat(struct w32_io* pio, struct _stat64 *buf) { int fd = _open_osfhandle((intptr_t)pio->handle, 0); debug2("pio:%p", pio); @@ -499,13 +496,18 @@ fileio_fstat(struct w32_io* pio, struct stat *buf) { return -1; } - return _fstat(fd, (struct _stat*)&buf); + return _fstat64(fd, buf); } /* isatty() implementation */ int fileio_isatty(struct w32_io* pio) { - return (GetFileType(pio->handle) == FILE_TYPE_CHAR) ? TRUE : FALSE; + if (GetFileType(pio->handle) == FILE_TYPE_CHAR) + return 1; + else { + errno = EINVAL; + return 0; + } } /* fdopen implementation */ diff --git a/contrib/win32/win32compat/inc/sys/stat.h b/contrib/win32/win32compat/inc/sys/stat.h new file mode 100644 index 0000000..455c5d1 --- /dev/null +++ b/contrib/win32/win32compat/inc/sys/stat.h @@ -0,0 +1,43 @@ +/* +* Author: Manoj Ampalam +* +* private stat.h (all code relying on POSIX wrapper should include this version +* instead of the one in Windows SDK. +*/ +#pragma once + +/* flags COPIED FROM STAT.H + */ +#define _S_IFMT 0xF000 // File type mask +#define _S_IFDIR 0x4000 // Directory +#define _S_IFCHR 0x2000 // Character special +#define _S_IFIFO 0x1000 // Pipe +#define _S_IFREG 0x8000 // Regular +#define _S_IREAD 0x0100 // Read permission, owner +#define _S_IWRITE 0x0080 // Write permission, owner +#define _S_IEXEC 0x0040 // Execute/search permission, owner + + +#define S_IFMT _S_IFMT +#define S_IFDIR _S_IFDIR +#define S_IFCHR _S_IFCHR +#define S_IFREG _S_IFREG +#define S_IREAD _S_IREAD +#define S_IWRITE _S_IWRITE +#define S_IEXEC _S_IEXEC + +#define stat w32_stat + +struct w32_stat { + dev_t st_dev; /* ID of device containing file */ + ino_t st_ino; /* inode number */ + unsigned short st_mode; /* protection */ + short st_nlink; /* number of hard links */ + short st_uid; /* user ID of owner */ + short st_gid; /* group ID of owner */ + dev_t st_rdev; /* device ID (if special file) */ + __int64 st_size; /* total size, in bytes */ + __int64 st_atime; /* time of last access */ + __int64 st_mtime; /* time of last modification */ + __int64 st_ctime; /* time of last status change */ +}; \ No newline at end of file diff --git a/contrib/win32/win32compat/inc/w32posix.h b/contrib/win32/win32compat/inc/w32posix.h index a294c0d..07f964e 100644 --- a/contrib/win32/win32compat/inc/w32posix.h +++ b/contrib/win32/win32compat/inc/w32posix.h @@ -45,7 +45,7 @@ int w32_pipe(int *pfds); int w32_open(const char *pathname, int flags, ...); int w32_read(int fd, void *dst, unsigned int max); int w32_write(int fd, const void *buf, unsigned int max); -int w32_fstat(int fd, struct stat *buf); +int w32_fstat(int fd, struct w32_stat *buf); int w32_isatty(int fd); FILE* w32_fdopen(int fd, const char *mode); diff --git a/contrib/win32/win32compat/w32fd.c b/contrib/win32/win32compat/w32fd.c index d6a2cc3..1e9b9f0 100644 --- a/contrib/win32/win32compat/w32fd.c +++ b/contrib/win32/win32compat/w32fd.c @@ -344,14 +344,17 @@ w32_write(int fd, const void *buf, unsigned int max) { } int -w32_fstat(int fd, struct stat *buf) { +w32_fstat(int fd, struct w32_stat *buf) { CHECK_FD(fd); - return fileio_fstat(fd_table.w32_ios[fd], buf); + return fileio_fstat(fd_table.w32_ios[fd], (struct _stat64*)buf); } int w32_isatty(int fd) { - CHECK_FD(fd); + if ((fd < 0) || (fd > MAX_FDS - 1) || fd_table.w32_ios[fd] == NULL) { + errno = EBADF; + return 0; + } return fileio_isatty(fd_table.w32_ios[fd]); } diff --git a/contrib/win32/win32compat/w32fd.h b/contrib/win32/win32compat/w32fd.h index e591c7d..12d3f09 100644 --- a/contrib/win32/win32compat/w32fd.h +++ b/contrib/win32/win32compat/w32fd.h @@ -113,7 +113,7 @@ int fileio_pipe(struct w32_io* pio[2]); struct w32_io* fileio_open(const char *pathname, int flags, int mode); int fileio_read(struct w32_io* pio, void *dst, unsigned int max); int fileio_write(struct w32_io* pio, const void *buf, unsigned int max); -int fileio_fstat(struct w32_io* pio, struct stat *buf); +int fileio_fstat(struct w32_io* pio, struct _stat64 *buf); int fileio_isatty(struct w32_io* pio); FILE* fileio_fdopen(struct w32_io* pio, const char *mode);