summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'sys-apps/gawk/files')
-rw-r--r--sys-apps/gawk/files/filefuncs/Makefile57
-rw-r--r--sys-apps/gawk/files/filefuncs/filefuncs.c485
-rw-r--r--sys-apps/gawk/files/gawk-4.1.0-ports.patch189
-rw-r--r--sys-apps/gawk/files/gawk-4.1.3-bsd_configure_readline.patch63
4 files changed, 794 insertions, 0 deletions
diff --git a/sys-apps/gawk/files/filefuncs/Makefile b/sys-apps/gawk/files/filefuncs/Makefile
new file mode 100644
index 000000000000..615ae02512ca
--- /dev/null
+++ b/sys-apps/gawk/files/filefuncs/Makefile
@@ -0,0 +1,57 @@
+# Copyright 1999-2004 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# Author: Martin Schlemmer <azarah@gentoo.org>
+# $Id$
+
+CC ?= gcc
+LD = $(CC)
+
+MAJORVER = 0
+MINORVER = 0.1
+
+AWKINCDIR = /usr/include/awk
+DESTDIR =
+
+TARGET = filefuncs
+TARGET_LIB = $(TARGET).so.$(MAJORVER).$(MINORVER)
+
+LIBDIR = lib
+
+# Gentoo specific cruft, you like it dont ya idiot
+ifdef D
+DESTDIR = $(D)
+endif
+ifdef S
+AWKINCDIR = $(S)
+endif
+
+DOIT = yes
+ifeq ($(USERLAND),Darwin)
+DOIT = no
+endif
+
+ifeq ($(DOIT),yes)
+
+all: $(TARGET_LIB)
+
+$(TARGET).o: $(TARGET).c
+ $(CC) $(CFLAGS) $(CPPFLAGS) -shared -Wall -DHAVE_CONFIG_H -c -O2 -fPIC -I$(AWKINCDIR) $^
+
+$(TARGET_LIB): $(TARGET).o
+ $(LD) $(LDFLAGS) -o $@ -shared -Wl,-soname -Wl,$(TARGET).so.$(MAJORVER) $^
+
+install: $(TARGET_LIB)
+ install -m 0755 -d $(DESTDIR)/$(LIBDIR)/rcscripts
+ install -m 0755 $(TARGET_LIB) $(DESTDIR)/$(LIBDIR)/rcscripts
+ ln -s $(TARGET_LIB) $(DESTDIR)/$(LIBDIR)/rcscripts/$(TARGET).so.$(MAJORVER)
+ ln -s $(TARGET_LIB) $(DESTDIR)/$(LIBDIR)/rcscripts/$(TARGET).so
+
+clean:
+ rm -f $(TARGET)
+ rm -f *.o *~ core
+
+else
+
+all install clean:
+
+endif
diff --git a/sys-apps/gawk/files/filefuncs/filefuncs.c b/sys-apps/gawk/files/filefuncs/filefuncs.c
new file mode 100644
index 000000000000..fcab2a62912d
--- /dev/null
+++ b/sys-apps/gawk/files/filefuncs/filefuncs.c
@@ -0,0 +1,485 @@
+/*
+ * filefuncs.c - Builtin functions that provide initial minimal iterface
+ * to the file system.
+ *
+ * Arnold Robbins, update for 3.1, Mon Nov 23 12:53:39 EST 1998
+ */
+
+/*
+ * Copyright (C) 2001 the Free Software Foundation, Inc.
+ *
+ * This file is part of GAWK, the GNU implementation of the
+ * AWK Programming Language.
+ *
+ * GAWK is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GAWK is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/*
+ * Copyright 1999-2004 Gentoo Foundation
+ * Distributed under the terms of the GNU General Public License v2
+ * Author: Martin Schlemmer <azarah@gentoo.org>, Nov 2002
+ * $Id$
+ *
+ * Extended with: do_symlink()
+ * do_unlink()
+ * do_mkdir()
+ * do_rmdir()
+ *
+ * for use in the Gentoo rcscripts
+ *
+ */
+
+#include "awk.h"
+
+#include <unistd.h>
+
+/* do_chdir --- provide dynamically loaded chdir() builtin for gawk */
+
+static NODE *
+do_chdir(tree)
+NODE *tree;
+{
+ NODE *newdir;
+ int ret = -1;
+
+ if (do_lint && tree->param_cnt > 1)
+ lintwarn("chdir: called with too many arguments");
+
+ newdir = get_argument(tree, 0);
+ if (newdir != NULL) {
+ (void) force_string(newdir);
+ ret = chdir(newdir->stptr);
+ if (ret < 0)
+ update_ERRNO();
+
+ free_temp(newdir);
+ } else if (do_lint)
+ lintwarn("chdir: called with no arguments");
+
+
+ /* Set the return value */
+ set_value(tmp_number((AWKNUM) ret));
+
+ /* Just to make the interpreter happy */
+ return tmp_number((AWKNUM) 0);
+}
+
+/* do_symlink --- provide dynamically loaded symlink() builtin for gawk */
+
+static NODE *
+do_symlink(tree)
+NODE *tree;
+{
+ NODE *oldpath, *newpath;
+ int ret = -1;
+
+ if (do_lint && tree->param_cnt > 2)
+ lintwarn("symlink: called with too many arguments");
+
+ oldpath = get_argument(tree, 0);
+ newpath = get_argument(tree, 1);
+ if ((oldpath != NULL) && (newpath)) {
+ (void) force_string(oldpath);
+ (void) force_string(newpath);
+ ret = symlink(oldpath->stptr, newpath->stptr);
+ if (ret < 0)
+ update_ERRNO();
+
+ free_temp(oldpath);
+ free_temp(newpath);
+ } else if (do_lint)
+ lintwarn("symlink: called with not enough arguments");
+
+ /* Set the return value */
+ set_value(tmp_number((AWKNUM) ret));
+
+ /* Just to make the interpreter happy */
+ return tmp_number((AWKNUM) 0);
+}
+
+/* do_unlink --- provide dynamically loaded unlink() builtin for gawk */
+
+static NODE *
+do_unlink(tree)
+NODE *tree;
+{
+ NODE *pathname;
+ int ret = -1;
+
+ if (do_lint && tree->param_cnt > 1)
+ lintwarn("unlink: called with too many arguments");
+
+ pathname = get_argument(tree, 0);
+ if (pathname != NULL) {
+ (void) force_string(pathname);
+ ret = unlink(pathname->stptr);
+ if (ret < 0)
+ update_ERRNO();
+
+ free_temp(pathname);
+ } else if (do_lint)
+ lintwarn("unlink: called with no arguments");
+
+ /* Set the return value */
+ set_value(tmp_number((AWKNUM) ret));
+
+ /* Just to make the interpreter happy */
+ return tmp_number((AWKNUM) 0);
+}
+
+/* do_mkdir --- provide dynamically loaded mkdir() builtin for gawk */
+
+static NODE *
+do_mkdir(tree)
+NODE *tree;
+{
+ NODE *pathname, *mode;
+ int ret = -1;
+
+ if (do_lint && tree->param_cnt > 2)
+ lintwarn("mkdir: called with too many arguments");
+
+ pathname = get_argument(tree, 0);
+ mode = get_argument(tree, 1);
+ if ((pathname != NULL) && (mode != NULL)) {
+ (void) force_string(pathname);
+ (void) force_number(mode);
+ ret = mkdir(pathname->stptr, mode->numbr);
+ if (ret < 0)
+ update_ERRNO();
+
+ free_temp(pathname);
+ free_temp(mode);
+ } else if (do_lint)
+ lintwarn("mkdir: called with not enough arguments");
+
+ /* Set the return value */
+ set_value(tmp_number((AWKNUM) ret));
+
+ /* Just to make the interpreter happy */
+ return tmp_number((AWKNUM) 0);
+}
+
+/* do_rmdir --- provide dynamically loaded rmdir() builtin for gawk */
+
+static NODE *
+do_rmdir(tree)
+NODE *tree;
+{
+ NODE *pathname;
+ int ret = -1;
+
+ if (do_lint && tree->param_cnt > 1)
+ lintwarn("rmdir: called with too many arguments");
+
+ pathname = get_argument(tree, 0);
+ if (pathname != NULL) {
+ (void) force_string(pathname);
+ ret = rmdir(pathname->stptr);
+ if (ret < 0)
+ update_ERRNO();
+
+ free_temp(pathname);
+ } else if (do_lint)
+ lintwarn("rmdir: called with no arguments");
+
+ /* Set the return value */
+ set_value(tmp_number((AWKNUM) ret));
+
+ /* Just to make the interpreter happy */
+ return tmp_number((AWKNUM) 0);
+}
+
+/* format_mode --- turn a stat mode field into something readable */
+
+static char *
+format_mode(fmode)
+unsigned long fmode;
+{
+ static char outbuf[12];
+ int i;
+
+ strcpy(outbuf, "----------");
+ /* first, get the file type */
+ i = 0;
+ switch (fmode & S_IFMT) {
+#ifdef S_IFSOCK
+ case S_IFSOCK:
+ outbuf[i] = 's';
+ break;
+#endif
+#ifdef S_IFLNK
+ case S_IFLNK:
+ outbuf[i] = 'l';
+ break;
+#endif
+ case S_IFREG:
+ outbuf[i] = '-'; /* redundant */
+ break;
+ case S_IFBLK:
+ outbuf[i] = 'b';
+ break;
+ case S_IFDIR:
+ outbuf[i] = 'd';
+ break;
+#ifdef S_IFDOOR /* Solaris weirdness */
+ case S_IFDOOR:
+ outbuf[i] = 'D';
+ break;
+#endif /* S_IFDOOR */
+ case S_IFCHR:
+ outbuf[i] = 'c';
+ break;
+#ifdef S_IFIFO
+ case S_IFIFO:
+ outbuf[i] = 'p';
+ break;
+#endif
+ }
+
+ i++;
+ if ((fmode & S_IRUSR) != 0)
+ outbuf[i] = 'r';
+ i++;
+ if ((fmode & S_IWUSR) != 0)
+ outbuf[i] = 'w';
+ i++;
+ if ((fmode & S_IXUSR) != 0)
+ outbuf[i] = 'x';
+ i++;
+
+ if ((fmode & S_IRGRP) != 0)
+ outbuf[i] = 'r';
+ i++;
+ if ((fmode & S_IWGRP) != 0)
+ outbuf[i] = 'w';
+ i++;
+ if ((fmode & S_IXGRP) != 0)
+ outbuf[i] = 'x';
+ i++;
+
+ if ((fmode & S_IROTH) != 0)
+ outbuf[i] = 'r';
+ i++;
+ if ((fmode & S_IWOTH) != 0)
+ outbuf[i] = 'w';
+ i++;
+ if ((fmode & S_IXOTH) != 0)
+ outbuf[i] = 'x';
+ i++;
+
+ outbuf[i] = '\0';
+
+ if ((fmode & S_ISUID) != 0) {
+ if (outbuf[3] == 'x')
+ outbuf[3] = 's';
+ else
+ outbuf[3] = 'S';
+ }
+
+ /* setgid without execute == locking */
+ if ((fmode & S_ISGID) != 0) {
+ if (outbuf[6] == 'x')
+ outbuf[6] = 's';
+ else
+ outbuf[6] = 'l';
+ }
+
+ if ((fmode & S_ISVTX) != 0) {
+ if (outbuf[9] == 'x')
+ outbuf[9] = 't';
+ else
+ outbuf[9] = 'T';
+ }
+
+ return outbuf;
+}
+
+/* do_stat --- provide a stat() function for gawk */
+
+static NODE *
+do_stat(tree)
+NODE *tree;
+{
+ NODE *file, *array;
+ struct stat sbuf;
+ int ret;
+ NODE **aptr;
+ char *pmode; /* printable mode */
+ char *type = "unknown";
+
+ /* check arg count */
+ if (tree->param_cnt != 2)
+ fatal(
+ "stat: called with incorrect number of arguments (%d), should be 2",
+ tree->param_cnt);
+
+ /* directory is first arg, array to hold results is second */
+ file = get_argument(tree, 0);
+ array = get_argument(tree, 1);
+
+ /* empty out the array */
+ assoc_clear(array);
+
+ /* lstat the file, if error, set ERRNO and return */
+ (void) force_string(file);
+ ret = lstat(file->stptr, & sbuf);
+ if (ret < 0) {
+ update_ERRNO();
+
+ set_value(tmp_number((AWKNUM) ret));
+
+ free_temp(file);
+ return tmp_number((AWKNUM) 0);
+ }
+
+ /* fill in the array */
+ aptr = assoc_lookup(array, tmp_string("name", 4), FALSE);
+ *aptr = dupnode(file);
+
+ aptr = assoc_lookup(array, tmp_string("dev", 3), FALSE);
+ *aptr = make_number((AWKNUM) sbuf.st_dev);
+
+ aptr = assoc_lookup(array, tmp_string("ino", 3), FALSE);
+ *aptr = make_number((AWKNUM) sbuf.st_ino);
+
+ aptr = assoc_lookup(array, tmp_string("mode", 4), FALSE);
+ *aptr = make_number((AWKNUM) sbuf.st_mode);
+
+ aptr = assoc_lookup(array, tmp_string("nlink", 5), FALSE);
+ *aptr = make_number((AWKNUM) sbuf.st_nlink);
+
+ aptr = assoc_lookup(array, tmp_string("uid", 3), FALSE);
+ *aptr = make_number((AWKNUM) sbuf.st_uid);
+
+ aptr = assoc_lookup(array, tmp_string("gid", 3), FALSE);
+ *aptr = make_number((AWKNUM) sbuf.st_gid);
+
+ aptr = assoc_lookup(array, tmp_string("size", 4), FALSE);
+ *aptr = make_number((AWKNUM) sbuf.st_size);
+
+ aptr = assoc_lookup(array, tmp_string("blocks", 6), FALSE);
+ *aptr = make_number((AWKNUM) sbuf.st_blocks);
+
+ aptr = assoc_lookup(array, tmp_string("atime", 5), FALSE);
+ *aptr = make_number((AWKNUM) sbuf.st_atime);
+
+ aptr = assoc_lookup(array, tmp_string("mtime", 5), FALSE);
+ *aptr = make_number((AWKNUM) sbuf.st_mtime);
+
+ aptr = assoc_lookup(array, tmp_string("ctime", 5), FALSE);
+ *aptr = make_number((AWKNUM) sbuf.st_ctime);
+
+ /* for block and character devices, add rdev, major and minor numbers */
+ if (S_ISBLK(sbuf.st_mode) || S_ISCHR(sbuf.st_mode)) {
+ aptr = assoc_lookup(array, tmp_string("rdev", 4), FALSE);
+ *aptr = make_number((AWKNUM) sbuf.st_rdev);
+
+ aptr = assoc_lookup(array, tmp_string("major", 5), FALSE);
+ *aptr = make_number((AWKNUM) major(sbuf.st_rdev));
+
+ aptr = assoc_lookup(array, tmp_string("minor", 5), FALSE);
+ *aptr = make_number((AWKNUM) minor(sbuf.st_rdev));
+ }
+
+#ifdef HAVE_ST_BLKSIZE
+ aptr = assoc_lookup(array, tmp_string("blksize", 7), FALSE);
+ *aptr = make_number((AWKNUM) sbuf.st_blksize);
+#endif /* HAVE_ST_BLKSIZE */
+
+ aptr = assoc_lookup(array, tmp_string("pmode", 5), FALSE);
+ pmode = format_mode(sbuf.st_mode);
+ *aptr = make_string(pmode, strlen(pmode));
+
+ /* for symbolic links, add a linkval field */
+ if (S_ISLNK(sbuf.st_mode)) {
+ char buf[BUFSIZ*2];
+ int linksize;
+
+ linksize = readlink(file->stptr, buf, sizeof buf);
+ /* should make this smarter */
+ if (linksize == sizeof(buf))
+ fatal("size of symbolic link too big");
+ buf[linksize] = '\0';
+
+ aptr = assoc_lookup(array, tmp_string("linkval", 7), FALSE);
+ *aptr = make_string(buf, linksize);
+ }
+
+ /* add a type field */
+ switch (sbuf.st_mode & S_IFMT) {
+#ifdef S_IFSOCK
+ case S_IFSOCK:
+ type = "socket";
+ break;
+#endif
+#ifdef S_IFLNK
+ case S_IFLNK:
+ type = "symlink";
+ break;
+#endif
+ case S_IFREG:
+ type = "file";
+ break;
+ case S_IFBLK:
+ type = "blockdev";
+ break;
+ case S_IFDIR:
+ type = "directory";
+ break;
+#ifdef S_IFDOOR
+ case S_IFDOOR:
+ type = "door";
+ break;
+#endif
+ case S_IFCHR:
+ type = "chardev";
+ break;
+#ifdef S_IFIFO
+ case S_IFIFO:
+ type = "fifo";
+ break;
+#endif
+ }
+
+ aptr = assoc_lookup(array, tmp_string("type", 4), FALSE);
+ *aptr = make_string(type, strlen(type));
+
+ free_temp(file);
+
+ /* Set the return value */
+ set_value(tmp_number((AWKNUM) ret));
+
+ /* Just to make the interpreter happy */
+ return tmp_number((AWKNUM) 0);
+}
+
+/* dlload --- load new builtins in this library */
+
+NODE *
+dlload(tree, dl)
+NODE *tree;
+void *dl;
+{
+ make_builtin("chdir", do_chdir, 1);
+ make_builtin("symlink", do_symlink, 2);
+ make_builtin("unlink", do_unlink, 1);
+ make_builtin("mkdir", do_mkdir, 2);
+ make_builtin("rmdir", do_rmdir, 1);
+ make_builtin("stat", do_stat, 2);
+
+ return tmp_number((AWKNUM) 0);
+}
+
diff --git a/sys-apps/gawk/files/gawk-4.1.0-ports.patch b/sys-apps/gawk/files/gawk-4.1.0-ports.patch
new file mode 100644
index 000000000000..9aba7e8a2df3
--- /dev/null
+++ b/sys-apps/gawk/files/gawk-4.1.0-ports.patch
@@ -0,0 +1,189 @@
+AIX port, bug#490266.
+
+This is from 2 upstream commits:
+
+http://git.savannah.gnu.org/cgit/gawk.git/commit/?h=gawk-4.1-stable&id=21c8b6d547b12942775d675ead2994992285c04c
+http://git.savannah.gnu.org/cgit/gawk.git/commit/?h=gawk-4.1-stable&id=29e3ae329c550b884169b7db20775cd74b95b77a
+
+#diff --git a/extension/ChangeLog b/extension/ChangeLog
+#index e01d6d1..4d1af22 100644
+#--- a/extension/ChangeLog
+#+++ b/extension/ChangeLog
+#@@ -1,3 +1,20 @@
+#+2013-10-23 Michael Haubenwallner <michael.haubenwallner@salomon.at>
+#+
+#+ Fix portability for AIX.
+#+
+#+ * inplace.c (_XOPEN_SOURCE): Define when not defined yet.
+#+ (_XOPEN_SOURCE_EXTENDED): Ditto. Needs to define a number.
+#+
+#+2013-06-10 Arnold D. Robbins <arnold@skeeve.com>
+#+
+#+ * configure.ac (AC_HEADER_MAJOR): New macro added.
+#+ Add check for limits.h header.
+#+ * filefuncs.c: Add the right stuff to get the major/minor macros.
+#+ * readdir.c: Add include of limits.h appropriately wrapped.
+#+
+#+ Thanks to ICHII Takashi <ichii386@schweetheart.jp> for the reports
+#+ and pointers.
+#+
+# 2013-05-09 Arnold D. Robbins <arnold@skeeve.com>
+#
+# * 4.1.0: Release tar ball made.
+#diff --git a/extension/configure.ac b/extension/configure.ac
+#index 53ed588..3ad03ed 100644
+#--- a/extension/configure.ac
+#+++ b/extension/configure.ac
+#@@ -64,7 +64,8 @@ else
+# AC_MSG_RESULT([no])
+# fi
+#
+#-AC_CHECK_HEADERS(dirent.h fnmatch.h time.h sys/time.h sys/select.h)
+#+AC_HEADER_MAJOR
+#+AC_CHECK_HEADERS(dirent.h fnmatch.h limits.h time.h sys/time.h sys/select.h)
+#
+# AC_CHECK_FUNCS(fdopendir fnmatch gettimeofday \
+# getdtablesize nanosleep select GetSystemTimeAsFileTime)
+diff --git a/extension/configh.in b/extension/configh.in
+index 9162ce4..02954ee 100644
+--- a/extension/configh.in
++++ b/extension/configh.in
+@@ -66,6 +66,9 @@
+ /* Define to 1 if you have the <inttypes.h> header file. */
+ #undef HAVE_INTTYPES_H
+
++/* Define to 1 if you have the <limits.h> header file. */
++#undef HAVE_LIMITS_H
++
+ /* Define to 1 if you have the <memory.h> header file. */
+ #undef HAVE_MEMORY_H
+
+@@ -109,6 +112,14 @@
+ */
+ #undef LT_OBJDIR
+
++/* Define to 1 if `major', `minor', and `makedev' are declared in <mkdev.h>.
++ */
++#undef MAJOR_IN_MKDEV
++
++/* Define to 1 if `major', `minor', and `makedev' are declared in
++ <sysmacros.h>. */
++#undef MAJOR_IN_SYSMACROS
++
+ /* Name of package */
+ #undef PACKAGE
+
+diff --git a/extension/configure b/extension/configure
+index f848b9b..c3f8f1c 100755
+--- a/extension/configure
++++ b/extension/configure
+@@ -13885,7 +13885,57 @@ else
+ $as_echo "no" >&6; }
+ fi
+
+-for ac_header in dirent.h fnmatch.h time.h sys/time.h sys/select.h
++{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether sys/types.h defines makedev" >&5
++$as_echo_n "checking whether sys/types.h defines makedev... " >&6; }
++if ${ac_cv_header_sys_types_h_makedev+:} false; then :
++ $as_echo_n "(cached) " >&6
++else
++ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h. */
++#include <sys/types.h>
++int
++main ()
++{
++return makedev(0, 0);
++ ;
++ return 0;
++}
++_ACEOF
++if ac_fn_c_try_link "$LINENO"; then :
++ ac_cv_header_sys_types_h_makedev=yes
++else
++ ac_cv_header_sys_types_h_makedev=no
++fi
++rm -f core conftest.err conftest.$ac_objext \
++ conftest$ac_exeext conftest.$ac_ext
++
++fi
++{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_sys_types_h_makedev" >&5
++$as_echo "$ac_cv_header_sys_types_h_makedev" >&6; }
++
++if test $ac_cv_header_sys_types_h_makedev = no; then
++ac_fn_c_check_header_mongrel "$LINENO" "sys/mkdev.h" "ac_cv_header_sys_mkdev_h" "$ac_includes_default"
++if test "x$ac_cv_header_sys_mkdev_h" = xyes; then :
++
++$as_echo "#define MAJOR_IN_MKDEV 1" >>confdefs.h
++
++fi
++
++
++
++ if test $ac_cv_header_sys_mkdev_h = no; then
++ ac_fn_c_check_header_mongrel "$LINENO" "sys/sysmacros.h" "ac_cv_header_sys_sysmacros_h" "$ac_includes_default"
++if test "x$ac_cv_header_sys_sysmacros_h" = xyes; then :
++
++$as_echo "#define MAJOR_IN_SYSMACROS 1" >>confdefs.h
++
++fi
++
++
++ fi
++fi
++
++for ac_header in dirent.h fnmatch.h limits.h time.h sys/time.h sys/select.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"
+diff --git a/extension/filefuncs.c b/extension/filefuncs.c
+index 1e8fc8d..9e637aa 100644
+--- a/extension/filefuncs.c
++++ b/extension/filefuncs.c
+@@ -46,6 +46,12 @@
+ #include <sys/types.h>
+ #include <sys/stat.h>
+
++#ifdef MAJOR_IN_MKDEV
++#include <sys/mkdev.h>
++#elif defined(MAJOR_IN_SYSMACROS)
++#include <sys/sysmacros.h>
++#endif
++
+ #include "gawkapi.h"
+
+ #include "gettext.h"
+diff --git a/extension/inplace.c b/extension/inplace.c
+index ded4746..69d452a 100644
+--- a/extension/inplace.c
++++ b/extension/inplace.c
+@@ -27,8 +27,12 @@
+ #include <config.h>
+ #endif
+
+-#define _XOPEN_SOURCE
+-#define _XOPEN_SOURCE_EXTENDED
++#ifndef _XOPEN_SOURCE
++# define _XOPEN_SOURCE
++#endif
++#ifndef _XOPEN_SOURCE_EXTENDED
++# define _XOPEN_SOURCE_EXTENDED 1
++#endif
+
+ #include <stdio.h>
+ #include <assert.h>
+diff --git a/extension/readdir.c b/extension/readdir.c
+index 5ca4dc6..c2a626a 100644
+--- a/extension/readdir.c
++++ b/extension/readdir.c
+@@ -44,6 +44,10 @@
+ #include <sys/types.h>
+ #include <sys/stat.h>
+
++#ifdef HAVE_LIMITS_H
++#include <limits.h>
++#endif
++
+ #ifdef HAVE_DIRENT_H
+ #include <dirent.h>
+ #else
diff --git a/sys-apps/gawk/files/gawk-4.1.3-bsd_configure_readline.patch b/sys-apps/gawk/files/gawk-4.1.3-bsd_configure_readline.patch
new file mode 100644
index 000000000000..3bd267efd179
--- /dev/null
+++ b/sys-apps/gawk/files/gawk-4.1.3-bsd_configure_readline.patch
@@ -0,0 +1,63 @@
+http://git.savannah.gnu.org/cgit/gawk.git/commit/?id=ac0ef52fe407b89c7968b927c7b2b513cc13963a
+
+--- gawk-4.1.3/configure 2015-05-19 15:38:35.000000000 +0200
++++ gawk-4.1.3/configure 2015-05-19 15:38:35.000000000 +0200
+@@ -10825,7 +10825,46 @@
+
+ if test $_found_readline = yes ; then
+ case $host_os in
+- *bsd* ) _combo="$_combo -ltermcap"
++ *bsd* ) { $as_echo "$as_me:${as_lineno-$LINENO}: checking for tgetent in -ltermcap" >&5
++$as_echo_n "checking for tgetent in -ltermcap... " >&6; }
++if ${ac_cv_lib_termcap_tgetent+:} false; then :
++ $as_echo_n "(cached) " >&6
++else
++ ac_check_lib_save_LIBS=$LIBS
++LIBS="-ltermcap $LIBS"
++cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h. */
++
++/* Override any GCC internal prototype to avoid an error.
++ Use char because int might match the return type of a GCC
++ builtin and then its argument prototype would still apply. */
++#ifdef __cplusplus
++extern "C"
++#endif
++char tgetent ();
++int
++main ()
++{
++return tgetent ();
++ ;
++ return 0;
++}
++_ACEOF
++if ac_fn_c_try_link "$LINENO"; then :
++ ac_cv_lib_termcap_tgetent=yes
++else
++ ac_cv_lib_termcap_tgetent=no
++fi
++rm -f core conftest.err conftest.$ac_objext \
++ conftest$ac_exeext conftest.$ac_ext
++LIBS=$ac_check_lib_save_LIBS
++fi
++{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_termcap_tgetent" >&5
++$as_echo "$ac_cv_lib_termcap_tgetent" >&6; }
++if test "x$ac_cv_lib_termcap_tgetent" = xyes; then :
++ _combo="$_combo -ltermcap"
++fi
++
+ ;;
+ esac
+
+--- gawk-4.1.3/m4/readline.m4 2015-04-05 12:19:19.000000000 +0200
++++ gawk-4.1.3/m4/readline.m4 2015-04-05 12:19:19.000000000 +0200
+@@ -92,7 +92,7 @@
+
+ if test $_found_readline = yes ; then
+ case $host_os in
+- *bsd* ) _combo="$_combo -ltermcap"
++ *bsd* ) AC_CHECK_LIB(termcap, tgetent, _combo="$_combo -ltermcap")
+ ;;
+ esac
+ AC_DEFINE(HAVE_LIBREADLINE,1,