diff options
Diffstat (limited to 'extension')
-rw-r--r-- | extension/ChangeLog | 43 | ||||
-rw-r--r-- | extension/Makefile.am | 5 | ||||
-rw-r--r-- | extension/Makefile.in | 33 | ||||
-rw-r--r-- | extension/configh.in | 7 | ||||
-rwxr-xr-x | extension/configure | 70 | ||||
-rw-r--r-- | extension/configure.ac | 2 | ||||
-rw-r--r-- | extension/filefuncs.c | 29 | ||||
-rw-r--r-- | extension/gawkdirfd.h | 8 | ||||
-rw-r--r-- | extension/inplace.c | 18 | ||||
-rw-r--r-- | extension/readdir.c | 86 | ||||
-rw-r--r-- | extension/rwarray.c | 4 |
11 files changed, 282 insertions, 23 deletions
diff --git a/extension/ChangeLog b/extension/ChangeLog index e01d6d14..66f7d355 100644 --- a/extension/ChangeLog +++ b/extension/ChangeLog @@ -1,3 +1,46 @@ +2013-05-16 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * Makefile.am (install-data-hook): Remove .la files installed by + Automake. Leaves less clutter, if not (yet) less noise. + +2013-05-16 Arnold D. Robbins <arnold@skeeve.com> + + * filefuncs.c (fill_stat_array): For _WIN32 use a blocksize of + 4096 for the "blksize" element, per Eli Zaretskii. + + * configure.ac [AC_STRUCT_ST_BLKSIZE]: Add call that was missing. + ARGH!!!! + +2013-05-14 Eli Zaretskii <eliz@gnu.org> + + * rwarray.c [__MINGW32__]: Include winsock2.h instead of + arpa/inet.h. + + * 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. + + * 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. + + * gawkdirfd.h (ENOTSUP): Define to ENOSYS if not already defined. + (DIR_TO_FD): If not defined yet, define to FAKE_FD_VALUE. + + * filefuncs.c (get_inode) [_WIN32]: New function, produces the + file index used on Windows as its inode. + (fill_stat_array) [_WIN32]: Use it. + 2013-05-09 Arnold D. Robbins <arnold@skeeve.com> * 4.1.0: Release tar ball made. diff --git a/extension/Makefile.am b/extension/Makefile.am index b51b6c06..7b52b14b 100644 --- a/extension/Makefile.am +++ b/extension/Makefile.am @@ -98,6 +98,11 @@ testext_la_SOURCES = testext.c testext_la_LDFLAGS = $(MY_MODULE_FLAGS) testext_la_LIBADD = $(MY_LIBS) +install-data-hook: + for i in $(pkgextension_LTLIBRARIES) ; do \ + $(RM) $(pkgextensiondir)/$$i ; \ + done + EXTRA_DIST = build-aux/config.rpath \ ChangeLog \ ChangeLog.0 \ diff --git a/extension/Makefile.in b/extension/Makefile.in index 1bd4750b..8d0a2869 100644 --- a/extension/Makefile.in +++ b/extension/Makefile.in @@ -1114,7 +1114,8 @@ info: info-recursive info-am: install-data-am: install-man install-pkgextensionLTLIBRARIES - + @$(NORMAL_INSTALL) + $(MAKE) $(AM_MAKEFLAGS) install-data-hook install-dvi: install-dvi-recursive install-dvi-am: @@ -1165,7 +1166,8 @@ uninstall-am: uninstall-man uninstall-pkgextensionLTLIBRARIES uninstall-man: uninstall-man3 -.MAKE: $(am__recursive_targets) all install-am install-strip +.MAKE: $(am__recursive_targets) all install-am install-data-am \ + install-strip .PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ am--refresh check check-am clean clean-cscope clean-generic \ @@ -1176,17 +1178,22 @@ uninstall-man: uninstall-man3 distclean-hdr distclean-libtool distclean-tags distcleancheck \ distdir distuninstallcheck dvi dvi-am html html-am info \ info-am install install-am install-data install-data-am \ - install-dvi install-dvi-am install-exec install-exec-am \ - install-html install-html-am install-info install-info-am \ - install-man install-man3 install-pdf install-pdf-am \ - install-pkgextensionLTLIBRARIES install-ps install-ps-am \ - install-strip installcheck installcheck-am installdirs \ - installdirs-am maintainer-clean maintainer-clean-generic \ - mostlyclean mostlyclean-compile mostlyclean-generic \ - mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ - uninstall-am uninstall-man uninstall-man3 \ - uninstall-pkgextensionLTLIBRARIES - + install-data-hook install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-man3 install-pdf \ + install-pdf-am install-pkgextensionLTLIBRARIES install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs installdirs-am maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags tags-am uninstall uninstall-am uninstall-man \ + uninstall-man3 uninstall-pkgextensionLTLIBRARIES + + +install-data-hook: + for i in $(pkgextension_LTLIBRARIES) ; do \ + $(RM) $(pkgextensiondir)/$$i ; \ + done # This is an ugly hack, initially for MirBSD but probably needed for other # systems. If gawk doesn't have the API built in, don't try to build the diff --git a/extension/configh.in b/extension/configh.in index 9162ce4d..cc84f4d0 100644 --- a/extension/configh.in +++ b/extension/configh.in @@ -87,6 +87,13 @@ /* Define to 1 if you have the <string.h> header file. */ #undef HAVE_STRING_H +/* Define to 1 if `st_blksize' is a member of `struct stat'. */ +#undef HAVE_STRUCT_STAT_ST_BLKSIZE + +/* Define to 1 if your `struct stat' has `st_blksize'. Deprecated, use + `HAVE_STRUCT_STAT_ST_BLKSIZE' instead. */ +#undef HAVE_ST_BLKSIZE + /* Define to 1 if you have the <sys/select.h> header file. */ #undef HAVE_SYS_SELECT_H diff --git a/extension/configure b/extension/configure index f848b9be..23b050d3 100755 --- a/extension/configure +++ b/extension/configure @@ -1817,6 +1817,63 @@ fi } # ac_fn_c_try_link +# ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES +# ---------------------------------------------------- +# Tries to find if the field MEMBER exists in type AGGR, after including +# INCLUDES, setting cache variable VAR accordingly. +ac_fn_c_check_member () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5 +$as_echo_n "checking for $2.$3... " >&6; } +if eval \${$4+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$5 +int +main () +{ +static $2 ac_aggr; +if (ac_aggr.$3) +return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + eval "$4=yes" +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$5 +int +main () +{ +static $2 ac_aggr; +if (sizeof ac_aggr.$3) +return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + eval "$4=yes" +else + eval "$4=no" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$4 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_member + # ac_fn_c_check_func LINENO FUNC VAR # ---------------------------------- # Tests whether FUNC exists, setting the cache variable VAR accordingly @@ -6382,6 +6439,19 @@ $as_echo "#define HAVE_DCGETTEXT 1" >>confdefs.h +ac_fn_c_check_member "$LINENO" "struct stat" "st_blksize" "ac_cv_member_struct_stat_st_blksize" "$ac_includes_default" +if test "x$ac_cv_member_struct_stat_st_blksize" = xyes; then : + +cat >>confdefs.h <<_ACEOF +#define HAVE_STRUCT_STAT_ST_BLKSIZE 1 +_ACEOF + + +$as_echo "#define HAVE_ST_BLKSIZE 1" >>confdefs.h + +fi + + if test -n "$ac_tool_prefix"; then for ac_prog in ar lib "link -lib" diff --git a/extension/configure.ac b/extension/configure.ac index 53ed588e..40f29681 100644 --- a/extension/configure.ac +++ b/extension/configure.ac @@ -38,6 +38,8 @@ AM_INIT_AUTOMAKE([-Wall -Werror]) AM_GNU_GETTEXT([external]) AM_GNU_GETTEXT_VERSION([0.18.1]) +dnl checks for structure members +AC_STRUCT_ST_BLKSIZE AM_PROG_AR AC_SYS_LARGEFILE diff --git a/extension/filefuncs.c b/extension/filefuncs.c index 1e8fc8d0..5117b32f 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 <windows.h> + +/* 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); @@ -326,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); diff --git a/extension/gawkdirfd.h b/extension/gawkdirfd.h index 1fbd6f57..e75f9bce 100644 --- a/extension/gawkdirfd.h +++ b/extension/gawkdirfd.h @@ -21,6 +21,14 @@ #include <config.h> +#ifndef ENOTSUP +# define ENOTSUP ENOSYS +#endif + +#ifndef DIR_TO_FD +# define DIR_TO_FD(d) (FAKE_FD_VALUE) +#endif + #if !defined(HAVE_DIRFD) && (!defined(HAVE_DECL_DIRFD) || HAVE_DECL_DIRFD == 0) int dirfd (DIR *dir_p) 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)); diff --git a/extension/readdir.c b/extension/readdir.c index 5ca4dc63..9d53ad9a 100644 --- a/extension/readdir.c +++ b/extension/readdir.c @@ -50,10 +50,14 @@ #error Cannot compile the dirent extension on this system! #endif -#include "gawkdirfd.h" +#ifdef __MINGW32__ +#include <windows.h> +#endif #include "gawkapi.h" +#include "gawkdirfd.h" + #include "gettext.h" #define _(msgid) gettext(msgid) #define N_(msgid) msgid @@ -77,7 +81,7 @@ typedef struct open_directory { /* ftype --- return type of file as a single character string */ static const char * -ftype(struct dirent *entry) +ftype(struct dirent *entry, const char *dirname) { #ifdef DT_BLK switch (entry->d_type) { @@ -92,10 +96,67 @@ ftype(struct dirent *entry) case DT_UNKNOWN: return "u"; } #else + char fname[PATH_MAX]; + struct stat sbuf; + + strcpy(fname, dirname); + strcat(fname, "/"); + strcat(fname, entry->d_name); + if (stat(fname, &sbuf) == 0) { + if (S_ISBLK(sbuf.st_mode)) + return "b"; + if (S_ISCHR(sbuf.st_mode)) + return "c"; + if (S_ISDIR(sbuf.st_mode)) + return "d"; + if (S_ISFIFO(sbuf.st_mode)) + return "p"; + if (S_ISREG(sbuf.st_mode)) + return "f"; +#ifdef S_ISLNK + if (S_ISLNK(sbuf.st_mode)) + return "l"; +#endif +#ifdef S_ISSOCK + if (S_ISSOCK(sbuf.st_mode)) + return "s"; +#endif + } return "u"; #endif } +/* get_inode --- get the inode of a file */ +#ifdef ZOS_USS +static long +#else +static long long +#endif +get_inode(struct dirent *entry, const char *dirname) +{ +#ifdef __MINGW32__ + char fname[PATH_MAX]; + HANDLE fh; + BY_HANDLE_FILE_INFORMATION info; + + sprintf(fname, "%s\\%s", dirname, entry->d_name); + 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; +#else + return entry->d_ino; +#endif +} + /* dir_get_record --- get one record at a time out of a directory */ static int @@ -107,6 +168,11 @@ dir_get_record(char **out, awk_input_buf_t *iobuf, int *errcode, int len; open_directory_t *the_dir; const char *ftstr; +#ifdef ZOS_USS + unsigned long ino; +#else + unsigned long long ino; +#endif /* * The caller sets *errcode to 0, so we should set it only if an @@ -129,17 +195,17 @@ dir_get_record(char **out, awk_input_buf_t *iobuf, int *errcode, return EOF; } -#ifdef ZOS_USS - len = sprintf(the_dir->buf, "%lu/%s", - (unsigned long) dirent->d_ino, - dirent->d_name); + ino = get_inode (dirent, iobuf->name); + +#if defined(ZOS_USS) + len = sprintf(the_dir->buf, "%lu/%s", ino, dirent->d_name); +#elif __MINGW32__ + len = sprintf(the_dir->buf, "%I64u/%s", ino, dirent->d_name); #else - len = sprintf(the_dir->buf, "%llu/%s", - (unsigned long long) dirent->d_ino, - dirent->d_name); + len = sprintf(the_dir->buf, "%llu/%s", ino, dirent->d_name); #endif - ftstr = ftype(dirent); + ftstr = ftype(dirent, iobuf->name); len += sprintf(the_dir->buf + len, "/%s", ftstr); *out = the_dir->buf; diff --git a/extension/rwarray.c b/extension/rwarray.c index d7b26c4a..6185000b 100644 --- a/extension/rwarray.c +++ b/extension/rwarray.c @@ -39,7 +39,11 @@ #include <string.h> #include <unistd.h> +#ifdef __MINGW32__ +#include <winsock2.h> +#else #include <arpa/inet.h> +#endif #include <sys/types.h> #include <sys/stat.h> |