diff options
-rw-r--r-- | extension/ChangeLog | 6 | ||||
-rw-r--r-- | extension/configh.in | 6 | ||||
-rwxr-xr-x | extension/configure | 4 | ||||
-rw-r--r-- | extension/configure.ac | 4 | ||||
-rw-r--r-- | extension/filefuncs.c | 66 |
5 files changed, 82 insertions, 4 deletions
diff --git a/extension/ChangeLog b/extension/ChangeLog index 11db1488..0821077c 100644 --- a/extension/ChangeLog +++ b/extension/ChangeLog @@ -1,3 +1,9 @@ +2016-01-20 Arnold D. Robbins <arnold@skeeve.com> + + * filefuncs.c: Add statvfs function. Undocumented for now. + * configure.ac: Add appropriate stuff to check for statvfs. + * configure, configh.in: Regenerated. + 2015-12-16 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (EXTRA_DIST): Add ext_custom.h so that it will be diff --git a/extension/configh.in b/extension/configh.in index 82cbb8f5..d3a226a5 100644 --- a/extension/configh.in +++ b/extension/configh.in @@ -60,6 +60,9 @@ /* Define to 1 if you have the `select' function. */ #undef HAVE_SELECT +/* Define to 1 if you have the `statvfs' function. */ +#undef HAVE_STATVFS + /* Define to 1 if you have the <stdint.h> header file. */ #undef HAVE_STDINT_H @@ -89,6 +92,9 @@ /* Define to 1 if you have the <sys/select.h> header file. */ #undef HAVE_SYS_SELECT_H +/* Define to 1 if you have the <sys/statvfs.h> header file. */ +#undef HAVE_SYS_STATVFS_H + /* Define to 1 if you have the <sys/stat.h> header file. */ #undef HAVE_SYS_STAT_H diff --git a/extension/configure b/extension/configure index e42ceb60..8b72f9f9 100755 --- a/extension/configure +++ b/extension/configure @@ -12602,7 +12602,7 @@ else $as_echo "no" >&6; } fi -for ac_header in fnmatch.h limits.h sys/time.h sys/select.h sys/param.h +for ac_header in fnmatch.h limits.h sys/time.h sys/select.h sys/param.h sys/statvfs.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" @@ -12860,7 +12860,7 @@ fi for ac_func in fdopendir fnmatch gettimeofday \ - getdtablesize nanosleep select GetSystemTimeAsFileTime + getdtablesize nanosleep select statvfs GetSystemTimeAsFileTime do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/extension/configure.ac b/extension/configure.ac index a0f78d76..2bdaab6f 100644 --- a/extension/configure.ac +++ b/extension/configure.ac @@ -64,13 +64,13 @@ else AC_MSG_RESULT([no]) fi -AC_CHECK_HEADERS(fnmatch.h limits.h sys/time.h sys/select.h sys/param.h) +AC_CHECK_HEADERS(fnmatch.h limits.h sys/time.h sys/select.h sys/param.h sys/statvfs.h) AC_HEADER_DIRENT AC_HEADER_MAJOR AC_HEADER_TIME AC_CHECK_FUNCS(fdopendir fnmatch gettimeofday \ - getdtablesize nanosleep select GetSystemTimeAsFileTime) + getdtablesize nanosleep select statvfs GetSystemTimeAsFileTime) GAWK_FUNC_DIRFD GAWK_PREREQ_DIRFD diff --git a/extension/filefuncs.c b/extension/filefuncs.c index 1441cb31..ae4f7c3d 100644 --- a/extension/filefuncs.c +++ b/extension/filefuncs.c @@ -6,6 +6,7 @@ * Arnold Robbins and John Haque, update for 3.1.4, applied Mon Jun 14 13:55:30 IDT 2004 * Arnold Robbins and Andrew Schorr, revised for new extension API, May 2012. * Arnold Robbins, add fts(), August 2012 + * Arnold Robbins, add statvfs(), November 2015 */ /* @@ -84,6 +85,10 @@ #include <sys/sysmacros.h> #endif +#if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) +#include <sys/statvfs.h> +#endif + #include "gawkapi.h" #include "gettext.h" @@ -502,6 +507,64 @@ do_stat(int nargs, awk_value_t *result) return make_number(ret, result); } +#if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) + +/* do_statvfs --- provide a statvfs() function for gawk */ + +static awk_value_t * +do_statvfs(int nargs, awk_value_t *result) +{ + awk_value_t file_param, array_param; + char *name; + awk_array_t array; + int ret; + struct statvfs vfsbuf; + + assert(result != NULL); + + if (nargs != 2) { + if (do_lint) + lintwarn(ext_id, _("statvfs: called with wrong number of arguments")); + return make_number(-1, result); + } + + /* file is first arg, array to hold results is second */ + if ( ! get_argument(0, AWK_STRING, & file_param) + || ! get_argument(1, AWK_ARRAY, & array_param)) { + warning(ext_id, _("stat: bad parameters")); + return make_number(-1, result); + } + + name = file_param.str_value.str; + array = array_param.array_cookie; + + /* always empty out the array */ + clear_array(array); + + /* stat the file; if error, set ERRNO and return */ + ret = statvfs(name, & vfsbuf); + if (ret < 0) { + update_ERRNO_int(errno); + return make_number(ret, result); + } + + array_set_numeric(array, "bsize", vfsbuf.f_bsize); /* filesystem block size */ + array_set_numeric(array, "frsize", vfsbuf.f_frsize); /* fragment size */ + array_set_numeric(array, "blocks", vfsbuf.f_blocks); /* size of fs in f_frsize units */ + array_set_numeric(array, "bfree", vfsbuf.f_bfree); /* # free blocks */ + array_set_numeric(array, "bavail", vfsbuf.f_bavail); /* # free blocks for unprivileged users */ + array_set_numeric(array, "files", vfsbuf.f_files); /* # inodes */ + array_set_numeric(array, "ffree", vfsbuf.f_ffree); /* # free inodes */ + array_set_numeric(array, "favail", vfsbuf.f_favail); /* # free inodes for unprivileged users */ + array_set_numeric(array, "fsid", vfsbuf.f_fsid); /* filesystem ID */ + array_set_numeric(array, "flag", vfsbuf.f_flag); /* mount flags */ + array_set_numeric(array, "namemax", vfsbuf.f_namemax); /* maximum filename length */ + + + return make_number(ret, result); +} +#endif + /* init_filefuncs --- initialization routine */ static awk_bool_t @@ -868,6 +931,9 @@ static awk_ext_func_t func_table[] = { #ifndef __MINGW32__ { "fts", do_fts, 3 }, #endif +#if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) + { "statvfs", do_statvfs, 2 }, +#endif }; |