aboutsummaryrefslogtreecommitdiffstats
path: root/extension/inplace.c
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2013-05-14 16:26:29 +0300
committerEli Zaretskii <eliz@gnu.org>2013-05-14 16:26:29 +0300
commit242f84cd211a13c4056d228aaa9bc1f57aa21763 (patch)
tree8be4635902df1dde1c21e6ca9cb457a2860c73ff /extension/inplace.c
parentc96323b5e32f54295556809833d2d6a44daa75d0 (diff)
downloadegawk-242f84cd211a13c4056d228aaa9bc1f57aa21763.tar.gz
egawk-242f84cd211a13c4056d228aaa9bc1f57aa21763.tar.bz2
egawk-242f84cd211a13c4056d228aaa9bc1f57aa21763.zip
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.
Diffstat (limited to 'extension/inplace.c')
-rw-r--r--extension/inplace.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/extension/inplace.c b/extension/inplace.c
index ded4746c..ad6f0e23 100644
--- a/extension/inplace.c
+++ b/extension/inplace.c
@@ -51,6 +51,20 @@
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif
+#ifdef __MINGW32__
+# define chown(x,y,z) (0)
+# define link(f1,f2) rename(f1,f2)
+int
+mkstemp (char *template)
+{
+ char *tmp_fname = _mktemp (template);
+
+ if (tmp_fname)
+ return _open (tmp_fname, O_RDWR | O_CREAT | O_EXCL, S_IREAD | S_IWRITE);
+ return -1;
+}
+#endif
+
static const gawk_api_t *api; /* for convenience macros to work */
static awk_ext_id_t *ext_id;
static const char *ext_version = "inplace extension: version 1.0";
@@ -225,6 +239,10 @@ do_inplace_end(int nargs, awk_value_t *result)
free(bakname);
}
+#ifdef __MINGW32__
+ unlink(filename.str_value.str);
+#endif
+
if (rename(state.tname, filename.str_value.str) < 0)
fatal(ext_id, _("inplace_end: rename(`%s', `%s') failed (%s)"),
state.tname, filename.str_value.str, strerror(errno));