From 242f84cd211a13c4056d228aaa9bc1f57aa21763 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Tue, 14 May 2013 16:26:29 +0300 Subject: Fix building, installing, and testing extensions on MS-Windows. test/Makefile.in (mpfr-tests, shlib-tests): Add a blank character between ' and /FOO/ in Gawk command lines, for the benefit of testing under MSYS Bash. test/filefuncs.awk (BEGIN): Call 'stat' on gawkapi.o, not on gawk, which does not exist on systems that produce gawk.exe. README_D/README.pc: Update the pc build and test instructions. pc/Makefile.tst (AWK): Set AWKLIBPATH so extensions could be found. (LS): New variable. (check): Add back shlib-tests and shlib-msg-end. (readdir): Add a warning regarding inode reporting by ls.exe. (fts, fork, fork2): Add message about expected failure on MinGW. pc/Makefile (install): Install the extensions. (install-strip): Likewise. pc/Makefile.ext: New file. io.c (devopen) [__EMX__ || __MINGW32__]: Produce EISDIR on MinGW when an attempt to open() a directory fails. (two_way_open) [__EMX__ || __MINGW32__]: When trying to open() a directory fails with EISDIR, assign FAKE_FD_VALUE to the file descriptor and attributes of a directory to its mode bits. This is needed to support the readdir extension. gawkapi.h (FAKE_FD_VALUE): New macro, used in io.h and in extension/gawkdirfd.h. extension/rwarray.c [__MINGW32__]: Include winsock2.h instead of arpa/inet.h. extension/readdir.c [__MINGW32__]: Include windows.h. Include gawkapi.h before gawkdirfd.h, since the former defines FAKE_FD_VALUE needed by the latter. (ftype): Accept an additional argument, the directory that is being read. Callers changed. [!DT_BLK]: Produce the file's type by calling 'stat' on it, if the dirent structure doesn't provide that. (get_inode): New function, to produce inode values on MS-Windows. (dir_get_record): Use it. extension/inplace.c (chown, link) [__MINGW32__]: Redirect to existing library functions. (mkstemp) [__MINGW32__]: New function, for MinGW, which doesn't have it in its library. (do_inplace_end) [__MINGW32__]: Remove the old file before renaming the new, since 'rename' on Windows cannot overwrite existing files. extension/gawkdirfd.h (ENOTSUP): Define to ENOSYS if not already defined. (DIR_TO_FD): If not defined yet, define to FAKE_FD_VALUE. extension/filefuncs.c (get_inode) [_WIN32]: New function, produces the file index used on Windows as its inode. (fill_stat_array) [_WIN32]: Use it. --- extension/filefuncs.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'extension/filefuncs.c') diff --git a/extension/filefuncs.c b/extension/filefuncs.c index 1e8fc8d0..277bb45f 100644 --- a/extension/filefuncs.c +++ b/extension/filefuncs.c @@ -73,6 +73,29 @@ #define S_ISVTX 0 #define major(s) (s) #define minor(s) (0) + +#include + +/* get_inode --- get the inode of a file */ +static long long +get_inode(const char *fname) +{ + HANDLE fh; + BY_HANDLE_FILE_INFORMATION info; + + fh = CreateFile(fname, 0, 0, NULL, OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (fh == INVALID_HANDLE_VALUE) + return 0; + if (GetFileInformationByHandle(fh, &info)) { + long long inode = info.nFileIndexHigh; + + inode <<= 32; + inode += info.nFileIndexLow; + return inode; + } + return 0; +} #endif static const gawk_api_t *api; /* for convenience macros to work */ @@ -302,7 +325,11 @@ fill_stat_array(const char *name, awk_array_t array, struct stat *sbuf) /* fill in the array */ array_set(array, "name", make_const_string(name, strlen(name), & tmp)); array_set_numeric(array, "dev", sbuf->st_dev); +#ifdef _WIN32 + array_set_numeric(array, "ino", (double)get_inode (name)); +#else array_set_numeric(array, "ino", sbuf->st_ino); +#endif array_set_numeric(array, "mode", sbuf->st_mode); array_set_numeric(array, "nlink", sbuf->st_nlink); array_set_numeric(array, "uid", sbuf->st_uid); -- cgit v1.2.3 From c029f5b16321d66b646f1d41a7bd4cf453c1cfff Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 16 May 2013 10:26:37 +0300 Subject: Add stat blocksize of 4096 for Windows. --- extension/filefuncs.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'extension/filefuncs.c') diff --git a/extension/filefuncs.c b/extension/filefuncs.c index 277bb45f..5117b32f 100644 --- a/extension/filefuncs.c +++ b/extension/filefuncs.c @@ -353,6 +353,8 @@ fill_stat_array(const char *name, awk_array_t array, struct stat *sbuf) #ifdef HAVE_ST_BLKSIZE array_set_numeric(array, "blksize", sbuf->st_blksize); +#elif defined(_WIN32) + array_set_numeric(array, "blksize", 4096); #endif /* HAVE_ST_BLKSIZE */ pmode = format_mode(sbuf->st_mode); -- cgit v1.2.3