nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0054-Add-grub_util_readlink.patch

8631a2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8631a2
From: Peter Jones <pjones@redhat.com>
8631a2
Date: Wed, 3 Sep 2014 10:01:03 -0400
8631a2
Subject: [PATCH] Add grub_util_readlink()
8631a2
8631a2
Add grub_util_readlink().  This requires pulling in stat and readlink from
8631a2
gnulib, which pulls in stat and related headers, but after that the
8631a2
implementation is straightforward.
8631a2
8631a2
Signed-off-by: Peter Jones <pjones@redhat.com>
8631a2
Reviewed-by: Adam Jackson <ajax@redhat.com>
8631a2
---
8631a2
 grub-core/gnulib/gettimeofday.c       | 154 +++++++
8631a2
 grub-core/gnulib/readlink.c           |  74 ++++
8631a2
 grub-core/gnulib/stat.c               | 138 +++++++
8631a2
 grub-core/osdep/windows/hostdisk.c    |   6 +
8631a2
 grub-core/gnulib/pathmax.h            |  83 ++++
8631a2
 grub-core/gnulib/sys_stat.in.h        | 732 ++++++++++++++++++++++++++++++++++
8631a2
 grub-core/gnulib/sys_time.in.h        | 213 ++++++++++
8631a2
 grub-core/gnulib/sys_types.in.h       |   2 +
8631a2
 grub-core/gnulib/time.h               | 586 +++++++++++++++++++++++++++
8631a2
 grub-core/gnulib/time.in.h            | 274 +++++++++++++
8631a2
 include/grub/osdep/hostfile_aros.h    |   6 +
8631a2
 include/grub/osdep/hostfile_unix.h    |   6 +
8631a2
 include/grub/osdep/hostfile_windows.h |   2 +
8631a2
 grub-core/gnulib/Makefile.am          | 177 +++++++-
8631a2
 m4/gettimeofday.m4                    | 138 +++++++
8631a2
 m4/gnulib-cache.m4                    |   3 +-
8631a2
 m4/gnulib-comp.m4                     |  49 +++
8631a2
 m4/largefile.m4                       | 146 +++++++
8631a2
 m4/pathmax.m4                         |  42 ++
8631a2
 m4/readlink.m4                        |  71 ++++
8631a2
 m4/stat.m4                            |  71 ++++
8631a2
 m4/sys_stat_h.m4                      |  96 +++++
8631a2
 m4/sys_time_h.m4                      | 110 +++++
8631a2
 m4/time_h.m4                          | 118 ++++++
8631a2
 24 files changed, 3295 insertions(+), 2 deletions(-)
8631a2
 create mode 100644 grub-core/gnulib/gettimeofday.c
8631a2
 create mode 100644 grub-core/gnulib/readlink.c
8631a2
 create mode 100644 grub-core/gnulib/stat.c
8631a2
 create mode 100644 grub-core/gnulib/pathmax.h
8631a2
 create mode 100644 grub-core/gnulib/sys_stat.in.h
8631a2
 create mode 100644 grub-core/gnulib/sys_time.in.h
8631a2
 create mode 100644 grub-core/gnulib/time.h
8631a2
 create mode 100644 grub-core/gnulib/time.in.h
8631a2
 create mode 100644 m4/gettimeofday.m4
8631a2
 create mode 100644 m4/largefile.m4
8631a2
 create mode 100644 m4/pathmax.m4
8631a2
 create mode 100644 m4/readlink.m4
8631a2
 create mode 100644 m4/stat.m4
8631a2
 create mode 100644 m4/sys_stat_h.m4
8631a2
 create mode 100644 m4/sys_time_h.m4
8631a2
 create mode 100644 m4/time_h.m4
8631a2
8631a2
diff --git a/grub-core/gnulib/gettimeofday.c b/grub-core/gnulib/gettimeofday.c
8631a2
new file mode 100644
09e3cc
index 000000000..8b2058e8c
8631a2
--- /dev/null
8631a2
+++ b/grub-core/gnulib/gettimeofday.c
8631a2
@@ -0,0 +1,154 @@
8631a2
+/* Provide gettimeofday for systems that don't have it or for which it's broken.
8631a2
+
8631a2
+   Copyright (C) 2001-2003, 2005-2007, 2009-2014 Free Software Foundation, Inc.
8631a2
+
8631a2
+   This program is free software; you can redistribute it and/or modify
8631a2
+   it under the terms of the GNU General Public License as published by
8631a2
+   the Free Software Foundation; either version 3, or (at your option)
8631a2
+   any later version.
8631a2
+
8631a2
+   This program is distributed in the hope that it will be useful,
8631a2
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
8631a2
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8631a2
+   GNU General Public License for more details.
8631a2
+
8631a2
+   You should have received a copy of the GNU General Public License
8631a2
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
8631a2
+
8631a2
+/* written by Jim Meyering */
8631a2
+
8631a2
+#include <config.h>
8631a2
+
8631a2
+/* Specification.  */
8631a2
+#include <sys/time.h>
8631a2
+
8631a2
+#include <time.h>
8631a2
+
8631a2
+#if HAVE_SYS_TIMEB_H
8631a2
+# include <sys/timeb.h>
8631a2
+#endif
8631a2
+
8631a2
+#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME
8631a2
+
8631a2
+/* Work around the bug in some systems whereby gettimeofday clobbers
8631a2
+   the static buffer that localtime uses for its return value.  The
8631a2
+   gettimeofday function from Mac OS X 10.0.4 (i.e., Darwin 1.3.7) has
8631a2
+   this problem.  The tzset replacement is necessary for at least
8631a2
+   Solaris 2.5, 2.5.1, and 2.6.  */
8631a2
+
8631a2
+static struct tm tm_zero_buffer;
8631a2
+static struct tm *localtime_buffer_addr = &tm_zero_buffer;
8631a2
+
8631a2
+# undef localtime
8631a2
+extern struct tm *localtime (time_t const *);
8631a2
+
8631a2
+# undef gmtime
8631a2
+extern struct tm *gmtime (time_t const *);
8631a2
+
8631a2
+/* This is a wrapper for localtime.  It is used only on systems for which
8631a2
+   gettimeofday clobbers the static buffer used for localtime's result.
8631a2
+
8631a2
+   On the first call, record the address of the static buffer that
8631a2
+   localtime uses for its result.  */
8631a2
+
8631a2
+struct tm *
8631a2
+rpl_localtime (time_t const *timep)
8631a2
+{
8631a2
+  struct tm *tm = localtime (timep);
8631a2
+
8631a2
+  if (localtime_buffer_addr == &tm_zero_buffer)
8631a2
+    localtime_buffer_addr = tm;
8631a2
+
8631a2
+  return tm;
8631a2
+}
8631a2
+
8631a2
+/* Same as above, since gmtime and localtime use the same buffer.  */
8631a2
+struct tm *
8631a2
+rpl_gmtime (time_t const *timep)
8631a2
+{
8631a2
+  struct tm *tm = gmtime (timep);
8631a2
+
8631a2
+  if (localtime_buffer_addr == &tm_zero_buffer)
8631a2
+    localtime_buffer_addr = tm;
8631a2
+
8631a2
+  return tm;
8631a2
+}
8631a2
+
8631a2
+#endif /* GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME */
8631a2
+
8631a2
+#if TZSET_CLOBBERS_LOCALTIME
8631a2
+
8631a2
+# undef tzset
8631a2
+extern void tzset (void);
8631a2
+
8631a2
+/* This is a wrapper for tzset, for systems on which tzset may clobber
8631a2
+   the static buffer used for localtime's result.  */
8631a2
+void
8631a2
+rpl_tzset (void)
8631a2
+{
8631a2
+  /* Save and restore the contents of the buffer used for localtime's
8631a2
+     result around the call to tzset.  */
8631a2
+  struct tm save = *localtime_buffer_addr;
8631a2
+  tzset ();
8631a2
+  *localtime_buffer_addr = save;
8631a2
+}
8631a2
+#endif
8631a2
+
8631a2
+/* This is a wrapper for gettimeofday.  It is used only on systems
8631a2
+   that lack this function, or whose implementation of this function
8631a2
+   causes problems.  */
8631a2
+
8631a2
+int
8631a2
+gettimeofday (struct timeval *restrict tv, void *restrict tz)
8631a2
+{
8631a2
+#undef gettimeofday
8631a2
+#if HAVE_GETTIMEOFDAY
8631a2
+# if GETTIMEOFDAY_CLOBBERS_LOCALTIME
8631a2
+  /* Save and restore the contents of the buffer used for localtime's
8631a2
+     result around the call to gettimeofday.  */
8631a2
+  struct tm save = *localtime_buffer_addr;
8631a2
+# endif
8631a2
+
8631a2
+# if defined timeval /* 'struct timeval' overridden by gnulib?  */
8631a2
+#  undef timeval
8631a2
+  struct timeval otv;
8631a2
+  int result = gettimeofday (&otv, (struct timezone *) tz);
8631a2
+  if (result == 0)
8631a2
+    {
8631a2
+      tv->tv_sec = otv.tv_sec;
8631a2
+      tv->tv_usec = otv.tv_usec;
8631a2
+    }
8631a2
+# else
8631a2
+  int result = gettimeofday (tv, (struct timezone *) tz);
8631a2
+# endif
8631a2
+
8631a2
+# if GETTIMEOFDAY_CLOBBERS_LOCALTIME
8631a2
+  *localtime_buffer_addr = save;
8631a2
+# endif
8631a2
+
8631a2
+  return result;
8631a2
+
8631a2
+#else
8631a2
+
8631a2
+# if HAVE__FTIME
8631a2
+
8631a2
+  struct _timeb timebuf;
8631a2
+  _ftime (&timebuf);
8631a2
+  tv->tv_sec = timebuf.time;
8631a2
+  tv->tv_usec = timebuf.millitm * 1000;
8631a2
+
8631a2
+# else
8631a2
+
8631a2
+#  if !defined OK_TO_USE_1S_CLOCK
8631a2
+#   error "Only 1-second nominal clock resolution found.  Is that intended?" \
8631a2
+          "If so, compile with the -DOK_TO_USE_1S_CLOCK option."
8631a2
+#  endif
8631a2
+  tv->tv_sec = time (NULL);
8631a2
+  tv->tv_usec = 0;
8631a2
+
8631a2
+# endif
8631a2
+
8631a2
+  return 0;
8631a2
+
8631a2
+#endif
8631a2
+}
8631a2
diff --git a/grub-core/gnulib/readlink.c b/grub-core/gnulib/readlink.c
8631a2
new file mode 100644
09e3cc
index 000000000..4c4963951
8631a2
--- /dev/null
8631a2
+++ b/grub-core/gnulib/readlink.c
8631a2
@@ -0,0 +1,74 @@
8631a2
+/* Stub for readlink().
8631a2
+   Copyright (C) 2003-2007, 2009-2014 Free Software Foundation, Inc.
8631a2
+
8631a2
+   This program is free software: you can redistribute it and/or modify
8631a2
+   it under the terms of the GNU General Public License as published by
8631a2
+   the Free Software Foundation; either version 3 of the License, or
8631a2
+   (at your option) any later version.
8631a2
+
8631a2
+   This program is distributed in the hope that it will be useful,
8631a2
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
8631a2
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8631a2
+   GNU General Public License for more details.
8631a2
+
8631a2
+   You should have received a copy of the GNU General Public License
8631a2
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
8631a2
+
8631a2
+#include <config.h>
8631a2
+
8631a2
+/* Specification.  */
8631a2
+#include <unistd.h>
8631a2
+
8631a2
+#include <errno.h>
8631a2
+#include <string.h>
8631a2
+#include <sys/stat.h>
8631a2
+
8631a2
+#if !HAVE_READLINK
8631a2
+
8631a2
+/* readlink() substitute for systems that don't have a readlink() function,
8631a2
+   such as DJGPP 2.03 and mingw32.  */
8631a2
+
8631a2
+ssize_t
8631a2
+readlink (const char *name, char *buf _GL_UNUSED,
8631a2
+          size_t bufsize _GL_UNUSED)
8631a2
+{
8631a2
+  struct stat statbuf;
8631a2
+
8631a2
+  /* In general we should use lstat() here, not stat().  But on platforms
8631a2
+     without symbolic links, lstat() - if it exists - would be equivalent to
8631a2
+     stat(), therefore we can use stat().  This saves us a configure check.  */
8631a2
+  if (stat (name, &statbuf) >= 0)
8631a2
+    errno = EINVAL;
8631a2
+  return -1;
8631a2
+}
8631a2
+
8631a2
+#else /* HAVE_READLINK */
8631a2
+
8631a2
+# undef readlink
8631a2
+
8631a2
+/* readlink() wrapper that uses correct types, for systems like cygwin
8631a2
+   1.5.x where readlink returns int, and which rejects trailing slash,
8631a2
+   for Solaris 9.  */
8631a2
+
8631a2
+ssize_t
8631a2
+rpl_readlink (const char *name, char *buf, size_t bufsize)
8631a2
+{
8631a2
+# if READLINK_TRAILING_SLASH_BUG
8631a2
+  size_t len = strlen (name);
8631a2
+  if (len && name[len - 1] == '/')
8631a2
+    {
8631a2
+      /* Even if name without the slash is a symlink to a directory,
8631a2
+         both lstat() and stat() must resolve the trailing slash to
8631a2
+         the directory rather than the symlink.  We can therefore
8631a2
+         safely use stat() to distinguish between EINVAL and
8631a2
+         ENOTDIR/ENOENT, avoiding extra overhead of rpl_lstat().  */
8631a2
+      struct stat st;
8631a2
+      if (stat (name, &st) == 0)
8631a2
+        errno = EINVAL;
8631a2
+      return -1;
8631a2
+    }
8631a2
+# endif /* READLINK_TRAILING_SLASH_BUG */
8631a2
+  return readlink (name, buf, bufsize);
8631a2
+}
8631a2
+
8631a2
+#endif /* HAVE_READLINK */
8631a2
diff --git a/grub-core/gnulib/stat.c b/grub-core/gnulib/stat.c
8631a2
new file mode 100644
09e3cc
index 000000000..35f4b0b1a
8631a2
--- /dev/null
8631a2
+++ b/grub-core/gnulib/stat.c
8631a2
@@ -0,0 +1,138 @@
8631a2
+/* Work around platform bugs in stat.
8631a2
+   Copyright (C) 2009-2014 Free Software Foundation, Inc.
8631a2
+
8631a2
+   This program is free software: you can redistribute it and/or modify
8631a2
+   it under the terms of the GNU General Public License as published by
8631a2
+   the Free Software Foundation; either version 3 of the License, or
8631a2
+   (at your option) any later version.
8631a2
+
8631a2
+   This program is distributed in the hope that it will be useful,
8631a2
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
8631a2
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8631a2
+   GNU General Public License for more details.
8631a2
+
8631a2
+   You should have received a copy of the GNU General Public License
8631a2
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
8631a2
+
8631a2
+/* written by Eric Blake */
8631a2
+
8631a2
+/* If the user's config.h happens to include <sys/stat.h>, let it include only
8631a2
+   the system's <sys/stat.h> here, so that orig_stat doesn't recurse to
8631a2
+   rpl_stat.  */
8631a2
+#define __need_system_sys_stat_h
8631a2
+#include <config.h>
8631a2
+
8631a2
+/* Get the original definition of stat.  It might be defined as a macro.  */
8631a2
+#include <sys/types.h>
8631a2
+#include <sys/stat.h>
8631a2
+#undef __need_system_sys_stat_h
8631a2
+
8631a2
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
8631a2
+# if _GL_WINDOWS_64_BIT_ST_SIZE
8631a2
+#  undef stat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */
8631a2
+#  define stat _stati64
8631a2
+#  define REPLACE_FUNC_STAT_DIR 1
8631a2
+#  undef REPLACE_FUNC_STAT_FILE
8631a2
+# elif REPLACE_FUNC_STAT_FILE
8631a2
+/* mingw64 has a broken stat() function, based on _stat(), in libmingwex.a.
8631a2
+   Bypass it.  */
8631a2
+#  define stat _stat
8631a2
+#  define REPLACE_FUNC_STAT_DIR 1
8631a2
+#  undef REPLACE_FUNC_STAT_FILE
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+static int
8631a2
+orig_stat (const char *filename, struct stat *buf)
8631a2
+{
8631a2
+  return stat (filename, buf);
8631a2
+}
8631a2
+
8631a2
+/* Specification.  */
8631a2
+/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
8631a2
+   eliminates this include because of the preliminary #include <sys/stat.h>
8631a2
+   above.  */
8631a2
+#include "sys/stat.h"
8631a2
+
8631a2
+#include <errno.h>
8631a2
+#include <limits.h>
8631a2
+#include <stdbool.h>
8631a2
+#include <string.h>
8631a2
+#include "dosname.h"
8631a2
+#include "verify.h"
8631a2
+
8631a2
+#if REPLACE_FUNC_STAT_DIR
8631a2
+# include "pathmax.h"
8631a2
+  /* The only known systems where REPLACE_FUNC_STAT_DIR is needed also
8631a2
+     have a constant PATH_MAX.  */
8631a2
+# ifndef PATH_MAX
8631a2
+#  error "Please port this replacement to your platform"
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+/* Store information about NAME into ST.  Work around bugs with
8631a2
+   trailing slashes.  Mingw has other bugs (such as st_ino always
8631a2
+   being 0 on success) which this wrapper does not work around.  But
8631a2
+   at least this implementation provides the ability to emulate fchdir
8631a2
+   correctly.  */
8631a2
+
8631a2
+int
8631a2
+rpl_stat (char const *name, struct stat *st)
8631a2
+{
8631a2
+  int result = orig_stat (name, st);
8631a2
+#if REPLACE_FUNC_STAT_FILE
8631a2
+  /* Solaris 9 mistakenly succeeds when given a non-directory with a
8631a2
+     trailing slash.  */
8631a2
+  if (result == 0 && !S_ISDIR (st->st_mode))
8631a2
+    {
8631a2
+      size_t len = strlen (name);
8631a2
+      if (ISSLASH (name[len - 1]))
8631a2
+        {
8631a2
+          errno = ENOTDIR;
8631a2
+          return -1;
8631a2
+        }
8631a2
+    }
8631a2
+#endif /* REPLACE_FUNC_STAT_FILE */
8631a2
+#if REPLACE_FUNC_STAT_DIR
8631a2
+
8631a2
+  if (result == -1 && errno == ENOENT)
8631a2
+    {
8631a2
+      /* Due to mingw's oddities, there are some directories (like
8631a2
+         c:\) where stat() only succeeds with a trailing slash, and
8631a2
+         other directories (like c:\windows) where stat() only
8631a2
+         succeeds without a trailing slash.  But we want the two to be
8631a2
+         synonymous, since chdir() manages either style.  Likewise, Mingw also
8631a2
+         reports ENOENT for names longer than PATH_MAX, when we want
8631a2
+         ENAMETOOLONG, and for stat("file/"), when we want ENOTDIR.
8631a2
+         Fortunately, mingw PATH_MAX is small enough for stack
8631a2
+         allocation.  */
8631a2
+      char fixed_name[PATH_MAX + 1] = {0};
8631a2
+      size_t len = strlen (name);
8631a2
+      bool check_dir = false;
8631a2
+      verify (PATH_MAX <= 4096);
8631a2
+      if (PATH_MAX <= len)
8631a2
+        errno = ENAMETOOLONG;
8631a2
+      else if (len)
8631a2
+        {
8631a2
+          strcpy (fixed_name, name);
8631a2
+          if (ISSLASH (fixed_name[len - 1]))
8631a2
+            {
8631a2
+              check_dir = true;
8631a2
+              while (len && ISSLASH (fixed_name[len - 1]))
8631a2
+                fixed_name[--len] = '\0';
8631a2
+              if (!len)
8631a2
+                fixed_name[0] = '/';
8631a2
+            }
8631a2
+          else
8631a2
+            fixed_name[len++] = '/';
8631a2
+          result = orig_stat (fixed_name, st);
8631a2
+          if (result == 0 && check_dir && !S_ISDIR (st->st_mode))
8631a2
+            {
8631a2
+              result = -1;
8631a2
+              errno = ENOTDIR;
8631a2
+            }
8631a2
+        }
8631a2
+    }
8631a2
+#endif /* REPLACE_FUNC_STAT_DIR */
8631a2
+  return result;
8631a2
+}
8631a2
diff --git a/grub-core/osdep/windows/hostdisk.c b/grub-core/osdep/windows/hostdisk.c
09e3cc
index 85507af88..6f49df465 100644
8631a2
--- a/grub-core/osdep/windows/hostdisk.c
8631a2
+++ b/grub-core/osdep/windows/hostdisk.c
8631a2
@@ -353,6 +353,12 @@ grub_util_mkdir (const char *dir)
8631a2
   free (windows_name);
8631a2
 }
8631a2
 
8631a2
+ssize_t
8631a2
+grub_util_readlink (const char *name, char *buf, size_t bufsize)
8631a2
+{
8631a2
+  return readlink(name, buf, bufsize);
8631a2
+}
8631a2
+
8631a2
 int
8631a2
 grub_util_rename (const char *from, const char *to)
8631a2
 {
8631a2
diff --git a/grub-core/gnulib/pathmax.h b/grub-core/gnulib/pathmax.h
8631a2
new file mode 100644
09e3cc
index 000000000..33fc3553d
8631a2
--- /dev/null
8631a2
+++ b/grub-core/gnulib/pathmax.h
8631a2
@@ -0,0 +1,83 @@
8631a2
+/* Define PATH_MAX somehow.  Requires sys/types.h.
8631a2
+   Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-2014 Free Software
8631a2
+   Foundation, Inc.
8631a2
+
8631a2
+   This program is free software; you can redistribute it and/or modify
8631a2
+   it under the terms of the GNU General Public License as published by
8631a2
+   the Free Software Foundation; either version 3, or (at your option)
8631a2
+   any later version.
8631a2
+
8631a2
+   This program is distributed in the hope that it will be useful,
8631a2
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
8631a2
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8631a2
+   GNU General Public License for more details.
8631a2
+
8631a2
+   You should have received a copy of the GNU General Public License
8631a2
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
8631a2
+
8631a2
+#ifndef _PATHMAX_H
8631a2
+# define _PATHMAX_H
8631a2
+
8631a2
+/* POSIX:2008 defines PATH_MAX to be the maximum number of bytes in a filename,
8631a2
+   including the terminating NUL byte.
8631a2
+   <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html>
8631a2
+   PATH_MAX is not defined on systems which have no limit on filename length,
8631a2
+   such as GNU/Hurd.
8631a2
+
8631a2
+   This file does *not* define PATH_MAX always.  Programs that use this file
8631a2
+   can handle the GNU/Hurd case in several ways:
8631a2
+     - Either with a package-wide handling, or with a per-file handling,
8631a2
+     - Either through a
8631a2
+         #ifdef PATH_MAX
8631a2
+       or through a fallback like
8631a2
+         #ifndef PATH_MAX
8631a2
+         # define PATH_MAX 8192
8631a2
+         #endif
8631a2
+       or through a fallback like
8631a2
+         #ifndef PATH_MAX
8631a2
+         # define PATH_MAX pathconf ("/", _PC_PATH_MAX)
8631a2
+         #endif
8631a2
+ */
8631a2
+
8631a2
+# include <unistd.h>
8631a2
+
8631a2
+# include <limits.h>
8631a2
+
8631a2
+# ifndef _POSIX_PATH_MAX
8631a2
+#  define _POSIX_PATH_MAX 256
8631a2
+# endif
8631a2
+
8631a2
+/* Don't include sys/param.h if it already has been.  */
8631a2
+# if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
8631a2
+#  include <sys/param.h>
8631a2
+# endif
8631a2
+
8631a2
+# if !defined PATH_MAX && defined MAXPATHLEN
8631a2
+#  define PATH_MAX MAXPATHLEN
8631a2
+# endif
8631a2
+
8631a2
+# ifdef __hpux
8631a2
+/* On HP-UX, PATH_MAX designates the maximum number of bytes in a filename,
8631a2
+   *not* including the terminating NUL byte, and is set to 1023.
8631a2
+   Additionally, when _XOPEN_SOURCE is defined to 500 or more, PATH_MAX is
8631a2
+   not defined at all any more.  */
8631a2
+#  undef PATH_MAX
8631a2
+#  define PATH_MAX 1024
8631a2
+# endif
8631a2
+
8631a2
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
8631a2
+/* The page "Naming Files, Paths, and Namespaces" on msdn.microsoft.com,
8631a2
+   section "Maximum Path Length Limitation",
8631a2
+   <http://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx#maxpath>
8631a2
+   explains that the maximum size of a filename, including the terminating
8631a2
+   NUL byte, is 260 = 3 + 256 + 1.
8631a2
+   This is the same value as
8631a2
+     - FILENAME_MAX in <stdio.h>,
8631a2
+     - _MAX_PATH in <stdlib.h>,
8631a2
+     - MAX_PATH in <windef.h>.
8631a2
+   Undefine the original value, because mingw's <limits.h> gets it wrong.  */
8631a2
+#  undef PATH_MAX
8631a2
+#  define PATH_MAX 260
8631a2
+# endif
8631a2
+
8631a2
+#endif /* _PATHMAX_H */
8631a2
diff --git a/grub-core/gnulib/sys_stat.in.h b/grub-core/gnulib/sys_stat.in.h
8631a2
new file mode 100644
09e3cc
index 000000000..b47a7ff0a
8631a2
--- /dev/null
8631a2
+++ b/grub-core/gnulib/sys_stat.in.h
8631a2
@@ -0,0 +1,732 @@
8631a2
+/* Provide a more complete sys/stat header file.
8631a2
+   Copyright (C) 2005-2014 Free Software Foundation, Inc.
8631a2
+
8631a2
+   This program is free software; you can redistribute it and/or modify
8631a2
+   it under the terms of the GNU General Public License as published by
8631a2
+   the Free Software Foundation; either version 3, or (at your option)
8631a2
+   any later version.
8631a2
+
8631a2
+   This program is distributed in the hope that it will be useful,
8631a2
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
8631a2
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8631a2
+   GNU General Public License for more details.
8631a2
+
8631a2
+   You should have received a copy of the GNU General Public License
8631a2
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
8631a2
+
8631a2
+/* Written by Eric Blake, Paul Eggert, and Jim Meyering.  */
8631a2
+
8631a2
+/* This file is supposed to be used on platforms where <sys/stat.h> is
8631a2
+   incomplete.  It is intended to provide definitions and prototypes
8631a2
+   needed by an application.  Start with what the system provides.  */
8631a2
+
8631a2
+#if __GNUC__ >= 3
8631a2
+@PRAGMA_SYSTEM_HEADER@
8631a2
+#endif
8631a2
+@PRAGMA_COLUMNS@
8631a2
+
8631a2
+#if defined __need_system_sys_stat_h
8631a2
+/* Special invocation convention.  */
8631a2
+
8631a2
+#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
8631a2
+
8631a2
+#else
8631a2
+/* Normal invocation convention.  */
8631a2
+
8631a2
+#ifndef _@GUARD_PREFIX@_SYS_STAT_H
8631a2
+
8631a2
+/* Get nlink_t.
8631a2
+   May also define off_t to a 64-bit type on native Windows.  */
8631a2
+#include <sys/types.h>
8631a2
+
8631a2
+/* Get struct timespec.  */
8631a2
+#include <time.h>
8631a2
+
8631a2
+/* The include_next requires a split double-inclusion guard.  */
8631a2
+#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
8631a2
+
8631a2
+#ifndef _@GUARD_PREFIX@_SYS_STAT_H
8631a2
+#define _@GUARD_PREFIX@_SYS_STAT_H
8631a2
+
8631a2
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
8631a2
+
8631a2
+/* The definition of _GL_ARG_NONNULL is copied here.  */
8631a2
+
8631a2
+/* The definition of _GL_WARN_ON_USE is copied here.  */
8631a2
+
8631a2
+/* Before doing "#define mkdir rpl_mkdir" below, we need to include all
8631a2
+   headers that may declare mkdir().  Native Windows platforms declare mkdir
8631a2
+   in <io.h> and/or <direct.h>, not in <unistd.h>.  */
8631a2
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
8631a2
+# include <io.h>     /* mingw32, mingw64 */
8631a2
+# include <direct.h> /* mingw64, MSVC 9 */
8631a2
+#endif
8631a2
+
8631a2
+/* Native Windows platforms declare umask() in <io.h>.  */
8631a2
+#if 0 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
8631a2
+# include <io.h>
8631a2
+#endif
8631a2
+
8631a2
+/* Large File Support on native Windows.  */
8631a2
+#if @WINDOWS_64_BIT_ST_SIZE@
8631a2
+# define stat _stati64
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_IFIFO
8631a2
+# ifdef _S_IFIFO
8631a2
+#  define S_IFIFO _S_IFIFO
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_IFMT
8631a2
+# define S_IFMT 0170000
8631a2
+#endif
8631a2
+
8631a2
+#if STAT_MACROS_BROKEN
8631a2
+# undef S_ISBLK
8631a2
+# undef S_ISCHR
8631a2
+# undef S_ISDIR
8631a2
+# undef S_ISFIFO
8631a2
+# undef S_ISLNK
8631a2
+# undef S_ISNAM
8631a2
+# undef S_ISMPB
8631a2
+# undef S_ISMPC
8631a2
+# undef S_ISNWK
8631a2
+# undef S_ISREG
8631a2
+# undef S_ISSOCK
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_ISBLK
8631a2
+# ifdef S_IFBLK
8631a2
+#  define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
8631a2
+# else
8631a2
+#  define S_ISBLK(m) 0
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_ISCHR
8631a2
+# ifdef S_IFCHR
8631a2
+#  define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
8631a2
+# else
8631a2
+#  define S_ISCHR(m) 0
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_ISDIR
8631a2
+# ifdef S_IFDIR
8631a2
+#  define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
8631a2
+# else
8631a2
+#  define S_ISDIR(m) 0
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_ISDOOR /* Solaris 2.5 and up */
8631a2
+# define S_ISDOOR(m) 0
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_ISFIFO
8631a2
+# ifdef S_IFIFO
8631a2
+#  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
8631a2
+# else
8631a2
+#  define S_ISFIFO(m) 0
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_ISLNK
8631a2
+# ifdef S_IFLNK
8631a2
+#  define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
8631a2
+# else
8631a2
+#  define S_ISLNK(m) 0
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_ISMPB /* V7 */
8631a2
+# ifdef S_IFMPB
8631a2
+#  define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
8631a2
+#  define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
8631a2
+# else
8631a2
+#  define S_ISMPB(m) 0
8631a2
+#  define S_ISMPC(m) 0
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_ISMPX /* AIX */
8631a2
+# define S_ISMPX(m) 0
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_ISNAM /* Xenix */
8631a2
+# ifdef S_IFNAM
8631a2
+#  define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
8631a2
+# else
8631a2
+#  define S_ISNAM(m) 0
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_ISNWK /* HP/UX */
8631a2
+# ifdef S_IFNWK
8631a2
+#  define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
8631a2
+# else
8631a2
+#  define S_ISNWK(m) 0
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_ISPORT /* Solaris 10 and up */
8631a2
+# define S_ISPORT(m) 0
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_ISREG
8631a2
+# ifdef S_IFREG
8631a2
+#  define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
8631a2
+# else
8631a2
+#  define S_ISREG(m) 0
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_ISSOCK
8631a2
+# ifdef S_IFSOCK
8631a2
+#  define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
8631a2
+# else
8631a2
+#  define S_ISSOCK(m) 0
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+#ifndef S_TYPEISMQ
8631a2
+# define S_TYPEISMQ(p) 0
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_TYPEISTMO
8631a2
+# define S_TYPEISTMO(p) 0
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+#ifndef S_TYPEISSEM
8631a2
+# ifdef S_INSEM
8631a2
+#  define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
8631a2
+# else
8631a2
+#  define S_TYPEISSEM(p) 0
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_TYPEISSHM
8631a2
+# ifdef S_INSHD
8631a2
+#  define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
8631a2
+# else
8631a2
+#  define S_TYPEISSHM(p) 0
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+/* high performance ("contiguous data") */
8631a2
+#ifndef S_ISCTG
8631a2
+# define S_ISCTG(p) 0
8631a2
+#endif
8631a2
+
8631a2
+/* Cray DMF (data migration facility): off line, with data  */
8631a2
+#ifndef S_ISOFD
8631a2
+# define S_ISOFD(p) 0
8631a2
+#endif
8631a2
+
8631a2
+/* Cray DMF (data migration facility): off line, with no data  */
8631a2
+#ifndef S_ISOFL
8631a2
+# define S_ISOFL(p) 0
8631a2
+#endif
8631a2
+
8631a2
+/* 4.4BSD whiteout */
8631a2
+#ifndef S_ISWHT
8631a2
+# define S_ISWHT(m) 0
8631a2
+#endif
8631a2
+
8631a2
+/* If any of the following are undefined,
8631a2
+   define them to their de facto standard values.  */
8631a2
+#if !S_ISUID
8631a2
+# define S_ISUID 04000
8631a2
+#endif
8631a2
+#if !S_ISGID
8631a2
+# define S_ISGID 02000
8631a2
+#endif
8631a2
+
8631a2
+/* S_ISVTX is a common extension to POSIX.  */
8631a2
+#ifndef S_ISVTX
8631a2
+# define S_ISVTX 01000
8631a2
+#endif
8631a2
+
8631a2
+#if !S_IRUSR && S_IREAD
8631a2
+# define S_IRUSR S_IREAD
8631a2
+#endif
8631a2
+#if !S_IRUSR
8631a2
+# define S_IRUSR 00400
8631a2
+#endif
8631a2
+#if !S_IRGRP
8631a2
+# define S_IRGRP (S_IRUSR >> 3)
8631a2
+#endif
8631a2
+#if !S_IROTH
8631a2
+# define S_IROTH (S_IRUSR >> 6)
8631a2
+#endif
8631a2
+
8631a2
+#if !S_IWUSR && S_IWRITE
8631a2
+# define S_IWUSR S_IWRITE
8631a2
+#endif
8631a2
+#if !S_IWUSR
8631a2
+# define S_IWUSR 00200
8631a2
+#endif
8631a2
+#if !S_IWGRP
8631a2
+# define S_IWGRP (S_IWUSR >> 3)
8631a2
+#endif
8631a2
+#if !S_IWOTH
8631a2
+# define S_IWOTH (S_IWUSR >> 6)
8631a2
+#endif
8631a2
+
8631a2
+#if !S_IXUSR && S_IEXEC
8631a2
+# define S_IXUSR S_IEXEC
8631a2
+#endif
8631a2
+#if !S_IXUSR
8631a2
+# define S_IXUSR 00100
8631a2
+#endif
8631a2
+#if !S_IXGRP
8631a2
+# define S_IXGRP (S_IXUSR >> 3)
8631a2
+#endif
8631a2
+#if !S_IXOTH
8631a2
+# define S_IXOTH (S_IXUSR >> 6)
8631a2
+#endif
8631a2
+
8631a2
+#if !S_IRWXU
8631a2
+# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
8631a2
+#endif
8631a2
+#if !S_IRWXG
8631a2
+# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
8631a2
+#endif
8631a2
+#if !S_IRWXO
8631a2
+# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
8631a2
+#endif
8631a2
+
8631a2
+/* S_IXUGO is a common extension to POSIX.  */
8631a2
+#if !S_IXUGO
8631a2
+# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
8631a2
+#endif
8631a2
+
8631a2
+#ifndef S_IRWXUGO
8631a2
+# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
8631a2
+#endif
8631a2
+
8631a2
+/* Macros for futimens and utimensat.  */
8631a2
+#ifndef UTIME_NOW
8631a2
+# define UTIME_NOW (-1)
8631a2
+# define UTIME_OMIT (-2)
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+#if @GNULIB_FCHMODAT@
8631a2
+# if !@HAVE_FCHMODAT@
8631a2
+_GL_FUNCDECL_SYS (fchmodat, int,
8631a2
+                  (int fd, char const *file, mode_t mode, int flag)
8631a2
+                  _GL_ARG_NONNULL ((2)));
8631a2
+# endif
8631a2
+_GL_CXXALIAS_SYS (fchmodat, int,
8631a2
+                  (int fd, char const *file, mode_t mode, int flag));
8631a2
+_GL_CXXALIASWARN (fchmodat);
8631a2
+#elif defined GNULIB_POSIXCHECK
8631a2
+# undef fchmodat
8631a2
+# if HAVE_RAW_DECL_FCHMODAT
8631a2
+_GL_WARN_ON_USE (fchmodat, "fchmodat is not portable - "
8631a2
+                 "use gnulib module openat for portability");
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+#if @GNULIB_FSTAT@
8631a2
+# if @REPLACE_FSTAT@
8631a2
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#   undef fstat
8631a2
+#   define fstat rpl_fstat
8631a2
+#  endif
8631a2
+_GL_FUNCDECL_RPL (fstat, int, (int fd, struct stat *buf) _GL_ARG_NONNULL ((2)));
8631a2
+_GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf));
8631a2
+# else
8631a2
+_GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf));
8631a2
+# endif
8631a2
+_GL_CXXALIASWARN (fstat);
8631a2
+#elif @WINDOWS_64_BIT_ST_SIZE@
8631a2
+/* Above, we define stat to _stati64.  */
8631a2
+# define fstat _fstati64
8631a2
+#elif defined GNULIB_POSIXCHECK
8631a2
+# undef fstat
8631a2
+# if HAVE_RAW_DECL_FSTAT
8631a2
+_GL_WARN_ON_USE (fstat, "fstat has portability problems - "
8631a2
+                 "use gnulib module fstat for portability");
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+#if @GNULIB_FSTATAT@
8631a2
+# if @REPLACE_FSTATAT@
8631a2
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#   undef fstatat
8631a2
+#   define fstatat rpl_fstatat
8631a2
+#  endif
8631a2
+_GL_FUNCDECL_RPL (fstatat, int,
8631a2
+                  (int fd, char const *name, struct stat *st, int flags)
8631a2
+                  _GL_ARG_NONNULL ((2, 3)));
8631a2
+_GL_CXXALIAS_RPL (fstatat, int,
8631a2
+                  (int fd, char const *name, struct stat *st, int flags));
8631a2
+# else
8631a2
+#  if !@HAVE_FSTATAT@
8631a2
+_GL_FUNCDECL_SYS (fstatat, int,
8631a2
+                  (int fd, char const *name, struct stat *st, int flags)
8631a2
+                  _GL_ARG_NONNULL ((2, 3)));
8631a2
+#  endif
8631a2
+_GL_CXXALIAS_SYS (fstatat, int,
8631a2
+                  (int fd, char const *name, struct stat *st, int flags));
8631a2
+# endif
8631a2
+_GL_CXXALIASWARN (fstatat);
8631a2
+#elif defined GNULIB_POSIXCHECK
8631a2
+# undef fstatat
8631a2
+# if HAVE_RAW_DECL_FSTATAT
8631a2
+_GL_WARN_ON_USE (fstatat, "fstatat is not portable - "
8631a2
+                 "use gnulib module openat for portability");
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+#if @GNULIB_FUTIMENS@
8631a2
+/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our futimens
8631a2
+   implementation relies on futimesat, which on Solaris 10 makes an invocation
8631a2
+   to futimens that is meant to invoke the libc's futimens(), not gnulib's
8631a2
+   futimens().  */
8631a2
+# if @REPLACE_FUTIMENS@ || (!@HAVE_FUTIMENS@ && defined __sun)
8631a2
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#   undef futimens
8631a2
+#   define futimens rpl_futimens
8631a2
+#  endif
8631a2
+_GL_FUNCDECL_RPL (futimens, int, (int fd, struct timespec const times[2]));
8631a2
+_GL_CXXALIAS_RPL (futimens, int, (int fd, struct timespec const times[2]));
8631a2
+# else
8631a2
+#  if !@HAVE_FUTIMENS@
8631a2
+_GL_FUNCDECL_SYS (futimens, int, (int fd, struct timespec const times[2]));
8631a2
+#  endif
8631a2
+_GL_CXXALIAS_SYS (futimens, int, (int fd, struct timespec const times[2]));
8631a2
+# endif
8631a2
+# if @HAVE_FUTIMENS@
8631a2
+_GL_CXXALIASWARN (futimens);
8631a2
+# endif
8631a2
+#elif defined GNULIB_POSIXCHECK
8631a2
+# undef futimens
8631a2
+# if HAVE_RAW_DECL_FUTIMENS
8631a2
+_GL_WARN_ON_USE (futimens, "futimens is not portable - "
8631a2
+                 "use gnulib module futimens for portability");
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+#if @GNULIB_LCHMOD@
8631a2
+/* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
8631a2
+   denotes a symbolic link.  */
8631a2
+# if !@HAVE_LCHMOD@
8631a2
+/* The lchmod replacement follows symbolic links.  Callers should take
8631a2
+   this into account; lchmod should be applied only to arguments that
8631a2
+   are known to not be symbolic links.  On hosts that lack lchmod,
8631a2
+   this can lead to race conditions between the check and the
8631a2
+   invocation of lchmod, but we know of no workarounds that are
8631a2
+   reliable in general.  You might try requesting support for lchmod
8631a2
+   from your operating system supplier.  */
8631a2
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#   define lchmod chmod
8631a2
+#  endif
8631a2
+/* Need to cast, because on mingw, the second parameter of chmod is
8631a2
+                                                int mode.  */
8631a2
+_GL_CXXALIAS_RPL_CAST_1 (lchmod, chmod, int,
8631a2
+                         (const char *filename, mode_t mode));
8631a2
+# else
8631a2
+#  if 0 /* assume already declared */
8631a2
+_GL_FUNCDECL_SYS (lchmod, int, (const char *filename, mode_t mode)
8631a2
+                               _GL_ARG_NONNULL ((1)));
8631a2
+#  endif
8631a2
+_GL_CXXALIAS_SYS (lchmod, int, (const char *filename, mode_t mode));
8631a2
+# endif
8631a2
+# if @HAVE_LCHMOD@
8631a2
+_GL_CXXALIASWARN (lchmod);
8631a2
+# endif
8631a2
+#elif defined GNULIB_POSIXCHECK
8631a2
+# undef lchmod
8631a2
+# if HAVE_RAW_DECL_LCHMOD
8631a2
+_GL_WARN_ON_USE (lchmod, "lchmod is unportable - "
8631a2
+                 "use gnulib module lchmod for portability");
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+#if @GNULIB_LSTAT@
8631a2
+# if ! @HAVE_LSTAT@
8631a2
+/* mingw does not support symlinks, therefore it does not have lstat.  But
8631a2
+   without links, stat does just fine.  */
8631a2
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#   define lstat stat
8631a2
+#  endif
8631a2
+_GL_CXXALIAS_RPL_1 (lstat, stat, int, (const char *name, struct stat *buf));
8631a2
+# elif @REPLACE_LSTAT@
8631a2
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#   undef lstat
8631a2
+#   define lstat rpl_lstat
8631a2
+#  endif
8631a2
+_GL_FUNCDECL_RPL (lstat, int, (const char *name, struct stat *buf)
8631a2
+                              _GL_ARG_NONNULL ((1, 2)));
8631a2
+_GL_CXXALIAS_RPL (lstat, int, (const char *name, struct stat *buf));
8631a2
+# else
8631a2
+_GL_CXXALIAS_SYS (lstat, int, (const char *name, struct stat *buf));
8631a2
+# endif
8631a2
+# if @HAVE_LSTAT@
8631a2
+_GL_CXXALIASWARN (lstat);
8631a2
+# endif
8631a2
+#elif defined GNULIB_POSIXCHECK
8631a2
+# undef lstat
8631a2
+# if HAVE_RAW_DECL_LSTAT
8631a2
+_GL_WARN_ON_USE (lstat, "lstat is unportable - "
8631a2
+                 "use gnulib module lstat for portability");
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+#if @REPLACE_MKDIR@
8631a2
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#  undef mkdir
8631a2
+#  define mkdir rpl_mkdir
8631a2
+# endif
8631a2
+_GL_FUNCDECL_RPL (mkdir, int, (char const *name, mode_t mode)
8631a2
+                              _GL_ARG_NONNULL ((1)));
8631a2
+_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
8631a2
+#else
8631a2
+/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
8631a2
+   Additionally, it declares _mkdir (and depending on compile flags, an
8631a2
+   alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
8631a2
+   which are included above.  */
8631a2
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
8631a2
+
8631a2
+#  if !GNULIB_defined_rpl_mkdir
8631a2
+static int
8631a2
+rpl_mkdir (char const *name, mode_t mode)
8631a2
+{
8631a2
+  return _mkdir (name);
8631a2
+}
8631a2
+#   define GNULIB_defined_rpl_mkdir 1
8631a2
+#  endif
8631a2
+
8631a2
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#   define mkdir rpl_mkdir
8631a2
+#  endif
8631a2
+_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
8631a2
+# else
8631a2
+_GL_CXXALIAS_SYS (mkdir, int, (char const *name, mode_t mode));
8631a2
+# endif
8631a2
+#endif
8631a2
+_GL_CXXALIASWARN (mkdir);
8631a2
+
8631a2
+
8631a2
+#if @GNULIB_MKDIRAT@
8631a2
+# if !@HAVE_MKDIRAT@
8631a2
+_GL_FUNCDECL_SYS (mkdirat, int, (int fd, char const *file, mode_t mode)
8631a2
+                                _GL_ARG_NONNULL ((2)));
8631a2
+# endif
8631a2
+_GL_CXXALIAS_SYS (mkdirat, int, (int fd, char const *file, mode_t mode));
8631a2
+_GL_CXXALIASWARN (mkdirat);
8631a2
+#elif defined GNULIB_POSIXCHECK
8631a2
+# undef mkdirat
8631a2
+# if HAVE_RAW_DECL_MKDIRAT
8631a2
+_GL_WARN_ON_USE (mkdirat, "mkdirat is not portable - "
8631a2
+                 "use gnulib module openat for portability");
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+#if @GNULIB_MKFIFO@
8631a2
+# if @REPLACE_MKFIFO@
8631a2
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#   undef mkfifo
8631a2
+#   define mkfifo rpl_mkfifo
8631a2
+#  endif
8631a2
+_GL_FUNCDECL_RPL (mkfifo, int, (char const *file, mode_t mode)
8631a2
+                               _GL_ARG_NONNULL ((1)));
8631a2
+_GL_CXXALIAS_RPL (mkfifo, int, (char const *file, mode_t mode));
8631a2
+# else
8631a2
+#  if !@HAVE_MKFIFO@
8631a2
+_GL_FUNCDECL_SYS (mkfifo, int, (char const *file, mode_t mode)
8631a2
+                               _GL_ARG_NONNULL ((1)));
8631a2
+#  endif
8631a2
+_GL_CXXALIAS_SYS (mkfifo, int, (char const *file, mode_t mode));
8631a2
+# endif
8631a2
+_GL_CXXALIASWARN (mkfifo);
8631a2
+#elif defined GNULIB_POSIXCHECK
8631a2
+# undef mkfifo
8631a2
+# if HAVE_RAW_DECL_MKFIFO
8631a2
+_GL_WARN_ON_USE (mkfifo, "mkfifo is not portable - "
8631a2
+                 "use gnulib module mkfifo for portability");
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+#if @GNULIB_MKFIFOAT@
8631a2
+# if !@HAVE_MKFIFOAT@
8631a2
+_GL_FUNCDECL_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode)
8631a2
+                                 _GL_ARG_NONNULL ((2)));
8631a2
+# endif
8631a2
+_GL_CXXALIAS_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode));
8631a2
+_GL_CXXALIASWARN (mkfifoat);
8631a2
+#elif defined GNULIB_POSIXCHECK
8631a2
+# undef mkfifoat
8631a2
+# if HAVE_RAW_DECL_MKFIFOAT
8631a2
+_GL_WARN_ON_USE (mkfifoat, "mkfifoat is not portable - "
8631a2
+                 "use gnulib module mkfifoat for portability");
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+#if @GNULIB_MKNOD@
8631a2
+# if @REPLACE_MKNOD@
8631a2
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#   undef mknod
8631a2
+#   define mknod rpl_mknod
8631a2
+#  endif
8631a2
+_GL_FUNCDECL_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev)
8631a2
+                              _GL_ARG_NONNULL ((1)));
8631a2
+_GL_CXXALIAS_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev));
8631a2
+# else
8631a2
+#  if !@HAVE_MKNOD@
8631a2
+_GL_FUNCDECL_SYS (mknod, int, (char const *file, mode_t mode, dev_t dev)
8631a2
+                              _GL_ARG_NONNULL ((1)));
8631a2
+#  endif
8631a2
+/* Need to cast, because on OSF/1 5.1, the third parameter is '...'.  */
8631a2
+_GL_CXXALIAS_SYS_CAST (mknod, int, (char const *file, mode_t mode, dev_t dev));
8631a2
+# endif
8631a2
+_GL_CXXALIASWARN (mknod);
8631a2
+#elif defined GNULIB_POSIXCHECK
8631a2
+# undef mknod
8631a2
+# if HAVE_RAW_DECL_MKNOD
8631a2
+_GL_WARN_ON_USE (mknod, "mknod is not portable - "
8631a2
+                 "use gnulib module mknod for portability");
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+#if @GNULIB_MKNODAT@
8631a2
+# if !@HAVE_MKNODAT@
8631a2
+_GL_FUNCDECL_SYS (mknodat, int,
8631a2
+                  (int fd, char const *file, mode_t mode, dev_t dev)
8631a2
+                  _GL_ARG_NONNULL ((2)));
8631a2
+# endif
8631a2
+_GL_CXXALIAS_SYS (mknodat, int,
8631a2
+                  (int fd, char const *file, mode_t mode, dev_t dev));
8631a2
+_GL_CXXALIASWARN (mknodat);
8631a2
+#elif defined GNULIB_POSIXCHECK
8631a2
+# undef mknodat
8631a2
+# if HAVE_RAW_DECL_MKNODAT
8631a2
+_GL_WARN_ON_USE (mknodat, "mknodat is not portable - "
8631a2
+                 "use gnulib module mkfifoat for portability");
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+#if @GNULIB_STAT@
8631a2
+# if @REPLACE_STAT@
8631a2
+/* We can't use the object-like #define stat rpl_stat, because of
8631a2
+   struct stat.  This means that rpl_stat will not be used if the user
8631a2
+   does (stat)(a,b).  Oh well.  */
8631a2
+#  if defined _AIX && defined stat && defined _LARGE_FILES
8631a2
+    /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
8631a2
+       so we have to replace stat64() instead of stat(). */
8631a2
+#   undef stat64
8631a2
+#   define stat64(name, st) rpl_stat (name, st)
8631a2
+#  elif @WINDOWS_64_BIT_ST_SIZE@
8631a2
+    /* Above, we define stat to _stati64.  */
8631a2
+#   if defined __MINGW32__ && defined _stati64
8631a2
+#    ifndef _USE_32BIT_TIME_T
8631a2
+      /* The system headers define _stati64 to _stat64.  */
8631a2
+#     undef _stat64
8631a2
+#     define _stat64(name, st) rpl_stat (name, st)
8631a2
+#    endif
8631a2
+#   elif defined _MSC_VER && defined _stati64
8631a2
+#    ifdef _USE_32BIT_TIME_T
8631a2
+      /* The system headers define _stati64 to _stat32i64.  */
8631a2
+#     undef _stat32i64
8631a2
+#     define _stat32i64(name, st) rpl_stat (name, st)
8631a2
+#    else
8631a2
+      /* The system headers define _stati64 to _stat64.  */
8631a2
+#     undef _stat64
8631a2
+#     define _stat64(name, st) rpl_stat (name, st)
8631a2
+#    endif
8631a2
+#   else
8631a2
+#    undef _stati64
8631a2
+#    define _stati64(name, st) rpl_stat (name, st)
8631a2
+#   endif
8631a2
+#  elif defined __MINGW32__ && defined stat
8631a2
+#   ifdef _USE_32BIT_TIME_T
8631a2
+     /* The system headers define stat to _stat32i64.  */
8631a2
+#    undef _stat32i64
8631a2
+#    define _stat32i64(name, st) rpl_stat (name, st)
8631a2
+#   else
8631a2
+     /* The system headers define stat to _stat64.  */
8631a2
+#    undef _stat64
8631a2
+#    define _stat64(name, st) rpl_stat (name, st)
8631a2
+#   endif
8631a2
+#  elif defined _MSC_VER && defined stat
8631a2
+#   ifdef _USE_32BIT_TIME_T
8631a2
+     /* The system headers define stat to _stat32.  */
8631a2
+#    undef _stat32
8631a2
+#    define _stat32(name, st) rpl_stat (name, st)
8631a2
+#   else
8631a2
+     /* The system headers define stat to _stat64i32.  */
8631a2
+#    undef _stat64i32
8631a2
+#    define _stat64i32(name, st) rpl_stat (name, st)
8631a2
+#   endif
8631a2
+#  else /* !(_AIX ||__MINGW32__ ||  _MSC_VER) */
8631a2
+#   undef stat
8631a2
+#   define stat(name, st) rpl_stat (name, st)
8631a2
+#  endif /* !_LARGE_FILES */
8631a2
+_GL_EXTERN_C int stat (const char *name, struct stat *buf)
8631a2
+                      _GL_ARG_NONNULL ((1, 2));
8631a2
+# endif
8631a2
+#elif defined GNULIB_POSIXCHECK
8631a2
+# undef stat
8631a2
+# if HAVE_RAW_DECL_STAT
8631a2
+_GL_WARN_ON_USE (stat, "stat is unportable - "
8631a2
+                 "use gnulib module stat for portability");
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+#if @GNULIB_UTIMENSAT@
8631a2
+/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our utimensat
8631a2
+   implementation relies on futimesat, which on Solaris 10 makes an invocation
8631a2
+   to utimensat that is meant to invoke the libc's utimensat(), not gnulib's
8631a2
+   utimensat().  */
8631a2
+# if @REPLACE_UTIMENSAT@ || (!@HAVE_UTIMENSAT@ && defined __sun)
8631a2
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#   undef utimensat
8631a2
+#   define utimensat rpl_utimensat
8631a2
+#  endif
8631a2
+_GL_FUNCDECL_RPL (utimensat, int, (int fd, char const *name,
8631a2
+                                   struct timespec const times[2], int flag)
8631a2
+                                  _GL_ARG_NONNULL ((2)));
8631a2
+_GL_CXXALIAS_RPL (utimensat, int, (int fd, char const *name,
8631a2
+                                   struct timespec const times[2], int flag));
8631a2
+# else
8631a2
+#  if !@HAVE_UTIMENSAT@
8631a2
+_GL_FUNCDECL_SYS (utimensat, int, (int fd, char const *name,
8631a2
+                                   struct timespec const times[2], int flag)
8631a2
+                                  _GL_ARG_NONNULL ((2)));
8631a2
+#  endif
8631a2
+_GL_CXXALIAS_SYS (utimensat, int, (int fd, char const *name,
8631a2
+                                   struct timespec const times[2], int flag));
8631a2
+# endif
8631a2
+# if @HAVE_UTIMENSAT@
8631a2
+_GL_CXXALIASWARN (utimensat);
8631a2
+# endif
8631a2
+#elif defined GNULIB_POSIXCHECK
8631a2
+# undef utimensat
8631a2
+# if HAVE_RAW_DECL_UTIMENSAT
8631a2
+_GL_WARN_ON_USE (utimensat, "utimensat is not portable - "
8631a2
+                 "use gnulib module utimensat for portability");
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+#endif /* _@GUARD_PREFIX@_SYS_STAT_H */
8631a2
+#endif /* _@GUARD_PREFIX@_SYS_STAT_H */
8631a2
+#endif
8631a2
diff --git a/grub-core/gnulib/sys_time.in.h b/grub-core/gnulib/sys_time.in.h
8631a2
new file mode 100644
09e3cc
index 000000000..30057ad49
8631a2
--- /dev/null
8631a2
+++ b/grub-core/gnulib/sys_time.in.h
8631a2
@@ -0,0 +1,213 @@
8631a2
+/* Provide a more complete sys/time.h.
8631a2
+
8631a2
+   Copyright (C) 2007-2014 Free Software Foundation, Inc.
8631a2
+
8631a2
+   This program is free software; you can redistribute it and/or modify
8631a2
+   it under the terms of the GNU General Public License as published by
8631a2
+   the Free Software Foundation; either version 3, or (at your option)
8631a2
+   any later version.
8631a2
+
8631a2
+   This program is distributed in the hope that it will be useful,
8631a2
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
8631a2
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8631a2
+   GNU General Public License for more details.
8631a2
+
8631a2
+   You should have received a copy of the GNU General Public License
8631a2
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
8631a2
+
8631a2
+/* Written by Paul Eggert.  */
8631a2
+
8631a2
+#ifndef _@GUARD_PREFIX@_SYS_TIME_H
8631a2
+
8631a2
+#if __GNUC__ >= 3
8631a2
+@PRAGMA_SYSTEM_HEADER@
8631a2
+#endif
8631a2
+@PRAGMA_COLUMNS@
8631a2
+
8631a2
+/* On Cygwin and on many BSDish systems, <sys/time.h> includes itself
8631a2
+   recursively via <sys/select.h>.
8631a2
+   Simply delegate to the system's header in this case; it is a no-op.
8631a2
+   Without this extra ifdef, the C++ gettimeofday declaration below
8631a2
+   would be a forward declaration in gnulib's nested <sys/time.h>.  */
8631a2
+#if defined _CYGWIN_SYS_TIME_H || defined _SYS_TIME_H || defined _SYS_TIME_H_
8631a2
+# @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@
8631a2
+#else
8631a2
+
8631a2
+/* The include_next requires a split double-inclusion guard.  */
8631a2
+#if @HAVE_SYS_TIME_H@
8631a2
+# @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@
8631a2
+#endif
8631a2
+
8631a2
+#ifndef _@GUARD_PREFIX@_SYS_TIME_H
8631a2
+#define _@GUARD_PREFIX@_SYS_TIME_H
8631a2
+
8631a2
+#if ! @HAVE_SYS_TIME_H@
8631a2
+# include <time.h>
8631a2
+#endif
8631a2
+
8631a2
+/* On native Windows with MSVC, get the 'struct timeval' type.
8631a2
+   Also, on native Windows with a 64-bit time_t, where we are overriding the
8631a2
+   'struct timeval' type, get all declarations of system functions whose
8631a2
+   signature contains 'struct timeval'.  */
8631a2
+#if (defined _MSC_VER || @REPLACE_STRUCT_TIMEVAL@) && @HAVE_WINSOCK2_H@ && !defined _GL_INCLUDING_WINSOCK2_H
8631a2
+# define _GL_INCLUDING_WINSOCK2_H
8631a2
+# include <winsock2.h>
8631a2
+# undef _GL_INCLUDING_WINSOCK2_H
8631a2
+#endif
8631a2
+
8631a2
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
8631a2
+
8631a2
+/* The definition of _GL_ARG_NONNULL is copied here.  */
8631a2
+
8631a2
+/* The definition of _GL_WARN_ON_USE is copied here.  */
8631a2
+
8631a2
+#ifdef __cplusplus
8631a2
+extern "C" {
8631a2
+#endif
8631a2
+
8631a2
+#if !@HAVE_STRUCT_TIMEVAL@ || @REPLACE_STRUCT_TIMEVAL@
8631a2
+
8631a2
+# if @REPLACE_STRUCT_TIMEVAL@
8631a2
+#  define timeval rpl_timeval
8631a2
+# endif
8631a2
+
8631a2
+# if !GNULIB_defined_struct_timeval
8631a2
+struct timeval
8631a2
+{
8631a2
+  time_t tv_sec;
8631a2
+  long int tv_usec;
8631a2
+};
8631a2
+#  define GNULIB_defined_struct_timeval 1
8631a2
+# endif
8631a2
+
8631a2
+#endif
8631a2
+
8631a2
+#ifdef __cplusplus
8631a2
+}
8631a2
+#endif
8631a2
+
8631a2
+#if @GNULIB_GETTIMEOFDAY@
8631a2
+# if @REPLACE_GETTIMEOFDAY@
8631a2
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#   undef gettimeofday
8631a2
+#   define gettimeofday rpl_gettimeofday
8631a2
+#  endif
8631a2
+_GL_FUNCDECL_RPL (gettimeofday, int,
8631a2
+                  (struct timeval *restrict, void *restrict)
8631a2
+                  _GL_ARG_NONNULL ((1)));
8631a2
+_GL_CXXALIAS_RPL (gettimeofday, int,
8631a2
+                  (struct timeval *restrict, void *restrict));
8631a2
+# else
8631a2
+#  if !@HAVE_GETTIMEOFDAY@
8631a2
+_GL_FUNCDECL_SYS (gettimeofday, int,
8631a2
+                  (struct timeval *restrict, void *restrict)
8631a2
+                  _GL_ARG_NONNULL ((1)));
8631a2
+#  endif
8631a2
+/* Need to cast, because on glibc systems, by default, the second argument is
8631a2
+                                                  struct timezone *.  */
8631a2
+_GL_CXXALIAS_SYS_CAST (gettimeofday, int,
8631a2
+                       (struct timeval *restrict, void *restrict));
8631a2
+# endif
8631a2
+_GL_CXXALIASWARN (gettimeofday);
8631a2
+#elif defined GNULIB_POSIXCHECK
8631a2
+# undef gettimeofday
8631a2
+# if HAVE_RAW_DECL_GETTIMEOFDAY
8631a2
+_GL_WARN_ON_USE (gettimeofday, "gettimeofday is unportable - "
8631a2
+                 "use gnulib module gettimeofday for portability");
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+/* Hide some function declarations from <winsock2.h>.  */
8631a2
+
8631a2
+#if defined _MSC_VER && @HAVE_WINSOCK2_H@
8631a2
+# if !defined _@GUARD_PREFIX@_UNISTD_H
8631a2
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#   undef close
8631a2
+#   define close close_used_without_including_unistd_h
8631a2
+#  else
8631a2
+     _GL_WARN_ON_USE (close,
8631a2
+                      "close() used without including <unistd.h>");
8631a2
+#  endif
8631a2
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#   undef gethostname
8631a2
+#   define gethostname gethostname_used_without_including_unistd_h
8631a2
+#  else
8631a2
+     _GL_WARN_ON_USE (gethostname,
8631a2
+                      "gethostname() used without including <unistd.h>");
8631a2
+#  endif
8631a2
+# endif
8631a2
+# if !defined _@GUARD_PREFIX@_SYS_SOCKET_H
8631a2
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#   undef socket
8631a2
+#   define socket              socket_used_without_including_sys_socket_h
8631a2
+#   undef connect
8631a2
+#   define connect             connect_used_without_including_sys_socket_h
8631a2
+#   undef accept
8631a2
+#   define accept              accept_used_without_including_sys_socket_h
8631a2
+#   undef bind
8631a2
+#   define bind                bind_used_without_including_sys_socket_h
8631a2
+#   undef getpeername
8631a2
+#   define getpeername         getpeername_used_without_including_sys_socket_h
8631a2
+#   undef getsockname
8631a2
+#   define getsockname         getsockname_used_without_including_sys_socket_h
8631a2
+#   undef getsockopt
8631a2
+#   define getsockopt          getsockopt_used_without_including_sys_socket_h
8631a2
+#   undef listen
8631a2
+#   define listen              listen_used_without_including_sys_socket_h
8631a2
+#   undef recv
8631a2
+#   define recv                recv_used_without_including_sys_socket_h
8631a2
+#   undef send
8631a2
+#   define send                send_used_without_including_sys_socket_h
8631a2
+#   undef recvfrom
8631a2
+#   define recvfrom            recvfrom_used_without_including_sys_socket_h
8631a2
+#   undef sendto
8631a2
+#   define sendto              sendto_used_without_including_sys_socket_h
8631a2
+#   undef setsockopt
8631a2
+#   define setsockopt          setsockopt_used_without_including_sys_socket_h
8631a2
+#   undef shutdown
8631a2
+#   define shutdown            shutdown_used_without_including_sys_socket_h
8631a2
+#  else
8631a2
+     _GL_WARN_ON_USE (socket,
8631a2
+                      "socket() used without including <sys/socket.h>");
8631a2
+     _GL_WARN_ON_USE (connect,
8631a2
+                      "connect() used without including <sys/socket.h>");
8631a2
+     _GL_WARN_ON_USE (accept,
8631a2
+                      "accept() used without including <sys/socket.h>");
8631a2
+     _GL_WARN_ON_USE (bind,
8631a2
+                      "bind() used without including <sys/socket.h>");
8631a2
+     _GL_WARN_ON_USE (getpeername,
8631a2
+                      "getpeername() used without including <sys/socket.h>");
8631a2
+     _GL_WARN_ON_USE (getsockname,
8631a2
+                      "getsockname() used without including <sys/socket.h>");
8631a2
+     _GL_WARN_ON_USE (getsockopt,
8631a2
+                      "getsockopt() used without including <sys/socket.h>");
8631a2
+     _GL_WARN_ON_USE (listen,
8631a2
+                      "listen() used without including <sys/socket.h>");
8631a2
+     _GL_WARN_ON_USE (recv,
8631a2
+                      "recv() used without including <sys/socket.h>");
8631a2
+     _GL_WARN_ON_USE (send,
8631a2
+                      "send() used without including <sys/socket.h>");
8631a2
+     _GL_WARN_ON_USE (recvfrom,
8631a2
+                      "recvfrom() used without including <sys/socket.h>");
8631a2
+     _GL_WARN_ON_USE (sendto,
8631a2
+                      "sendto() used without including <sys/socket.h>");
8631a2
+     _GL_WARN_ON_USE (setsockopt,
8631a2
+                      "setsockopt() used without including <sys/socket.h>");
8631a2
+     _GL_WARN_ON_USE (shutdown,
8631a2
+                      "shutdown() used without including <sys/socket.h>");
8631a2
+#  endif
8631a2
+# endif
8631a2
+# if !defined _@GUARD_PREFIX@_SYS_SELECT_H
8631a2
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#   undef select
8631a2
+#   define select select_used_without_including_sys_select_h
8631a2
+#  else
8631a2
+     _GL_WARN_ON_USE (select,
8631a2
+                      "select() used without including <sys/select.h>");
8631a2
+#  endif
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+#endif /* _@GUARD_PREFIX@_SYS_TIME_H */
8631a2
+#endif /* _CYGWIN_SYS_TIME_H */
8631a2
+#endif /* _@GUARD_PREFIX@_SYS_TIME_H */
8631a2
diff --git a/grub-core/gnulib/sys_types.in.h b/grub-core/gnulib/sys_types.in.h
09e3cc
index d7da35623..9520c0903 100644
8631a2
--- a/grub-core/gnulib/sys_types.in.h
8631a2
+++ b/grub-core/gnulib/sys_types.in.h
8631a2
@@ -23,7 +23,9 @@
8631a2
 #ifndef _@GUARD_PREFIX@_SYS_TYPES_H
8631a2
 
8631a2
 /* The include_next requires a split double-inclusion guard.  */
8631a2
+# define _GL_INCLUDING_SYS_TYPES_H
8631a2
 #@INCLUDE_NEXT@ @NEXT_SYS_TYPES_H@
8631a2
+# undef _GL_INCLUDING_SYS_TYPES_H
8631a2
 
8631a2
 #ifndef _@GUARD_PREFIX@_SYS_TYPES_H
8631a2
 #define _@GUARD_PREFIX@_SYS_TYPES_H
8631a2
diff --git a/grub-core/gnulib/time.h b/grub-core/gnulib/time.h
8631a2
new file mode 100644
09e3cc
index 000000000..b9203d556
8631a2
--- /dev/null
8631a2
+++ b/grub-core/gnulib/time.h
8631a2
@@ -0,0 +1,586 @@
8631a2
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
8631a2
+/* A more-standard <time.h>.
8631a2
+
8631a2
+   Copyright (C) 2007-2014 Free Software Foundation, Inc.
8631a2
+
8631a2
+   This program is free software; you can redistribute it and/or modify
8631a2
+   it under the terms of the GNU General Public License as published by
8631a2
+   the Free Software Foundation; either version 3, or (at your option)
8631a2
+   any later version.
8631a2
+
8631a2
+   This program is distributed in the hope that it will be useful,
8631a2
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
8631a2
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8631a2
+   GNU General Public License for more details.
8631a2
+
8631a2
+   You should have received a copy of the GNU General Public License
8631a2
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
8631a2
+
8631a2
+#if __GNUC__ >= 3
8631a2
+#pragma GCC system_header
8631a2
+#endif
8631a2
+
8631a2
+
8631a2
+/* Don't get in the way of glibc when it includes time.h merely to
8631a2
+   declare a few standard symbols, rather than to declare all the
8631a2
+   symbols.  Also, Solaris 8 <time.h> eventually includes itself
8631a2
+   recursively; if that is happening, just include the system <time.h>
8631a2
+   without adding our own declarations.  */
8631a2
+#if (defined __need_time_t || defined __need_clock_t \
8631a2
+     || defined __need_timespec \
8631a2
+     || defined _GL_TIME_H)
8631a2
+
8631a2
+# include_next <time.h>
8631a2
+
8631a2
+#else
8631a2
+
8631a2
+# define _GL_TIME_H
8631a2
+
8631a2
+# include_next <time.h>
8631a2
+
8631a2
+/* NetBSD 5.0 mis-defines NULL.  */
8631a2
+# include <stddef.h>
8631a2
+
8631a2
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
8631a2
+#ifndef _GL_CXXDEFS_H
8631a2
+#define _GL_CXXDEFS_H
8631a2
+
8631a2
+/* The three most frequent use cases of these macros are:
8631a2
+
8631a2
+   * For providing a substitute for a function that is missing on some
8631a2
+     platforms, but is declared and works fine on the platforms on which
8631a2
+     it exists:
8631a2
+
8631a2
+       #if @GNULIB_FOO@
8631a2
+       # if !@HAVE_FOO@
8631a2
+       _GL_FUNCDECL_SYS (foo, ...);
8631a2
+       # endif
8631a2
+       _GL_CXXALIAS_SYS (foo, ...);
8631a2
+       _GL_CXXALIASWARN (foo);
8631a2
+       #elif defined GNULIB_POSIXCHECK
8631a2
+       ...
8631a2
+       #endif
8631a2
+
8631a2
+   * For providing a replacement for a function that exists on all platforms,
8631a2
+     but is broken/insufficient and needs to be replaced on some platforms:
8631a2
+
8631a2
+       #if @GNULIB_FOO@
8631a2
+       # if @REPLACE_FOO@
8631a2
+       #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+       #   undef foo
8631a2
+       #   define foo rpl_foo
8631a2
+       #  endif
8631a2
+       _GL_FUNCDECL_RPL (foo, ...);
8631a2
+       _GL_CXXALIAS_RPL (foo, ...);
8631a2
+       # else
8631a2
+       _GL_CXXALIAS_SYS (foo, ...);
8631a2
+       # endif
8631a2
+       _GL_CXXALIASWARN (foo);
8631a2
+       #elif defined GNULIB_POSIXCHECK
8631a2
+       ...
8631a2
+       #endif
8631a2
+
8631a2
+   * For providing a replacement for a function that exists on some platforms
8631a2
+     but is broken/insufficient and needs to be replaced on some of them and
8631a2
+     is additionally either missing or undeclared on some other platforms:
8631a2
+
8631a2
+       #if @GNULIB_FOO@
8631a2
+       # if @REPLACE_FOO@
8631a2
+       #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+       #   undef foo
8631a2
+       #   define foo rpl_foo
8631a2
+       #  endif
8631a2
+       _GL_FUNCDECL_RPL (foo, ...);
8631a2
+       _GL_CXXALIAS_RPL (foo, ...);
8631a2
+       # else
8631a2
+       #  if !@HAVE_FOO@   or   if !@HAVE_DECL_FOO@
8631a2
+       _GL_FUNCDECL_SYS (foo, ...);
8631a2
+       #  endif
8631a2
+       _GL_CXXALIAS_SYS (foo, ...);
8631a2
+       # endif
8631a2
+       _GL_CXXALIASWARN (foo);
8631a2
+       #elif defined GNULIB_POSIXCHECK
8631a2
+       ...
8631a2
+       #endif
8631a2
+*/
8631a2
+
8631a2
+/* _GL_EXTERN_C declaration;
8631a2
+   performs the declaration with C linkage.  */
8631a2
+#if defined __cplusplus
8631a2
+# define _GL_EXTERN_C extern "C"
8631a2
+#else
8631a2
+# define _GL_EXTERN_C extern
8631a2
+#endif
8631a2
+
8631a2
+/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
8631a2
+   declares a replacement function, named rpl_func, with the given prototype,
8631a2
+   consisting of return type, parameters, and attributes.
8631a2
+   Example:
8631a2
+     _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
8631a2
+                                  _GL_ARG_NONNULL ((1)));
8631a2
+ */
8631a2
+#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
8631a2
+  _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
8631a2
+#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
8631a2
+  _GL_EXTERN_C rettype rpl_func parameters_and_attributes
8631a2
+
8631a2
+/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
8631a2
+   declares the system function, named func, with the given prototype,
8631a2
+   consisting of return type, parameters, and attributes.
8631a2
+   Example:
8631a2
+     _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
8631a2
+                                  _GL_ARG_NONNULL ((1)));
8631a2
+ */
8631a2
+#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
8631a2
+  _GL_EXTERN_C rettype func parameters_and_attributes
8631a2
+
8631a2
+/* _GL_CXXALIAS_RPL (func, rettype, parameters);
8631a2
+   declares a C++ alias called GNULIB_NAMESPACE::func
8631a2
+   that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
8631a2
+   Example:
8631a2
+     _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
8631a2
+ */
8631a2
+#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
8631a2
+  _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
8631a2
+#if defined __cplusplus && defined GNULIB_NAMESPACE
8631a2
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
8631a2
+    namespace GNULIB_NAMESPACE                                \
8631a2
+    {                                                         \
8631a2
+      rettype (*const func) parameters = ::rpl_func;          \
8631a2
+    }                                                         \
8631a2
+    _GL_EXTERN_C int _gl_cxxalias_dummy
8631a2
+#else
8631a2
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
8631a2
+    _GL_EXTERN_C int _gl_cxxalias_dummy
8631a2
+#endif
8631a2
+
8631a2
+/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
8631a2
+   is like  _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
8631a2
+   except that the C function rpl_func may have a slightly different
8631a2
+   declaration.  A cast is used to silence the "invalid conversion" error
8631a2
+   that would otherwise occur.  */
8631a2
+#if defined __cplusplus && defined GNULIB_NAMESPACE
8631a2
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
8631a2
+    namespace GNULIB_NAMESPACE                                     \
8631a2
+    {                                                              \
8631a2
+      rettype (*const func) parameters =                           \
8631a2
+        reinterpret_cast<rettype(*)parameters>(::rpl_func);        \
8631a2
+    }                                                              \
8631a2
+    _GL_EXTERN_C int _gl_cxxalias_dummy
8631a2
+#else
8631a2
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
8631a2
+    _GL_EXTERN_C int _gl_cxxalias_dummy
8631a2
+#endif
8631a2
+
8631a2
+/* _GL_CXXALIAS_SYS (func, rettype, parameters);
8631a2
+   declares a C++ alias called GNULIB_NAMESPACE::func
8631a2
+   that redirects to the system provided function func, if GNULIB_NAMESPACE
8631a2
+   is defined.
8631a2
+   Example:
8631a2
+     _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
8631a2
+ */
8631a2
+#if defined __cplusplus && defined GNULIB_NAMESPACE
8631a2
+  /* If we were to write
8631a2
+       rettype (*const func) parameters = ::func;
8631a2
+     like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
8631a2
+     better (remove an indirection through a 'static' pointer variable),
8631a2
+     but then the _GL_CXXALIASWARN macro below would cause a warning not only
8631a2
+     for uses of ::func but also for uses of GNULIB_NAMESPACE::func.  */
8631a2
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
8631a2
+    namespace GNULIB_NAMESPACE                     \
8631a2
+    {                                              \
8631a2
+      static rettype (*func) parameters = ::func;  \
8631a2
+    }                                              \
8631a2
+    _GL_EXTERN_C int _gl_cxxalias_dummy
8631a2
+#else
8631a2
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
8631a2
+    _GL_EXTERN_C int _gl_cxxalias_dummy
8631a2
+#endif
8631a2
+
8631a2
+/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
8631a2
+   is like  _GL_CXXALIAS_SYS (func, rettype, parameters);
8631a2
+   except that the C function func may have a slightly different declaration.
8631a2
+   A cast is used to silence the "invalid conversion" error that would
8631a2
+   otherwise occur.  */
8631a2
+#if defined __cplusplus && defined GNULIB_NAMESPACE
8631a2
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
8631a2
+    namespace GNULIB_NAMESPACE                          \
8631a2
+    {                                                   \
8631a2
+      static rettype (*func) parameters =               \
8631a2
+        reinterpret_cast<rettype(*)parameters>(::func); \
8631a2
+    }                                                   \
8631a2
+    _GL_EXTERN_C int _gl_cxxalias_dummy
8631a2
+#else
8631a2
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
8631a2
+    _GL_EXTERN_C int _gl_cxxalias_dummy
8631a2
+#endif
8631a2
+
8631a2
+/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
8631a2
+   is like  _GL_CXXALIAS_SYS (func, rettype, parameters);
8631a2
+   except that the C function is picked among a set of overloaded functions,
8631a2
+   namely the one with rettype2 and parameters2.  Two consecutive casts
8631a2
+   are used to silence the "cannot find a match" and "invalid conversion"
8631a2
+   errors that would otherwise occur.  */
8631a2
+#if defined __cplusplus && defined GNULIB_NAMESPACE
8631a2
+  /* The outer cast must be a reinterpret_cast.
8631a2
+     The inner cast: When the function is defined as a set of overloaded
8631a2
+     functions, it works as a static_cast<>, choosing the designated variant.
8631a2
+     When the function is defined as a single variant, it works as a
8631a2
+     reinterpret_cast<>. The parenthesized cast syntax works both ways.  */
8631a2
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
8631a2
+    namespace GNULIB_NAMESPACE                                                \
8631a2
+    {                                                                         \
8631a2
+      static rettype (*func) parameters =                                     \
8631a2
+        reinterpret_cast<rettype(*)parameters>(                               \
8631a2
+          (rettype2(*)parameters2)(::func));                                  \
8631a2
+    }                                                                         \
8631a2
+    _GL_EXTERN_C int _gl_cxxalias_dummy
8631a2
+#else
8631a2
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
8631a2
+    _GL_EXTERN_C int _gl_cxxalias_dummy
8631a2
+#endif
8631a2
+
8631a2
+/* _GL_CXXALIASWARN (func);
8631a2
+   causes a warning to be emitted when ::func is used but not when
8631a2
+   GNULIB_NAMESPACE::func is used.  func must be defined without overloaded
8631a2
+   variants.  */
8631a2
+#if defined __cplusplus && defined GNULIB_NAMESPACE
8631a2
+# define _GL_CXXALIASWARN(func) \
8631a2
+   _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
8631a2
+# define _GL_CXXALIASWARN_1(func,namespace) \
8631a2
+   _GL_CXXALIASWARN_2 (func, namespace)
8631a2
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
8631a2
+   we enable the warning only when not optimizing.  */
8631a2
+# if !__OPTIMIZE__
8631a2
+#  define _GL_CXXALIASWARN_2(func,namespace) \
8631a2
+    _GL_WARN_ON_USE (func, \
8631a2
+                     "The symbol ::" #func " refers to the system function. " \
8631a2
+                     "Use " #namespace "::" #func " instead.")
8631a2
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
8631a2
+#  define _GL_CXXALIASWARN_2(func,namespace) \
8631a2
+     extern __typeof__ (func) func
8631a2
+# else
8631a2
+#  define _GL_CXXALIASWARN_2(func,namespace) \
8631a2
+     _GL_EXTERN_C int _gl_cxxalias_dummy
8631a2
+# endif
8631a2
+#else
8631a2
+# define _GL_CXXALIASWARN(func) \
8631a2
+    _GL_EXTERN_C int _gl_cxxalias_dummy
8631a2
+#endif
8631a2
+
8631a2
+/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
8631a2
+   causes a warning to be emitted when the given overloaded variant of ::func
8631a2
+   is used but not when GNULIB_NAMESPACE::func is used.  */
8631a2
+#if defined __cplusplus && defined GNULIB_NAMESPACE
8631a2
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
8631a2
+   _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
8631a2
+                        GNULIB_NAMESPACE)
8631a2
+# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
8631a2
+   _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
8631a2
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
8631a2
+   we enable the warning only when not optimizing.  */
8631a2
+# if !__OPTIMIZE__
8631a2
+#  define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
8631a2
+    _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
8631a2
+                         "The symbol ::" #func " refers to the system function. " \
8631a2
+                         "Use " #namespace "::" #func " instead.")
8631a2
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
8631a2
+#  define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
8631a2
+     extern __typeof__ (func) func
8631a2
+# else
8631a2
+#  define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
8631a2
+     _GL_EXTERN_C int _gl_cxxalias_dummy
8631a2
+# endif
8631a2
+#else
8631a2
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
8631a2
+    _GL_EXTERN_C int _gl_cxxalias_dummy
8631a2
+#endif
8631a2
+
8631a2
+#endif /* _GL_CXXDEFS_H */
8631a2
+
8631a2
+/* The definition of _GL_ARG_NONNULL is copied here.  */
8631a2
+/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
8631a2
+   that the values passed as arguments n, ..., m must be non-NULL pointers.
8631a2
+   n = 1 stands for the first argument, n = 2 for the second argument etc.  */
8631a2
+#ifndef _GL_ARG_NONNULL
8631a2
+# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
8631a2
+#  define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
8631a2
+# else
8631a2
+#  define _GL_ARG_NONNULL(params)
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+/* The definition of _GL_WARN_ON_USE is copied here.  */
8631a2
+#ifndef _GL_WARN_ON_USE
8631a2
+
8631a2
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
8631a2
+/* A compiler attribute is available in gcc versions 4.3.0 and later.  */
8631a2
+#  define _GL_WARN_ON_USE(function, message) \
8631a2
+extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
8631a2
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
8631a2
+/* Verify the existence of the function.  */
8631a2
+#  define _GL_WARN_ON_USE(function, message) \
8631a2
+extern __typeof__ (function) function
8631a2
+# else /* Unsupported.  */
8631a2
+#  define _GL_WARN_ON_USE(function, message) \
8631a2
+_GL_WARN_EXTERN_C int _gl_warn_on_use
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
8631a2
+   is like _GL_WARN_ON_USE (function, "string"), except that the function is
8631a2
+   declared with the given prototype, consisting of return type, parameters,
8631a2
+   and attributes.
8631a2
+   This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
8631a2
+   not work in this case.  */
8631a2
+#ifndef _GL_WARN_ON_USE_CXX
8631a2
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
8631a2
+#  define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
8631a2
+extern rettype function parameters_and_attributes \
8631a2
+     __attribute__ ((__warning__ (msg)))
8631a2
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
8631a2
+/* Verify the existence of the function.  */
8631a2
+#  define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
8631a2
+extern rettype function parameters_and_attributes
8631a2
+# else /* Unsupported.  */
8631a2
+#  define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
8631a2
+_GL_WARN_EXTERN_C int _gl_warn_on_use
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+/* _GL_WARN_EXTERN_C declaration;
8631a2
+   performs the declaration with C linkage.  */
8631a2
+#ifndef _GL_WARN_EXTERN_C
8631a2
+# if defined __cplusplus
8631a2
+#  define _GL_WARN_EXTERN_C extern "C"
8631a2
+# else
8631a2
+#  define _GL_WARN_EXTERN_C extern
8631a2
+# endif
8631a2
+#endif
8631a2
+
8631a2
+/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
8631a2
+   Or they define it with the wrong member names or define it in <sys/time.h>
8631a2
+   (e.g., FreeBSD circa 1997).  Stock Mingw prior to 3.0 does not define it,
8631a2
+   but the pthreads-win32 library defines it in <pthread.h>.  */
8631a2
+# if ! 1
8631a2
+#  if 0
8631a2
+#   include <sys/time.h>
8631a2
+#  elif 0
8631a2
+#   include <pthread.h>
8631a2
+#  else
8631a2
+
8631a2
+#   ifdef __cplusplus
8631a2
+extern "C" {
8631a2
+#   endif
8631a2
+
8631a2
+#   if !GNULIB_defined_struct_timespec
8631a2
+#    undef timespec
8631a2
+#    define timespec rpl_timespec
8631a2
+struct timespec
8631a2
+{
8631a2
+  time_t tv_sec;
8631a2
+  long int tv_nsec;
8631a2
+};
8631a2
+#    define GNULIB_defined_struct_timespec 1
8631a2
+#   endif
8631a2
+
8631a2
+#   ifdef __cplusplus
8631a2
+}
8631a2
+#   endif
8631a2
+
8631a2
+#  endif
8631a2
+# endif
8631a2
+
8631a2
+# if !GNULIB_defined_struct_time_t_must_be_integral
8631a2
+/* Per http://austingroupbugs.net/view.php?id=327, POSIX requires
8631a2
+   time_t to be an integer type, even though C99 permits floating
8631a2
+   point.  We don't know of any implementation that uses floating
8631a2
+   point, and it is much easier to write code that doesn't have to
8631a2
+   worry about that corner case, so we force the issue.  */
8631a2
+struct __time_t_must_be_integral {
8631a2
+  unsigned int __floating_time_t_unsupported : (time_t) 1;
8631a2
+};
8631a2
+#  define GNULIB_defined_struct_time_t_must_be_integral 1
8631a2
+# endif
8631a2
+
8631a2
+/* Sleep for at least RQTP seconds unless interrupted,  If interrupted,
8631a2
+   return -1 and store the remaining time into RMTP.  See
8631a2
+   <http://www.opengroup.org/susv3xsh/nanosleep.html>.  */
8631a2
+# if 0
8631a2
+#  if GNULIB_PORTCHECK
8631a2
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#    define nanosleep rpl_nanosleep
8631a2
+#   endif
8631a2
+_GL_FUNCDECL_RPL (nanosleep, int,
8631a2
+                  (struct timespec const *__rqtp, struct timespec *__rmtp)
8631a2
+                  _GL_ARG_NONNULL ((1)));
8631a2
+_GL_CXXALIAS_RPL (nanosleep, int,
8631a2
+                  (struct timespec const *__rqtp, struct timespec *__rmtp));
8631a2
+#  else
8631a2
+#   if ! 1
8631a2
+_GL_FUNCDECL_SYS (nanosleep, int,
8631a2
+                  (struct timespec const *__rqtp, struct timespec *__rmtp)
8631a2
+                  _GL_ARG_NONNULL ((1)));
8631a2
+#   endif
8631a2
+_GL_CXXALIAS_SYS (nanosleep, int,
8631a2
+                  (struct timespec const *__rqtp, struct timespec *__rmtp));
8631a2
+#  endif
8631a2
+_GL_CXXALIASWARN (nanosleep);
8631a2
+# endif
8631a2
+
8631a2
+/* Return the 'time_t' representation of TP and normalize TP.  */
8631a2
+# if 0
8631a2
+#  if GNULIB_PORTCHECK
8631a2
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#    define mktime rpl_mktime
8631a2
+#   endif
8631a2
+_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
8631a2
+_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
8631a2
+#  else
8631a2
+_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
8631a2
+#  endif
8631a2
+_GL_CXXALIASWARN (mktime);
8631a2
+# endif
8631a2
+
8631a2
+/* Convert TIMER to RESULT, assuming local time and UTC respectively.  See
8631a2
+   <http://www.opengroup.org/susv3xsh/localtime_r.html> and
8631a2
+   <http://www.opengroup.org/susv3xsh/gmtime_r.html>.  */
8631a2
+# if 0
8631a2
+#  if GNULIB_PORTCHECK
8631a2
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#    undef localtime_r
8631a2
+#    define localtime_r rpl_localtime_r
8631a2
+#   endif
8631a2
+_GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
8631a2
+                                             struct tm *restrict __result)
8631a2
+                                            _GL_ARG_NONNULL ((1, 2)));
8631a2
+_GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
8631a2
+                                             struct tm *restrict __result));
8631a2
+#  else
8631a2
+#   if ! 1
8631a2
+_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
8631a2
+                                             struct tm *restrict __result)
8631a2
+                                            _GL_ARG_NONNULL ((1, 2)));
8631a2
+#   endif
8631a2
+_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
8631a2
+                                             struct tm *restrict __result));
8631a2
+#  endif
8631a2
+#  if 1
8631a2
+_GL_CXXALIASWARN (localtime_r);
8631a2
+#  endif
8631a2
+#  if GNULIB_PORTCHECK
8631a2
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#    undef gmtime_r
8631a2
+#    define gmtime_r rpl_gmtime_r
8631a2
+#   endif
8631a2
+_GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
8631a2
+                                          struct tm *restrict __result)
8631a2
+                                         _GL_ARG_NONNULL ((1, 2)));
8631a2
+_GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
8631a2
+                                          struct tm *restrict __result));
8631a2
+#  else
8631a2
+#   if ! 1
8631a2
+_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
8631a2
+                                          struct tm *restrict __result)
8631a2
+                                         _GL_ARG_NONNULL ((1, 2)));
8631a2
+#   endif
8631a2
+_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
8631a2
+                                          struct tm *restrict __result));
8631a2
+#  endif
8631a2
+#  if 1
8631a2
+_GL_CXXALIASWARN (gmtime_r);
8631a2
+#  endif
8631a2
+# endif
8631a2
+
8631a2
+/* Convert TIMER to RESULT, assuming local time and UTC respectively.  See
8631a2
+   <http://www.opengroup.org/susv3xsh/localtime.html> and
8631a2
+   <http://www.opengroup.org/susv3xsh/gmtime.html>.  */
8631a2
+# if 1
8631a2
+#  if 0
8631a2
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#    undef localtime
8631a2
+#    define localtime rpl_localtime
8631a2
+#   endif
8631a2
+_GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer)
8631a2
+		                          _GL_ARG_NONNULL ((1)));
8631a2
+_GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer));
8631a2
+#  else
8631a2
+_GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer));
8631a2
+#  endif
8631a2
+_GL_CXXALIASWARN (localtime);
8631a2
+# endif
8631a2
+
8631a2
+# if 1
8631a2
+#  if 0
8631a2
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#    undef gmtime
8631a2
+#    define gmtime rpl_gmtime
8631a2
+#   endif
8631a2
+_GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer)
8631a2
+                                       _GL_ARG_NONNULL ((1)));
8631a2
+_GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer));
8631a2
+#  else
8631a2
+_GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer));
8631a2
+#  endif
8631a2
+_GL_CXXALIASWARN (gmtime);
8631a2
+# endif
8631a2
+
8631a2
+/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
8631a2
+   the resulting broken-down time into TM.  See
8631a2
+   <http://www.opengroup.org/susv3xsh/strptime.html>.  */
8631a2
+# if 0
8631a2
+#  if ! 1
8631a2
+_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
8631a2
+                                     char const *restrict __format,
8631a2
+                                     struct tm *restrict __tm)
8631a2
+                                    _GL_ARG_NONNULL ((1, 2, 3)));
8631a2
+#  endif
8631a2
+_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
8631a2
+                                     char const *restrict __format,
8631a2
+                                     struct tm *restrict __tm));
8631a2
+_GL_CXXALIASWARN (strptime);
8631a2
+# endif
8631a2
+
8631a2
+/* Convert TM to a time_t value, assuming UTC.  */
8631a2
+# if 0
8631a2
+#  if GNULIB_PORTCHECK
8631a2
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#    undef timegm
8631a2
+#    define timegm rpl_timegm
8631a2
+#   endif
8631a2
+_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
8631a2
+_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
8631a2
+#  else
8631a2
+#   if ! 1
8631a2
+_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
8631a2
+#   endif
8631a2
+_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
8631a2
+#  endif
8631a2
+_GL_CXXALIASWARN (timegm);
8631a2
+# endif
8631a2
+
8631a2
+/* Encourage applications to avoid unsafe functions that can overrun
8631a2
+   buffers when given outlandish struct tm values.  Portable
8631a2
+   applications should use strftime (or even sprintf) instead.  */
8631a2
+# if defined GNULIB_POSIXCHECK
8631a2
+#  undef asctime
8631a2
+_GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
8631a2
+                 "better use strftime (or even sprintf) instead");
8631a2
+# endif
8631a2
+# if defined GNULIB_POSIXCHECK
8631a2
+#  undef asctime_r
8631a2
+_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - "
8631a2
+                 "better use strftime (or even sprintf) instead");
8631a2
+# endif
8631a2
+# if defined GNULIB_POSIXCHECK
8631a2
+#  undef ctime
8631a2
+_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - "
8631a2
+                 "better use strftime (or even sprintf) instead");
8631a2
+# endif
8631a2
+# if defined GNULIB_POSIXCHECK
8631a2
+#  undef ctime_r
8631a2
+_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - "
8631a2
+                 "better use strftime (or even sprintf) instead");
8631a2
+# endif
8631a2
+
8631a2
+#endif
8631a2
diff --git a/grub-core/gnulib/time.in.h b/grub-core/gnulib/time.in.h
8631a2
new file mode 100644
09e3cc
index 000000000..81abdf46e
8631a2
--- /dev/null
8631a2
+++ b/grub-core/gnulib/time.in.h
8631a2
@@ -0,0 +1,274 @@
8631a2
+/* A more-standard <time.h>.
8631a2
+
8631a2
+   Copyright (C) 2007-2014 Free Software Foundation, Inc.
8631a2
+
8631a2
+   This program is free software; you can redistribute it and/or modify
8631a2
+   it under the terms of the GNU General Public License as published by
8631a2
+   the Free Software Foundation; either version 3, or (at your option)
8631a2
+   any later version.
8631a2
+
8631a2
+   This program is distributed in the hope that it will be useful,
8631a2
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
8631a2
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8631a2
+   GNU General Public License for more details.
8631a2
+
8631a2
+   You should have received a copy of the GNU General Public License
8631a2
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
8631a2
+
8631a2
+#if __GNUC__ >= 3
8631a2
+@PRAGMA_SYSTEM_HEADER@
8631a2
+#endif
8631a2
+@PRAGMA_COLUMNS@
8631a2
+
8631a2
+/* Don't get in the way of glibc when it includes time.h merely to
8631a2
+   declare a few standard symbols, rather than to declare all the
8631a2
+   symbols.  Also, Solaris 8 <time.h> eventually includes itself
8631a2
+   recursively; if that is happening, just include the system <time.h>
8631a2
+   without adding our own declarations.  */
8631a2
+#if (defined __need_time_t || defined __need_clock_t \
8631a2
+     || defined __need_timespec \
8631a2
+     || defined _@GUARD_PREFIX@_TIME_H)
8631a2
+
8631a2
+# @INCLUDE_NEXT@ @NEXT_TIME_H@
8631a2
+
8631a2
+#else
8631a2
+
8631a2
+# define _@GUARD_PREFIX@_TIME_H
8631a2
+
8631a2
+# @INCLUDE_NEXT@ @NEXT_TIME_H@
8631a2
+
8631a2
+/* NetBSD 5.0 mis-defines NULL.  */
8631a2
+# include <stddef.h>
8631a2
+
8631a2
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
8631a2
+
8631a2
+/* The definition of _GL_ARG_NONNULL is copied here.  */
8631a2
+
8631a2
+/* The definition of _GL_WARN_ON_USE is copied here.  */
8631a2
+
8631a2
+/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
8631a2
+   Or they define it with the wrong member names or define it in <sys/time.h>
8631a2
+   (e.g., FreeBSD circa 1997).  Stock Mingw prior to 3.0 does not define it,
8631a2
+   but the pthreads-win32 library defines it in <pthread.h>.  */
8631a2
+# if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
8631a2
+#  if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
8631a2
+#   include <sys/time.h>
8631a2
+#  elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@
8631a2
+#   include <pthread.h>
8631a2
+#  else
8631a2
+
8631a2
+#   ifdef __cplusplus
8631a2
+extern "C" {
8631a2
+#   endif
8631a2
+
8631a2
+#   if !GNULIB_defined_struct_timespec
8631a2
+#    undef timespec
8631a2
+#    define timespec rpl_timespec
8631a2
+struct timespec
8631a2
+{
8631a2
+  time_t tv_sec;
8631a2
+  long int tv_nsec;
8631a2
+};
8631a2
+#    define GNULIB_defined_struct_timespec 1
8631a2
+#   endif
8631a2
+
8631a2
+#   ifdef __cplusplus
8631a2
+}
8631a2
+#   endif
8631a2
+
8631a2
+#  endif
8631a2
+# endif
8631a2
+
8631a2
+# if !GNULIB_defined_struct_time_t_must_be_integral
8631a2
+/* Per http://austingroupbugs.net/view.php?id=327, POSIX requires
8631a2
+   time_t to be an integer type, even though C99 permits floating
8631a2
+   point.  We don't know of any implementation that uses floating
8631a2
+   point, and it is much easier to write code that doesn't have to
8631a2
+   worry about that corner case, so we force the issue.  */
8631a2
+struct __time_t_must_be_integral {
8631a2
+  unsigned int __floating_time_t_unsupported : (time_t) 1;
8631a2
+};
8631a2
+#  define GNULIB_defined_struct_time_t_must_be_integral 1
8631a2
+# endif
8631a2
+
8631a2
+/* Sleep for at least RQTP seconds unless interrupted,  If interrupted,
8631a2
+   return -1 and store the remaining time into RMTP.  See
8631a2
+   <http://www.opengroup.org/susv3xsh/nanosleep.html>.  */
8631a2
+# if @GNULIB_NANOSLEEP@
8631a2
+#  if @REPLACE_NANOSLEEP@
8631a2
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#    define nanosleep rpl_nanosleep
8631a2
+#   endif
8631a2
+_GL_FUNCDECL_RPL (nanosleep, int,
8631a2
+                  (struct timespec const *__rqtp, struct timespec *__rmtp)
8631a2
+                  _GL_ARG_NONNULL ((1)));
8631a2
+_GL_CXXALIAS_RPL (nanosleep, int,
8631a2
+                  (struct timespec const *__rqtp, struct timespec *__rmtp));
8631a2
+#  else
8631a2
+#   if ! @HAVE_NANOSLEEP@
8631a2
+_GL_FUNCDECL_SYS (nanosleep, int,
8631a2
+                  (struct timespec const *__rqtp, struct timespec *__rmtp)
8631a2
+                  _GL_ARG_NONNULL ((1)));
8631a2
+#   endif
8631a2
+_GL_CXXALIAS_SYS (nanosleep, int,
8631a2
+                  (struct timespec const *__rqtp, struct timespec *__rmtp));
8631a2
+#  endif
8631a2
+_GL_CXXALIASWARN (nanosleep);
8631a2
+# endif
8631a2
+
8631a2
+/* Return the 'time_t' representation of TP and normalize TP.  */
8631a2
+# if @GNULIB_MKTIME@
8631a2
+#  if @REPLACE_MKTIME@
8631a2
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#    define mktime rpl_mktime
8631a2
+#   endif
8631a2
+_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
8631a2
+_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
8631a2
+#  else
8631a2
+_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
8631a2
+#  endif
8631a2
+_GL_CXXALIASWARN (mktime);
8631a2
+# endif
8631a2
+
8631a2
+/* Convert TIMER to RESULT, assuming local time and UTC respectively.  See
8631a2
+   <http://www.opengroup.org/susv3xsh/localtime_r.html> and
8631a2
+   <http://www.opengroup.org/susv3xsh/gmtime_r.html>.  */
8631a2
+# if @GNULIB_TIME_R@
8631a2
+#  if @REPLACE_LOCALTIME_R@
8631a2
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#    undef localtime_r
8631a2
+#    define localtime_r rpl_localtime_r
8631a2
+#   endif
8631a2
+_GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
8631a2
+                                             struct tm *restrict __result)
8631a2
+                                            _GL_ARG_NONNULL ((1, 2)));
8631a2
+_GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
8631a2
+                                             struct tm *restrict __result));
8631a2
+#  else
8631a2
+#   if ! @HAVE_DECL_LOCALTIME_R@
8631a2
+_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
8631a2
+                                             struct tm *restrict __result)
8631a2
+                                            _GL_ARG_NONNULL ((1, 2)));
8631a2
+#   endif
8631a2
+_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
8631a2
+                                             struct tm *restrict __result));
8631a2
+#  endif
8631a2
+#  if @HAVE_DECL_LOCALTIME_R@
8631a2
+_GL_CXXALIASWARN (localtime_r);
8631a2
+#  endif
8631a2
+#  if @REPLACE_LOCALTIME_R@
8631a2
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#    undef gmtime_r
8631a2
+#    define gmtime_r rpl_gmtime_r
8631a2
+#   endif
8631a2
+_GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
8631a2
+                                          struct tm *restrict __result)
8631a2
+                                         _GL_ARG_NONNULL ((1, 2)));
8631a2
+_GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
8631a2
+                                          struct tm *restrict __result));
8631a2
+#  else
8631a2
+#   if ! @HAVE_DECL_LOCALTIME_R@
8631a2
+_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
8631a2
+                                          struct tm *restrict __result)
8631a2
+                                         _GL_ARG_NONNULL ((1, 2)));
8631a2
+#   endif
8631a2
+_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
8631a2
+                                          struct tm *restrict __result));
8631a2
+#  endif
8631a2
+#  if @HAVE_DECL_LOCALTIME_R@
8631a2
+_GL_CXXALIASWARN (gmtime_r);
8631a2
+#  endif
8631a2
+# endif
8631a2
+
8631a2
+/* Convert TIMER to RESULT, assuming local time and UTC respectively.  See
8631a2
+   <http://www.opengroup.org/susv3xsh/localtime.html> and
8631a2
+   <http://www.opengroup.org/susv3xsh/gmtime.html>.  */
8631a2
+# if @GNULIB_GETTIMEOFDAY@
8631a2
+#  if @REPLACE_LOCALTIME@
8631a2
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#    undef localtime
8631a2
+#    define localtime rpl_localtime
8631a2
+#   endif
8631a2
+_GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer)
8631a2
+		                          _GL_ARG_NONNULL ((1)));
8631a2
+_GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer));
8631a2
+#  else
8631a2
+_GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer));
8631a2
+#  endif
8631a2
+_GL_CXXALIASWARN (localtime);
8631a2
+# endif
8631a2
+
8631a2
+# if @GNULIB_GETTIMEOFDAY@
8631a2
+#  if @REPLACE_GMTIME@
8631a2
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#    undef gmtime
8631a2
+#    define gmtime rpl_gmtime
8631a2
+#   endif
8631a2
+_GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer)
8631a2
+                                       _GL_ARG_NONNULL ((1)));
8631a2
+_GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer));
8631a2
+#  else
8631a2
+_GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer));
8631a2
+#  endif
8631a2
+_GL_CXXALIASWARN (gmtime);
8631a2
+# endif
8631a2
+
8631a2
+/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
8631a2
+   the resulting broken-down time into TM.  See
8631a2
+   <http://www.opengroup.org/susv3xsh/strptime.html>.  */
8631a2
+# if @GNULIB_STRPTIME@
8631a2
+#  if ! @HAVE_STRPTIME@
8631a2
+_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
8631a2
+                                     char const *restrict __format,
8631a2
+                                     struct tm *restrict __tm)
8631a2
+                                    _GL_ARG_NONNULL ((1, 2, 3)));
8631a2
+#  endif
8631a2
+_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
8631a2
+                                     char const *restrict __format,
8631a2
+                                     struct tm *restrict __tm));
8631a2
+_GL_CXXALIASWARN (strptime);
8631a2
+# endif
8631a2
+
8631a2
+/* Convert TM to a time_t value, assuming UTC.  */
8631a2
+# if @GNULIB_TIMEGM@
8631a2
+#  if @REPLACE_TIMEGM@
8631a2
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
8631a2
+#    undef timegm
8631a2
+#    define timegm rpl_timegm
8631a2
+#   endif
8631a2
+_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
8631a2
+_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
8631a2
+#  else
8631a2
+#   if ! @HAVE_TIMEGM@
8631a2
+_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
8631a2
+#   endif
8631a2
+_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
8631a2
+#  endif
8631a2
+_GL_CXXALIASWARN (timegm);
8631a2
+# endif
8631a2
+
8631a2
+/* Encourage applications to avoid unsafe functions that can overrun
8631a2
+   buffers when given outlandish struct tm values.  Portable
8631a2
+   applications should use strftime (or even sprintf) instead.  */
8631a2
+# if defined GNULIB_POSIXCHECK
8631a2
+#  undef asctime
8631a2
+_GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
8631a2
+                 "better use strftime (or even sprintf) instead");
8631a2
+# endif
8631a2
+# if defined GNULIB_POSIXCHECK
8631a2
+#  undef asctime_r
8631a2
+_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - "
8631a2
+                 "better use strftime (or even sprintf) instead");
8631a2
+# endif
8631a2
+# if defined GNULIB_POSIXCHECK
8631a2
+#  undef ctime
8631a2
+_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - "
8631a2
+                 "better use strftime (or even sprintf) instead");
8631a2
+# endif
8631a2
+# if defined GNULIB_POSIXCHECK
8631a2
+#  undef ctime_r
8631a2
+_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - "
8631a2
+                 "better use strftime (or even sprintf) instead");
8631a2
+# endif
8631a2
+
8631a2
+#endif
8631a2
diff --git a/include/grub/osdep/hostfile_aros.h b/include/grub/osdep/hostfile_aros.h
09e3cc
index a059c0fa4..161fbb7bd 100644
8631a2
--- a/include/grub/osdep/hostfile_aros.h
8631a2
+++ b/include/grub/osdep/hostfile_aros.h
8631a2
@@ -68,6 +68,12 @@ grub_util_rename (const char *from, const char *to)
8631a2
   return rename (from, to);
8631a2
 }
8631a2
 
8631a2
+static inline ssize_t
8631a2
+grub_util_readlink (const char *name, char *buf, size_t bufsize)
8631a2
+{
8631a2
+  return readlink(name, buf, bufsize);
8631a2
+}
8631a2
+
8631a2
 #define grub_util_mkdir(a) mkdir ((a), 0755)
8631a2
 
8631a2
 struct grub_util_fd
8631a2
diff --git a/include/grub/osdep/hostfile_unix.h b/include/grub/osdep/hostfile_unix.h
09e3cc
index 9ffe46fa3..17cd3aa8b 100644
8631a2
--- a/include/grub/osdep/hostfile_unix.h
8631a2
+++ b/include/grub/osdep/hostfile_unix.h
8631a2
@@ -71,6 +71,12 @@ grub_util_rename (const char *from, const char *to)
8631a2
   return rename (from, to);
8631a2
 }
8631a2
 
8631a2
+static inline ssize_t
8631a2
+grub_util_readlink (const char *name, char *buf, size_t bufsize)
8631a2
+{
8631a2
+  return readlink(name, buf, bufsize);
8631a2
+}
8631a2
+
8631a2
 #define grub_util_mkdir(a) mkdir ((a), 0755)
8631a2
 
8631a2
 #if defined (__NetBSD__)
8631a2
diff --git a/include/grub/osdep/hostfile_windows.h b/include/grub/osdep/hostfile_windows.h
09e3cc
index bf6451b6d..8c92d0591 100644
8631a2
--- a/include/grub/osdep/hostfile_windows.h
8631a2
+++ b/include/grub/osdep/hostfile_windows.h
8631a2
@@ -41,6 +41,8 @@ typedef struct grub_util_fd_dir *grub_util_fd_dir_t;
8631a2
 
8631a2
 int
8631a2
 grub_util_rename (const char *from, const char *to);
8631a2
+ssize_t
8631a2
+grub_util_readlink (const char *name, char *buf, size_t bufsize);
8631a2
 int
8631a2
 grub_util_unlink (const char *name);
8631a2
 void
8631a2
diff --git a/grub-core/gnulib/Makefile.am b/grub-core/gnulib/Makefile.am
09e3cc
index 3444397fe..b7c5e60e1 100644
8631a2
--- a/grub-core/gnulib/Makefile.am
8631a2
+++ b/grub-core/gnulib/Makefile.am
8631a2
@@ -21,7 +21,7 @@
8631a2
 # the same distribution terms as the rest of that program.
8631a2
 #
8631a2
 # Generated by gnulib-tool.
8631a2
-# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname regex
8631a2
+# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname readlink regex
8631a2
 
8631a2
 AUTOMAKE_OPTIONS = 1.5 gnits subdir-objects
8631a2
 
8631a2
@@ -326,6 +326,15 @@ libgnu_a_SOURCES += gettext.h
8631a2
 
8631a2
 ## end   gnulib module gettext-h
8631a2
 
8631a2
+## begin gnulib module gettimeofday
8631a2
+
8631a2
+
8631a2
+EXTRA_DIST += gettimeofday.c
8631a2
+
8631a2
+EXTRA_libgnu_a_SOURCES += gettimeofday.c
8631a2
+
8631a2
+## end   gnulib module gettimeofday
8631a2
+
8631a2
 ## begin gnulib module havelib
8631a2
 
8631a2
 
8631a2
@@ -596,6 +605,13 @@ EXTRA_libgnu_a_SOURCES += nl_langinfo.c
8631a2
 
8631a2
 ## end   gnulib module nl_langinfo
8631a2
 
8631a2
+## begin gnulib module pathmax
8631a2
+
8631a2
+
8631a2
+EXTRA_DIST += pathmax.h
8631a2
+
8631a2
+## end   gnulib module pathmax
8631a2
+
8631a2
 ## begin gnulib module progname
8631a2
 
8631a2
 libgnu_a_SOURCES += progname.h progname.c
8631a2
@@ -611,6 +627,15 @@ EXTRA_libgnu_a_SOURCES += rawmemchr.c
8631a2
 
8631a2
 ## end   gnulib module rawmemchr
8631a2
 
8631a2
+## begin gnulib module readlink
8631a2
+
8631a2
+
8631a2
+EXTRA_DIST += readlink.c
8631a2
+
8631a2
+EXTRA_libgnu_a_SOURCES += readlink.c
8631a2
+
8631a2
+## end   gnulib module readlink
8631a2
+
8631a2
 ## begin gnulib module realloc-posix
8631a2
 
8631a2
 
8631a2
@@ -725,6 +750,15 @@ EXTRA_DIST += $(top_srcdir)/build-aux/snippet/warn-on-use.h
8631a2
 
8631a2
 ## end   gnulib module snippet/warn-on-use
8631a2
 
8631a2
+## begin gnulib module stat
8631a2
+
8631a2
+
8631a2
+EXTRA_DIST += stat.c
8631a2
+
8631a2
+EXTRA_libgnu_a_SOURCES += stat.c
8631a2
+
8631a2
+## end   gnulib module stat
8631a2
+
8631a2
 ## begin gnulib module stdalign
8631a2
 
8631a2
 BUILT_SOURCES += $(STDALIGN_H)
8631a2
@@ -1280,6 +1314,102 @@ libgnu_a_SOURCES += strnlen1.h strnlen1.c
8631a2
 
8631a2
 ## end   gnulib module strnlen1
8631a2
 
8631a2
+## begin gnulib module sys_stat
8631a2
+
8631a2
+BUILT_SOURCES += sys/stat.h
8631a2
+
8631a2
+# We need the following in order to create <sys/stat.h> when the system
8631a2
+# has one that is incomplete.
8631a2
+sys/stat.h: sys_stat.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
8631a2
+	$(AM_V_at)$(MKDIR_P) sys
8631a2
+	$(AM_V_GEN)rm -f $@-t $@ && \
8631a2
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
8631a2
+	  sed -e 's|@''GUARD_PREFIX''@|GL|g' \
8631a2
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
8631a2
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
8631a2
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
8631a2
+	      -e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \
8631a2
+	      -e 's|@''WINDOWS_64_BIT_ST_SIZE''@|$(WINDOWS_64_BIT_ST_SIZE)|g' \
8631a2
+	      -e 's/@''GNULIB_FCHMODAT''@/$(GNULIB_FCHMODAT)/g' \
8631a2
+	      -e 's/@''GNULIB_FSTAT''@/$(GNULIB_FSTAT)/g' \
8631a2
+	      -e 's/@''GNULIB_FSTATAT''@/$(GNULIB_FSTATAT)/g' \
8631a2
+	      -e 's/@''GNULIB_FUTIMENS''@/$(GNULIB_FUTIMENS)/g' \
8631a2
+	      -e 's/@''GNULIB_LCHMOD''@/$(GNULIB_LCHMOD)/g' \
8631a2
+	      -e 's/@''GNULIB_LSTAT''@/$(GNULIB_LSTAT)/g' \
8631a2
+	      -e 's/@''GNULIB_MKDIRAT''@/$(GNULIB_MKDIRAT)/g' \
8631a2
+	      -e 's/@''GNULIB_MKFIFO''@/$(GNULIB_MKFIFO)/g' \
8631a2
+	      -e 's/@''GNULIB_MKFIFOAT''@/$(GNULIB_MKFIFOAT)/g' \
8631a2
+	      -e 's/@''GNULIB_MKNOD''@/$(GNULIB_MKNOD)/g' \
8631a2
+	      -e 's/@''GNULIB_MKNODAT''@/$(GNULIB_MKNODAT)/g' \
8631a2
+	      -e 's/@''GNULIB_STAT''@/$(GNULIB_STAT)/g' \
8631a2
+	      -e 's/@''GNULIB_UTIMENSAT''@/$(GNULIB_UTIMENSAT)/g' \
8631a2
+	      -e 's|@''HAVE_FCHMODAT''@|$(HAVE_FCHMODAT)|g' \
8631a2
+	      -e 's|@''HAVE_FSTATAT''@|$(HAVE_FSTATAT)|g' \
8631a2
+	      -e 's|@''HAVE_FUTIMENS''@|$(HAVE_FUTIMENS)|g' \
8631a2
+	      -e 's|@''HAVE_LCHMOD''@|$(HAVE_LCHMOD)|g' \
8631a2
+	      -e 's|@''HAVE_LSTAT''@|$(HAVE_LSTAT)|g' \
8631a2
+	      -e 's|@''HAVE_MKDIRAT''@|$(HAVE_MKDIRAT)|g' \
8631a2
+	      -e 's|@''HAVE_MKFIFO''@|$(HAVE_MKFIFO)|g' \
8631a2
+	      -e 's|@''HAVE_MKFIFOAT''@|$(HAVE_MKFIFOAT)|g' \
8631a2
+	      -e 's|@''HAVE_MKNOD''@|$(HAVE_MKNOD)|g' \
8631a2
+	      -e 's|@''HAVE_MKNODAT''@|$(HAVE_MKNODAT)|g' \
8631a2
+	      -e 's|@''HAVE_UTIMENSAT''@|$(HAVE_UTIMENSAT)|g' \
8631a2
+	      -e 's|@''REPLACE_FSTAT''@|$(REPLACE_FSTAT)|g' \
8631a2
+	      -e 's|@''REPLACE_FSTATAT''@|$(REPLACE_FSTATAT)|g' \
8631a2
+	      -e 's|@''REPLACE_FUTIMENS''@|$(REPLACE_FUTIMENS)|g' \
8631a2
+	      -e 's|@''REPLACE_LSTAT''@|$(REPLACE_LSTAT)|g' \
8631a2
+	      -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \
8631a2
+	      -e 's|@''REPLACE_MKFIFO''@|$(REPLACE_MKFIFO)|g' \
8631a2
+	      -e 's|@''REPLACE_MKNOD''@|$(REPLACE_MKNOD)|g' \
8631a2
+	      -e 's|@''REPLACE_STAT''@|$(REPLACE_STAT)|g' \
8631a2
+	      -e 's|@''REPLACE_UTIMENSAT''@|$(REPLACE_UTIMENSAT)|g' \
8631a2
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
8631a2
+	      -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
8631a2
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
8631a2
+	      < $(srcdir)/sys_stat.in.h; \
8631a2
+	} > $@-t && \
8631a2
+	mv $@-t $@
8631a2
+MOSTLYCLEANFILES += sys/stat.h sys/stat.h-t
8631a2
+MOSTLYCLEANDIRS += sys
8631a2
+
8631a2
+EXTRA_DIST += sys_stat.in.h
8631a2
+
8631a2
+## end   gnulib module sys_stat
8631a2
+
8631a2
+## begin gnulib module sys_time
8631a2
+
8631a2
+BUILT_SOURCES += sys/time.h
8631a2
+
8631a2
+# We need the following in order to create <sys/time.h> when the system
8631a2
+# doesn't have one that works with the given compiler.
8631a2
+sys/time.h: sys_time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
8631a2
+	$(AM_V_at)$(MKDIR_P) sys
8631a2
+	$(AM_V_GEN)rm -f $@-t $@ && \
8631a2
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
8631a2
+	  sed -e 's|@''GUARD_PREFIX''@|GL|g' \
8631a2
+	      -e 's/@''HAVE_SYS_TIME_H''@/$(HAVE_SYS_TIME_H)/g' \
8631a2
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
8631a2
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
8631a2
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
8631a2
+	      -e 's|@''NEXT_SYS_TIME_H''@|$(NEXT_SYS_TIME_H)|g' \
8631a2
+	      -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \
8631a2
+	      -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
8631a2
+	      -e 's/@''HAVE_GETTIMEOFDAY''@/$(HAVE_GETTIMEOFDAY)/g' \
8631a2
+	      -e 's/@''HAVE_STRUCT_TIMEVAL''@/$(HAVE_STRUCT_TIMEVAL)/g' \
8631a2
+	      -e 's/@''REPLACE_GETTIMEOFDAY''@/$(REPLACE_GETTIMEOFDAY)/g' \
8631a2
+	      -e 's/@''REPLACE_STRUCT_TIMEVAL''@/$(REPLACE_STRUCT_TIMEVAL)/g' \
8631a2
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
8631a2
+	      -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
8631a2
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
8631a2
+	      < $(srcdir)/sys_time.in.h; \
8631a2
+	} > $@-t && \
8631a2
+	mv $@-t $@
8631a2
+MOSTLYCLEANFILES += sys/time.h sys/time.h-t
8631a2
+
8631a2
+EXTRA_DIST += sys_time.in.h
8631a2
+
8631a2
+## end   gnulib module sys_time
8631a2
+
8631a2
 ## begin gnulib module sys_types
8631a2
 
8631a2
 BUILT_SOURCES += sys/types.h
8631a2
@@ -1334,6 +1464,51 @@ EXTRA_DIST += sysexits.in.h
8631a2
 
8631a2
 ## end   gnulib module sysexits
8631a2
 
8631a2
+## begin gnulib module time
8631a2
+
8631a2
+BUILT_SOURCES += time.h
8631a2
+
8631a2
+# We need the following in order to create <time.h> when the system
8631a2
+# doesn't have one that works with the given compiler.
8631a2
+time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
8631a2
+	$(AM_V_GEN)rm -f $@-t $@ && \
8631a2
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
8631a2
+	  sed -e 's|@''GUARD_PREFIX''@|GL|g' \
8631a2
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
8631a2
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
8631a2
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
8631a2
+	      -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \
8631a2
+	      -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \
8631a2
+	      -e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \
8631a2
+	      -e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \
8631a2
+	      -e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \
8631a2
+	      -e 's/@''GNULIB_TIMEGM''@/$(GNULIB_TIMEGM)/g' \
8631a2
+	      -e 's/@''GNULIB_TIME_R''@/$(GNULIB_TIME_R)/g' \
8631a2
+	      -e 's|@''HAVE_DECL_LOCALTIME_R''@|$(HAVE_DECL_LOCALTIME_R)|g' \
8631a2
+	      -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \
8631a2
+	      -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \
8631a2
+	      -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \
8631a2
+	      -e 's|@''REPLACE_GMTIME''@|$(REPLACE_GMTIME)|g' \
8631a2
+	      -e 's|@''REPLACE_LOCALTIME''@|$(REPLACE_LOCALTIME)|g' \
8631a2
+	      -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \
8631a2
+	      -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \
8631a2
+	      -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \
8631a2
+	      -e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \
8631a2
+	      -e 's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g' \
8631a2
+	      -e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \
8631a2
+	      -e 's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \
8631a2
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
8631a2
+	      -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
8631a2
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
8631a2
+	      < $(srcdir)/time.in.h; \
8631a2
+	} > $@-t && \
8631a2
+	mv $@-t $@
8631a2
+MOSTLYCLEANFILES += time.h time.h-t
8631a2
+
8631a2
+EXTRA_DIST += time.in.h
8631a2
+
8631a2
+## end   gnulib module time
8631a2
+
8631a2
 ## begin gnulib module unistd
8631a2
 
8631a2
 BUILT_SOURCES += unistd.h
8631a2
diff --git a/m4/gettimeofday.m4 b/m4/gettimeofday.m4
8631a2
new file mode 100644
09e3cc
index 000000000..1c2d66ee2
8631a2
--- /dev/null
8631a2
+++ b/m4/gettimeofday.m4
8631a2
@@ -0,0 +1,138 @@
8631a2
+# serial 21
8631a2
+
8631a2
+# Copyright (C) 2001-2003, 2005, 2007, 2009-2014 Free Software Foundation, Inc.
8631a2
+# This file is free software; the Free Software Foundation
8631a2
+# gives unlimited permission to copy and/or distribute it,
8631a2
+# with or without modifications, as long as this notice is preserved.
8631a2
+
8631a2
+dnl From Jim Meyering.
8631a2
+
8631a2
+AC_DEFUN([gl_FUNC_GETTIMEOFDAY],
8631a2
+[
8631a2
+  AC_REQUIRE([AC_C_RESTRICT])
8631a2
+  AC_REQUIRE([gl_HEADER_SYS_TIME_H])
8631a2
+  AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
8631a2
+  AC_CHECK_FUNCS_ONCE([gettimeofday])
8631a2
+
8631a2
+  gl_gettimeofday_timezone=void
8631a2
+  if test $ac_cv_func_gettimeofday != yes; then
8631a2
+    HAVE_GETTIMEOFDAY=0
8631a2
+  else
8631a2
+    gl_FUNC_GETTIMEOFDAY_CLOBBER
8631a2
+    AC_CACHE_CHECK([for gettimeofday with POSIX signature],
8631a2
+      [gl_cv_func_gettimeofday_posix_signature],
8631a2
+      [AC_COMPILE_IFELSE(
8631a2
+         [AC_LANG_PROGRAM(
8631a2
+            [[#include <sys/time.h>
8631a2
+              struct timeval c;
8631a2
+              int gettimeofday (struct timeval *restrict, void *restrict);
8631a2
+            ]],
8631a2
+            [[/* glibc uses struct timezone * rather than the POSIX void *
8631a2
+                 if _GNU_SOURCE is defined.  However, since the only portable
8631a2
+                 use of gettimeofday uses NULL as the second parameter, and
8631a2
+                 since the glibc definition is actually more typesafe, it is
8631a2
+                 not worth wrapping this to get a compliant signature.  */
8631a2
+              int (*f) (struct timeval *restrict, void *restrict)
8631a2
+                = gettimeofday;
8631a2
+              int x = f (&c, 0);
8631a2
+              return !(x | c.tv_sec | c.tv_usec);
8631a2
+            ]])],
8631a2
+          [gl_cv_func_gettimeofday_posix_signature=yes],
8631a2
+          [AC_COMPILE_IFELSE(
8631a2
+            [AC_LANG_PROGRAM(
8631a2
+              [[#include <sys/time.h>
8631a2
+int gettimeofday (struct timeval *restrict, struct timezone *restrict);
8631a2
+              ]])],
8631a2
+            [gl_cv_func_gettimeofday_posix_signature=almost],
8631a2
+            [gl_cv_func_gettimeofday_posix_signature=no])])])
8631a2
+    if test $gl_cv_func_gettimeofday_posix_signature = almost; then
8631a2
+      gl_gettimeofday_timezone='struct timezone'
8631a2
+    elif test $gl_cv_func_gettimeofday_posix_signature != yes; then
8631a2
+      REPLACE_GETTIMEOFDAY=1
8631a2
+    fi
8631a2
+    dnl If we override 'struct timeval', we also have to override gettimeofday.
8631a2
+    if test $REPLACE_STRUCT_TIMEVAL = 1; then
8631a2
+      REPLACE_GETTIMEOFDAY=1
8631a2
+    fi
8631a2
+    m4_ifdef([gl_FUNC_TZSET_CLOBBER], [
8631a2
+      gl_FUNC_TZSET_CLOBBER
8631a2
+      case "$gl_cv_func_tzset_clobber" in
8631a2
+        *yes)
8631a2
+          REPLACE_GETTIMEOFDAY=1
8631a2
+          gl_GETTIMEOFDAY_REPLACE_LOCALTIME
8631a2
+          AC_DEFINE([tzset], [rpl_tzset],
8631a2
+            [Define to rpl_tzset if the wrapper function should be used.])
8631a2
+          AC_DEFINE([TZSET_CLOBBERS_LOCALTIME], [1],
8631a2
+            [Define if tzset clobbers localtime's static buffer.])
8631a2
+          ;;
8631a2
+      esac
8631a2
+    ])
8631a2
+  fi
8631a2
+  AC_DEFINE_UNQUOTED([GETTIMEOFDAY_TIMEZONE], [$gl_gettimeofday_timezone],
8631a2
+    [Define this to 'void' or 'struct timezone' to match the system's
8631a2
+     declaration of the second argument to gettimeofday.])
8631a2
+])
8631a2
+
8631a2
+
8631a2
+dnl See if gettimeofday clobbers the static buffer that localtime uses
8631a2
+dnl for its return value.  The gettimeofday function from Mac OS X 10.0.4
8631a2
+dnl (i.e., Darwin 1.3.7) has this problem.
8631a2
+dnl
8631a2
+dnl If it does, then arrange to use gettimeofday and localtime only via
8631a2
+dnl the wrapper functions that work around the problem.
8631a2
+
8631a2
+AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER],
8631a2
+[
8631a2
+ AC_REQUIRE([gl_HEADER_SYS_TIME_H])
8631a2
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
8631a2
+
8631a2
+ AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer],
8631a2
+  [gl_cv_func_gettimeofday_clobber],
8631a2
+  [AC_RUN_IFELSE(
8631a2
+     [AC_LANG_PROGRAM(
8631a2
+        [[#include <string.h>
8631a2
+          #include <sys/time.h>
8631a2
+          #include <time.h>
8631a2
+          #include <stdlib.h>
8631a2
+        ]],
8631a2
+        [[
8631a2
+          time_t t = 0;
8631a2
+          struct tm *lt;
8631a2
+          struct tm saved_lt;
8631a2
+          struct timeval tv;
8631a2
+          lt = localtime (&t);
8631a2
+          saved_lt = *lt;
8631a2
+          gettimeofday (&tv, NULL);
8631a2
+          return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0;
8631a2
+        ]])],
8631a2
+     [gl_cv_func_gettimeofday_clobber=no],
8631a2
+     [gl_cv_func_gettimeofday_clobber=yes],
8631a2
+     [# When cross-compiling:
8631a2
+      case "$host_os" in
8631a2
+                # Guess all is fine on glibc systems.
8631a2
+        *-gnu*) gl_cv_func_gettimeofday_clobber="guessing no" ;;
8631a2
+                # If we don't know, assume the worst.
8631a2
+        *)      gl_cv_func_gettimeofday_clobber="guessing yes" ;;
8631a2
+      esac
8631a2
+     ])])
8631a2
+
8631a2
+ case "$gl_cv_func_gettimeofday_clobber" in
8631a2
+   *yes)
8631a2
+     REPLACE_GETTIMEOFDAY=1
8631a2
+     gl_GETTIMEOFDAY_REPLACE_LOCALTIME
8631a2
+     AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], [1],
8631a2
+       [Define if gettimeofday clobbers the localtime buffer.])
8631a2
+     ;;
8631a2
+ esac
8631a2
+])
8631a2
+
8631a2
+AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
8631a2
+  REPLACE_GMTIME=1
8631a2
+  REPLACE_LOCALTIME=1
8631a2
+])
8631a2
+
8631a2
+# Prerequisites of lib/gettimeofday.c.
8631a2
+AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [
8631a2
+  AC_CHECK_HEADERS([sys/timeb.h])
8631a2
+  AC_CHECK_FUNCS([_ftime])
8631a2
+])
8631a2
diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4
09e3cc
index 408918440..ef2ec5bcc 100644
8631a2
--- a/m4/gnulib-cache.m4
8631a2
+++ b/m4/gnulib-cache.m4
8631a2
@@ -27,7 +27,7 @@
8631a2
 
8631a2
 
8631a2
 # Specification in the form of a command-line invocation:
8631a2
-#   gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname regex
8631a2
+#   gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname readlink regex
8631a2
 
8631a2
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
8631a2
 gl_LOCAL_DIR([])
8631a2
@@ -39,6 +39,7 @@ gl_MODULES([
8631a2
   getline
8631a2
   gettext
8631a2
   progname
8631a2
+  readlink
8631a2
   regex
8631a2
 ])
8631a2
 gl_AVOID([])
8631a2
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4
09e3cc
index 7a19f60d8..66fd0eda9 100644
8631a2
--- a/m4/gnulib-comp.m4
8631a2
+++ b/m4/gnulib-comp.m4
8631a2
@@ -60,10 +60,13 @@ AC_DEFUN([gl_EARLY],
8631a2
   # Code from module getopt-posix:
8631a2
   # Code from module gettext:
8631a2
   # Code from module gettext-h:
8631a2
+  # Code from module gettimeofday:
8631a2
   # Code from module havelib:
8631a2
   # Code from module include_next:
8631a2
   # Code from module intprops:
8631a2
   # Code from module langinfo:
8631a2
+  # Code from module largefile:
8631a2
+  AC_REQUIRE([AC_SYS_LARGEFILE])
8631a2
   # Code from module localcharset:
8631a2
   # Code from module locale:
8631a2
   # Code from module localeconv:
8631a2
@@ -81,8 +84,10 @@ AC_DEFUN([gl_EARLY],
8631a2
   # Code from module multiarch:
8631a2
   # Code from module nl_langinfo:
8631a2
   # Code from module nocrash:
8631a2
+  # Code from module pathmax:
8631a2
   # Code from module progname:
8631a2
   # Code from module rawmemchr:
8631a2
+  # Code from module readlink:
8631a2
   # Code from module realloc-posix:
8631a2
   # Code from module regex:
8631a2
   # Code from module size_max:
8631a2
@@ -92,6 +97,7 @@ AC_DEFUN([gl_EARLY],
8631a2
   # Code from module snippet/c++defs:
8631a2
   # Code from module snippet/warn-on-use:
8631a2
   # Code from module ssize_t:
8631a2
+  # Code from module stat:
8631a2
   # Code from module stdalign:
8631a2
   # Code from module stdbool:
8631a2
   # Code from module stddef:
8631a2
@@ -108,8 +114,11 @@ AC_DEFUN([gl_EARLY],
8631a2
   # Code from module strndup:
8631a2
   # Code from module strnlen:
8631a2
   # Code from module strnlen1:
8631a2
+  # Code from module sys_stat:
8631a2
+  # Code from module sys_time:
8631a2
   # Code from module sys_types:
8631a2
   # Code from module sysexits:
8631a2
+  # Code from module time:
8631a2
   # Code from module unistd:
8631a2
   # Code from module unitypes:
8631a2
   # Code from module uniwidth/base:
8631a2
@@ -211,7 +220,14 @@ AC_DEFUN([gl_INIT],
8631a2
   AM_GNU_GETTEXT_VERSION([0.18.1])
8631a2
   AC_SUBST([LIBINTL])
8631a2
   AC_SUBST([LTLIBINTL])
8631a2
+  gl_FUNC_GETTIMEOFDAY
8631a2
+  if test $HAVE_GETTIMEOFDAY = 0 || test $REPLACE_GETTIMEOFDAY = 1; then
8631a2
+    AC_LIBOBJ([gettimeofday])
8631a2
+    gl_PREREQ_GETTIMEOFDAY
8631a2
+  fi
8631a2
+  gl_SYS_TIME_MODULE_INDICATOR([gettimeofday])
8631a2
   gl_LANGINFO_H
8631a2
+  AC_REQUIRE([gl_LARGEFILE])
8631a2
   gl_LOCALCHARSET
8631a2
   LOCALCHARSET_TESTS_ENVIRONMENT="CHARSETALIASDIR=\"\$(abs_top_builddir)/$gl_source_base\""
8631a2
   AC_SUBST([LOCALCHARSET_TESTS_ENVIRONMENT])
8631a2
@@ -284,6 +300,7 @@ AC_DEFUN([gl_INIT],
8631a2
     AC_LIBOBJ([nl_langinfo])
8631a2
   fi
8631a2
   gl_LANGINFO_MODULE_INDICATOR([nl_langinfo])
8631a2
+  gl_PATHMAX
8631a2
   AC_CHECK_DECLS([program_invocation_name], [], [], [#include <errno.h>])
8631a2
   AC_CHECK_DECLS([program_invocation_short_name], [], [], [#include <errno.h>])
8631a2
   gl_FUNC_RAWMEMCHR
8631a2
@@ -292,6 +309,12 @@ AC_DEFUN([gl_INIT],
8631a2
     gl_PREREQ_RAWMEMCHR
8631a2
   fi
8631a2
   gl_STRING_MODULE_INDICATOR([rawmemchr])
8631a2
+  gl_FUNC_READLINK
8631a2
+  if test $HAVE_READLINK = 0 || test $REPLACE_READLINK = 1; then
8631a2
+    AC_LIBOBJ([readlink])
8631a2
+    gl_PREREQ_READLINK
8631a2
+  fi
8631a2
+  gl_UNISTD_MODULE_INDICATOR([readlink])
8631a2
   gl_FUNC_REALLOC_POSIX
8631a2
   if test $REPLACE_REALLOC = 1; then
8631a2
     AC_LIBOBJ([realloc])
8631a2
@@ -309,6 +332,12 @@ AC_DEFUN([gl_INIT],
8631a2
   fi
8631a2
   gl_UNISTD_MODULE_INDICATOR([sleep])
8631a2
   gt_TYPE_SSIZE_T
8631a2
+  gl_FUNC_STAT
8631a2
+  if test $REPLACE_STAT = 1; then
8631a2
+    AC_LIBOBJ([stat])
8631a2
+    gl_PREREQ_STAT
8631a2
+  fi
8631a2
+  gl_SYS_STAT_MODULE_INDICATOR([stat])
8631a2
   gl_STDALIGN_H
8631a2
   AM_STDBOOL_H
8631a2
   gl_STDDEF_H
8631a2
@@ -355,9 +384,14 @@ AC_DEFUN([gl_INIT],
8631a2
     gl_PREREQ_STRNLEN
8631a2
   fi
8631a2
   gl_STRING_MODULE_INDICATOR([strnlen])
8631a2
+  gl_HEADER_SYS_STAT_H
8631a2
+  AC_PROG_MKDIR_P
8631a2
+  gl_HEADER_SYS_TIME_H
8631a2
+  AC_PROG_MKDIR_P
8631a2
   gl_SYS_TYPES_H
8631a2
   AC_PROG_MKDIR_P
8631a2
   gl_SYSEXITS
8631a2
+  gl_HEADER_TIME_H
8631a2
   gl_UNISTD_H
8631a2
   gl_LIBUNISTRING_LIBHEADER([0.9], [unitypes.h])
8631a2
   gl_LIBUNISTRING_LIBHEADER([0.9], [uniwidth.h])
8631a2
@@ -562,6 +596,7 @@ AC_DEFUN([gl_FILE_LIST], [
8631a2
   lib/getopt1.c
8631a2
   lib/getopt_int.h
8631a2
   lib/gettext.h
8631a2
+  lib/gettimeofday.c
8631a2
   lib/intprops.h
8631a2
   lib/itold.c
8631a2
   lib/langinfo.in.h
8631a2
@@ -587,6 +622,7 @@ AC_DEFUN([gl_FILE_LIST], [
8631a2
   lib/msvc-nothrow.c
8631a2
   lib/msvc-nothrow.h
8631a2
   lib/nl_langinfo.c
8631a2
+  lib/pathmax.h
8631a2
   lib/printf-args.c
8631a2
   lib/printf-args.h
8631a2
   lib/printf-parse.c
8631a2
@@ -595,6 +631,7 @@ AC_DEFUN([gl_FILE_LIST], [
8631a2
   lib/progname.h
8631a2
   lib/rawmemchr.c
8631a2
   lib/rawmemchr.valgrind
8631a2
+  lib/readlink.c
8631a2
   lib/realloc.c
8631a2
   lib/ref-add.sin
8631a2
   lib/ref-del.sin
8631a2
@@ -606,6 +643,7 @@ AC_DEFUN([gl_FILE_LIST], [
8631a2
   lib/regexec.c
8631a2
   lib/size_max.h
8631a2
   lib/sleep.c
8631a2
+  lib/stat.c
8631a2
   lib/stdalign.in.h
8631a2
   lib/stdbool.in.h
8631a2
   lib/stddef.in.h
8631a2
@@ -627,8 +665,11 @@ AC_DEFUN([gl_FILE_LIST], [
8631a2
   lib/strnlen.c
8631a2
   lib/strnlen1.c
8631a2
   lib/strnlen1.h
8631a2
+  lib/sys_stat.in.h
8631a2
+  lib/sys_time.in.h
8631a2
   lib/sys_types.in.h
8631a2
   lib/sysexits.in.h
8631a2
+  lib/time.in.h
8631a2
   lib/unistd.c
8631a2
   lib/unistd.in.h
8631a2
   lib/unitypes.in.h
8631a2
@@ -667,6 +708,7 @@ AC_DEFUN([gl_FILE_LIST], [
8631a2
   m4/getline.m4
8631a2
   m4/getopt.m4
8631a2
   m4/gettext.m4
8631a2
+  m4/gettimeofday.m4
8631a2
   m4/glibc2.m4
8631a2
   m4/glibc21.m4
8631a2
   m4/gnulib-common.m4
8631a2
@@ -681,6 +723,7 @@ AC_DEFUN([gl_FILE_LIST], [
8631a2
   m4/inttypes-pri.m4
8631a2
   m4/inttypes_h.m4
8631a2
   m4/langinfo_h.m4
8631a2
+  m4/largefile.m4
8631a2
   m4/lcmessage.m4
8631a2
   m4/lib-ld.m4
8631a2
   m4/lib-link.m4
8631a2
@@ -712,16 +755,19 @@ AC_DEFUN([gl_FILE_LIST], [
8631a2
   m4/nls.m4
8631a2
   m4/nocrash.m4
8631a2
   m4/off_t.m4
8631a2
+  m4/pathmax.m4
8631a2
   m4/po.m4
8631a2
   m4/printf-posix.m4
8631a2
   m4/printf.m4
8631a2
   m4/progtest.m4
8631a2
   m4/rawmemchr.m4
8631a2
+  m4/readlink.m4
8631a2
   m4/realloc.m4
8631a2
   m4/regex.m4
8631a2
   m4/size_max.m4
8631a2
   m4/sleep.m4
8631a2
   m4/ssize_t.m4
8631a2
+  m4/stat.m4
8631a2
   m4/stdalign.m4
8631a2
   m4/stdbool.m4
8631a2
   m4/stddef_h.m4
8631a2
@@ -737,9 +783,12 @@ AC_DEFUN([gl_FILE_LIST], [
8631a2
   m4/strndup.m4
8631a2
   m4/strnlen.m4
8631a2
   m4/sys_socket_h.m4
8631a2
+  m4/sys_stat_h.m4
8631a2
+  m4/sys_time_h.m4
8631a2
   m4/sys_types_h.m4
8631a2
   m4/sysexits.m4
8631a2
   m4/threadlib.m4
8631a2
+  m4/time_h.m4
8631a2
   m4/uintmax_t.m4
8631a2
   m4/unistd_h.m4
8631a2
   m4/vasnprintf.m4
8631a2
diff --git a/m4/largefile.m4 b/m4/largefile.m4
8631a2
new file mode 100644
09e3cc
index 000000000..a1b564ad9
8631a2
--- /dev/null
8631a2
+++ b/m4/largefile.m4
8631a2
@@ -0,0 +1,146 @@
8631a2
+# Enable large files on systems where this is not the default.
8631a2
+
8631a2
+# Copyright 1992-1996, 1998-2014 Free Software Foundation, Inc.
8631a2
+# This file is free software; the Free Software Foundation
8631a2
+# gives unlimited permission to copy and/or distribute it,
8631a2
+# with or without modifications, as long as this notice is preserved.
8631a2
+
8631a2
+# The following implementation works around a problem in autoconf <= 2.69;
8631a2
+# AC_SYS_LARGEFILE does not configure for large inodes on Mac OS X 10.5,
8631a2
+# or configures them incorrectly in some cases.
8631a2
+m4_version_prereq([2.70], [] ,[
8631a2
+
8631a2
+# _AC_SYS_LARGEFILE_TEST_INCLUDES
8631a2
+# -------------------------------
8631a2
+m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES],
8631a2
+[@%:@include <sys/types.h>
8631a2
+ /* Check that off_t can represent 2**63 - 1 correctly.
8631a2
+    We can't simply define LARGE_OFF_T to be 9223372036854775807,
8631a2
+    since some C++ compilers masquerading as C compilers
8631a2
+    incorrectly reject 9223372036854775807.  */
8631a2
+@%:@define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
8631a2
+  int off_t_is_large[[(LARGE_OFF_T % 2147483629 == 721
8631a2
+                       && LARGE_OFF_T % 2147483647 == 1)
8631a2
+                      ? 1 : -1]];[]dnl
8631a2
+])
8631a2
+
8631a2
+
8631a2
+# _AC_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE,
8631a2
+#                               CACHE-VAR,
8631a2
+#                               DESCRIPTION,
8631a2
+#                               PROLOGUE, [FUNCTION-BODY])
8631a2
+# --------------------------------------------------------
8631a2
+m4_define([_AC_SYS_LARGEFILE_MACRO_VALUE],
8631a2
+[AC_CACHE_CHECK([for $1 value needed for large files], [$3],
8631a2
+[while :; do
8631a2
+  m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])(
8631a2
+    [AC_LANG_PROGRAM([$5], [$6])],
8631a2
+    [$3=no; break])
8631a2
+  m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])(
8631a2
+    [AC_LANG_PROGRAM([@%:@define $1 $2
8631a2
+$5], [$6])],
8631a2
+    [$3=$2; break])
8631a2
+  $3=unknown
8631a2
+  break
8631a2
+done])
8631a2
+case $$3 in #(
8631a2
+  no | unknown) ;;
8631a2
+  *) AC_DEFINE_UNQUOTED([$1], [$$3], [$4]);;
8631a2
+esac
8631a2
+rm -rf conftest*[]dnl
8631a2
+])# _AC_SYS_LARGEFILE_MACRO_VALUE
8631a2
+
8631a2
+
8631a2
+# AC_SYS_LARGEFILE
8631a2
+# ----------------
8631a2
+# By default, many hosts won't let programs access large files;
8631a2
+# one must use special compiler options to get large-file access to work.
8631a2
+# For more details about this brain damage please see:
8631a2
+# http://www.unix-systems.org/version2/whatsnew/lfs20mar.html
8631a2
+AC_DEFUN([AC_SYS_LARGEFILE],
8631a2
+[AC_ARG_ENABLE(largefile,
8631a2
+               [  --disable-largefile     omit support for large files])
8631a2
+if test "$enable_largefile" != no; then
8631a2
+
8631a2
+  AC_CACHE_CHECK([for special C compiler options needed for large files],
8631a2
+    ac_cv_sys_largefile_CC,
8631a2
+    [ac_cv_sys_largefile_CC=no
8631a2
+     if test "$GCC" != yes; then
8631a2
+       ac_save_CC=$CC
8631a2
+       while :; do
8631a2
+         # IRIX 6.2 and later do not support large files by default,
8631a2
+         # so use the C compiler's -n32 option if that helps.
8631a2
+         AC_LANG_CONFTEST([AC_LANG_PROGRAM([_AC_SYS_LARGEFILE_TEST_INCLUDES])])
8631a2
+         AC_COMPILE_IFELSE([], [break])
8631a2
+         CC="$CC -n32"
8631a2
+         AC_COMPILE_IFELSE([], [ac_cv_sys_largefile_CC=' -n32'; break])
8631a2
+         break
8631a2
+       done
8631a2
+       CC=$ac_save_CC
8631a2
+       rm -f conftest.$ac_ext
8631a2
+    fi])
8631a2
+  if test "$ac_cv_sys_largefile_CC" != no; then
8631a2
+    CC=$CC$ac_cv_sys_largefile_CC
8631a2
+  fi
8631a2
+
8631a2
+  _AC_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64,
8631a2
+    ac_cv_sys_file_offset_bits,
8631a2
+    [Number of bits in a file offset, on hosts where this is settable.],
8631a2
+    [_AC_SYS_LARGEFILE_TEST_INCLUDES])
8631a2
+  if test $ac_cv_sys_file_offset_bits = unknown; then
8631a2
+    _AC_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1,
8631a2
+      ac_cv_sys_large_files,
8631a2
+      [Define for large files, on AIX-style hosts.],
8631a2
+      [_AC_SYS_LARGEFILE_TEST_INCLUDES])
8631a2
+  fi
8631a2
+
8631a2
+  AC_DEFINE([_DARWIN_USE_64_BIT_INODE], [1],
8631a2
+    [Enable large inode numbers on Mac OS X 10.5.])
8631a2
+fi
8631a2
+])# AC_SYS_LARGEFILE
8631a2
+])# m4_version_prereq 2.70
8631a2
+
8631a2
+# Enable large files on systems where this is implemented by Gnulib, not by the
8631a2
+# system headers.
8631a2
+# Set the variables WINDOWS_64_BIT_OFF_T, WINDOWS_64_BIT_ST_SIZE if Gnulib
8631a2
+# overrides ensure that off_t or 'struct size.st_size' are 64-bit, respectively.
8631a2
+AC_DEFUN([gl_LARGEFILE],
8631a2
+[
8631a2
+  AC_REQUIRE([AC_CANONICAL_HOST])
8631a2
+  case "$host_os" in
8631a2
+    mingw*)
8631a2
+      dnl Native Windows.
8631a2
+      dnl mingw64 defines off_t to a 64-bit type already, if
8631a2
+      dnl _FILE_OFFSET_BITS=64, which is ensured by AC_SYS_LARGEFILE.
8631a2
+      AC_CACHE_CHECK([for 64-bit off_t], [gl_cv_type_off_t_64],
8631a2
+        [AC_COMPILE_IFELSE(
8631a2
+           [AC_LANG_PROGRAM(
8631a2
+              [[#include <sys/types.h>
8631a2
+                int verify_off_t_size[sizeof (off_t) >= 8 ? 1 : -1];
8631a2
+              ]],
8631a2
+              [[]])],
8631a2
+           [gl_cv_type_off_t_64=yes], [gl_cv_type_off_t_64=no])
8631a2
+        ])
8631a2
+      if test $gl_cv_type_off_t_64 = no; then
8631a2
+        WINDOWS_64_BIT_OFF_T=1
8631a2
+      else
8631a2
+        WINDOWS_64_BIT_OFF_T=0
8631a2
+      fi
8631a2
+      dnl But all native Windows platforms (including mingw64) have a 32-bit
8631a2
+      dnl st_size member in 'struct stat'.
8631a2
+      WINDOWS_64_BIT_ST_SIZE=1
8631a2
+      ;;
8631a2
+    *)
8631a2
+      dnl Nothing to do on gnulib's side.
8631a2
+      dnl A 64-bit off_t is
8631a2
+      dnl   - already the default on Mac OS X, FreeBSD, NetBSD, OpenBSD, IRIX,
8631a2
+      dnl     OSF/1, Cygwin,
8631a2
+      dnl   - enabled by _FILE_OFFSET_BITS=64 (ensured by AC_SYS_LARGEFILE) on
8631a2
+      dnl     glibc, HP-UX, Solaris,
8631a2
+      dnl   - enabled by _LARGE_FILES=1 (ensured by AC_SYS_LARGEFILE) on AIX,
8631a2
+      dnl   - impossible to achieve on Minix 3.1.8.
8631a2
+      WINDOWS_64_BIT_OFF_T=0
8631a2
+      WINDOWS_64_BIT_ST_SIZE=0
8631a2
+      ;;
8631a2
+  esac
8631a2
+])
8631a2
diff --git a/m4/pathmax.m4 b/m4/pathmax.m4
8631a2
new file mode 100644
09e3cc
index 000000000..114f91f04
8631a2
--- /dev/null
8631a2
+++ b/m4/pathmax.m4
8631a2
@@ -0,0 +1,42 @@
8631a2
+# pathmax.m4 serial 10
8631a2
+dnl Copyright (C) 2002-2003, 2005-2006, 2009-2014 Free Software Foundation,
8631a2
+dnl Inc.
8631a2
+dnl This file is free software; the Free Software Foundation
8631a2
+dnl gives unlimited permission to copy and/or distribute it,
8631a2
+dnl with or without modifications, as long as this notice is preserved.
8631a2
+
8631a2
+AC_DEFUN([gl_PATHMAX],
8631a2
+[
8631a2
+  dnl Prerequisites of lib/pathmax.h.
8631a2
+  AC_CHECK_HEADERS_ONCE([sys/param.h])
8631a2
+])
8631a2
+
8631a2
+# Expands to a piece of C program that defines PATH_MAX in the same way as
8631a2
+# "pathmax.h" will do.
8631a2
+AC_DEFUN([gl_PATHMAX_SNIPPET], [[
8631a2
+/* Arrange to define PATH_MAX, like "pathmax.h" does. */
8631a2
+#if HAVE_UNISTD_H
8631a2
+# include <unistd.h>
8631a2
+#endif
8631a2
+#include <limits.h>
8631a2
+#if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
8631a2
+# include <sys/param.h>
8631a2
+#endif
8631a2
+#if !defined PATH_MAX && defined MAXPATHLEN
8631a2
+# define PATH_MAX MAXPATHLEN
8631a2
+#endif
8631a2
+#ifdef __hpux
8631a2
+# undef PATH_MAX
8631a2
+# define PATH_MAX 1024
8631a2
+#endif
8631a2
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
8631a2
+# undef PATH_MAX
8631a2
+# define PATH_MAX 260
8631a2
+#endif
8631a2
+]])
8631a2
+
8631a2
+# Prerequisites of gl_PATHMAX_SNIPPET.
8631a2
+AC_DEFUN([gl_PATHMAX_SNIPPET_PREREQ],
8631a2
+[
8631a2
+  AC_CHECK_HEADERS_ONCE([unistd.h sys/param.h])
8631a2
+])
8631a2
diff --git a/m4/readlink.m4 b/m4/readlink.m4
8631a2
new file mode 100644
09e3cc
index 000000000..f9ce868c2
8631a2
--- /dev/null
8631a2
+++ b/m4/readlink.m4
8631a2
@@ -0,0 +1,71 @@
8631a2
+# readlink.m4 serial 12
8631a2
+dnl Copyright (C) 2003, 2007, 2009-2014 Free Software Foundation, Inc.
8631a2
+dnl This file is free software; the Free Software Foundation
8631a2
+dnl gives unlimited permission to copy and/or distribute it,
8631a2
+dnl with or without modifications, as long as this notice is preserved.
8631a2
+
8631a2
+AC_DEFUN([gl_FUNC_READLINK],
8631a2
+[
8631a2
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
8631a2
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
8631a2
+  AC_CHECK_FUNCS_ONCE([readlink])
8631a2
+  if test $ac_cv_func_readlink = no; then
8631a2
+    HAVE_READLINK=0
8631a2
+  else
8631a2
+    AC_CACHE_CHECK([whether readlink signature is correct],
8631a2
+      [gl_cv_decl_readlink_works],
8631a2
+      [AC_COMPILE_IFELSE(
8631a2
+         [AC_LANG_PROGRAM(
8631a2
+           [[#include <unistd.h>
8631a2
+      /* Cause compilation failure if original declaration has wrong type.  */
8631a2
+      ssize_t readlink (const char *, char *, size_t);]])],
8631a2
+         [gl_cv_decl_readlink_works=yes], [gl_cv_decl_readlink_works=no])])
8631a2
+    dnl Solaris 9 ignores trailing slash.
8631a2
+    dnl FreeBSD 7.2 dereferences only one level of links with trailing slash.
8631a2
+    AC_CACHE_CHECK([whether readlink handles trailing slash correctly],
8631a2
+      [gl_cv_func_readlink_works],
8631a2
+      [# We have readlink, so assume ln -s works.
8631a2
+       ln -s conftest.no-such conftest.link
8631a2
+       ln -s conftest.link conftest.lnk2
8631a2
+       AC_RUN_IFELSE(
8631a2
+         [AC_LANG_PROGRAM(
8631a2
+           [[#include <unistd.h>
8631a2
+]], [[char buf[20];
8631a2
+      return readlink ("conftest.lnk2/", buf, sizeof buf) != -1;]])],
8631a2
+         [gl_cv_func_readlink_works=yes], [gl_cv_func_readlink_works=no],
8631a2
+         [case "$host_os" in
8631a2
+                    # Guess yes on glibc systems.
8631a2
+            *-gnu*) gl_cv_func_readlink_works="guessing yes" ;;
8631a2
+                    # If we don't know, assume the worst.
8631a2
+            *)      gl_cv_func_readlink_works="guessing no" ;;
8631a2
+          esac
8631a2
+         ])
8631a2
+      rm -f conftest.link conftest.lnk2])
8631a2
+    case "$gl_cv_func_readlink_works" in
8631a2
+      *yes)
8631a2
+        if test "$gl_cv_decl_readlink_works" != yes; then
8631a2
+          REPLACE_READLINK=1
8631a2
+        fi
8631a2
+        ;;
8631a2
+      *)
8631a2
+        AC_DEFINE([READLINK_TRAILING_SLASH_BUG], [1], [Define to 1 if readlink
8631a2
+          fails to recognize a trailing slash.])
8631a2
+        REPLACE_READLINK=1
8631a2
+        ;;
8631a2
+    esac
8631a2
+  fi
8631a2
+])
8631a2
+
8631a2
+# Like gl_FUNC_READLINK, except prepare for separate compilation
8631a2
+# (no REPLACE_READLINK, no AC_LIBOBJ).
8631a2
+AC_DEFUN([gl_FUNC_READLINK_SEPARATE],
8631a2
+[
8631a2
+  AC_CHECK_FUNCS_ONCE([readlink])
8631a2
+  gl_PREREQ_READLINK
8631a2
+])
8631a2
+
8631a2
+# Prerequisites of lib/readlink.c.
8631a2
+AC_DEFUN([gl_PREREQ_READLINK],
8631a2
+[
8631a2
+  :
8631a2
+])
8631a2
diff --git a/m4/stat.m4 b/m4/stat.m4
8631a2
new file mode 100644
09e3cc
index 000000000..1ae327b36
8631a2
--- /dev/null
8631a2
+++ b/m4/stat.m4
8631a2
@@ -0,0 +1,71 @@
8631a2
+# serial 11
8631a2
+
8631a2
+# Copyright (C) 2009-2014 Free Software Foundation, Inc.
8631a2
+#
8631a2
+# This file is free software; the Free Software Foundation
8631a2
+# gives unlimited permission to copy and/or distribute it,
8631a2
+# with or without modifications, as long as this notice is preserved.
8631a2
+
8631a2
+AC_DEFUN([gl_FUNC_STAT],
8631a2
+[
8631a2
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
8631a2
+  AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
8631a2
+  AC_CHECK_FUNCS_ONCE([lstat])
8631a2
+  dnl mingw is the only known platform where stat(".") and stat("./") differ
8631a2
+  AC_CACHE_CHECK([whether stat handles trailing slashes on directories],
8631a2
+      [gl_cv_func_stat_dir_slash],
8631a2
+      [AC_RUN_IFELSE(
8631a2
+         [AC_LANG_PROGRAM(
8631a2
+           [[#include <sys/stat.h>
8631a2
+]], [[struct stat st; return stat (".", &st) != stat ("./", &st);]])],
8631a2
+         [gl_cv_func_stat_dir_slash=yes], [gl_cv_func_stat_dir_slash=no],
8631a2
+         [case $host_os in
8631a2
+            mingw*) gl_cv_func_stat_dir_slash="guessing no";;
8631a2
+            *) gl_cv_func_stat_dir_slash="guessing yes";;
8631a2
+          esac])])
8631a2
+  dnl AIX 7.1, Solaris 9, mingw64 mistakenly succeed on stat("file/").
8631a2
+  dnl (For mingw, this is due to a broken stat() override in libmingwex.a.)
8631a2
+  dnl FreeBSD 7.2 mistakenly succeeds on stat("link-to-file/").
8631a2
+  AC_CACHE_CHECK([whether stat handles trailing slashes on files],
8631a2
+      [gl_cv_func_stat_file_slash],
8631a2
+      [touch conftest.tmp
8631a2
+       # Assume that if we have lstat, we can also check symlinks.
8631a2
+       if test $ac_cv_func_lstat = yes; then
8631a2
+         ln -s conftest.tmp conftest.lnk
8631a2
+       fi
8631a2
+       AC_RUN_IFELSE(
8631a2
+         [AC_LANG_PROGRAM(
8631a2
+           [[#include <sys/stat.h>
8631a2
+]], [[int result = 0;
8631a2
+      struct stat st;
8631a2
+      if (!stat ("conftest.tmp/", &st))
8631a2
+        result |= 1;
8631a2
+#if HAVE_LSTAT
8631a2
+      if (!stat ("conftest.lnk/", &st))
8631a2
+        result |= 2;
8631a2
+#endif
8631a2
+      return result;
8631a2
+           ]])],
8631a2
+         [gl_cv_func_stat_file_slash=yes], [gl_cv_func_stat_file_slash=no],
8631a2
+         [case "$host_os" in
8631a2
+                    # Guess yes on glibc systems.
8631a2
+            *-gnu*) gl_cv_func_stat_file_slash="guessing yes" ;;
8631a2
+                    # If we don't know, assume the worst.
8631a2
+            *)      gl_cv_func_stat_file_slash="guessing no" ;;
8631a2
+          esac
8631a2
+         ])
8631a2
+       rm -f conftest.tmp conftest.lnk])
8631a2
+  case $gl_cv_func_stat_dir_slash in
8631a2
+    *no) REPLACE_STAT=1
8631a2
+      AC_DEFINE([REPLACE_FUNC_STAT_DIR], [1], [Define to 1 if stat needs
8631a2
+        help when passed a directory name with a trailing slash]);;
8631a2
+  esac
8631a2
+  case $gl_cv_func_stat_file_slash in
8631a2
+    *no) REPLACE_STAT=1
8631a2
+      AC_DEFINE([REPLACE_FUNC_STAT_FILE], [1], [Define to 1 if stat needs
8631a2
+        help when passed a file name with a trailing slash]);;
8631a2
+  esac
8631a2
+])
8631a2
+
8631a2
+# Prerequisites of lib/stat.c.
8631a2
+AC_DEFUN([gl_PREREQ_STAT], [:])
8631a2
diff --git a/m4/sys_stat_h.m4 b/m4/sys_stat_h.m4
8631a2
new file mode 100644
09e3cc
index 000000000..eaa7642ba
8631a2
--- /dev/null
8631a2
+++ b/m4/sys_stat_h.m4
8631a2
@@ -0,0 +1,96 @@
8631a2
+# sys_stat_h.m4 serial 28   -*- Autoconf -*-
8631a2
+dnl Copyright (C) 2006-2014 Free Software Foundation, Inc.
8631a2
+dnl This file is free software; the Free Software Foundation
8631a2
+dnl gives unlimited permission to copy and/or distribute it,
8631a2
+dnl with or without modifications, as long as this notice is preserved.
8631a2
+
8631a2
+dnl From Eric Blake.
8631a2
+dnl Provide a GNU-like <sys/stat.h>.
8631a2
+
8631a2
+AC_DEFUN([gl_HEADER_SYS_STAT_H],
8631a2
+[
8631a2
+  AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
8631a2
+
8631a2
+  dnl Check for broken stat macros.
8631a2
+  AC_REQUIRE([AC_HEADER_STAT])
8631a2
+
8631a2
+  gl_CHECK_NEXT_HEADERS([sys/stat.h])
8631a2
+
8631a2
+  dnl Ensure the type mode_t gets defined.
8631a2
+  AC_REQUIRE([AC_TYPE_MODE_T])
8631a2
+
8631a2
+  dnl Whether to override 'struct stat'.
8631a2
+  m4_ifdef([gl_LARGEFILE], [
8631a2
+    AC_REQUIRE([gl_LARGEFILE])
8631a2
+  ], [
8631a2
+    WINDOWS_64_BIT_ST_SIZE=0
8631a2
+  ])
8631a2
+  AC_SUBST([WINDOWS_64_BIT_ST_SIZE])
8631a2
+  if test $WINDOWS_64_BIT_ST_SIZE = 1; then
8631a2
+    AC_DEFINE([_GL_WINDOWS_64_BIT_ST_SIZE], [1],
8631a2
+      [Define to 1 if Gnulib overrides 'struct stat' on Windows so that
8631a2
+       struct stat.st_size becomes 64-bit.])
8631a2
+  fi
8631a2
+
8631a2
+  dnl Define types that are supposed to be defined in <sys/types.h> or
8631a2
+  dnl <sys/stat.h>.
8631a2
+  AC_CHECK_TYPE([nlink_t], [],
8631a2
+    [AC_DEFINE([nlink_t], [int],
8631a2
+       [Define to the type of st_nlink in struct stat, or a supertype.])],
8631a2
+    [#include <sys/types.h>
8631a2
+     #include <sys/stat.h>])
8631a2
+
8631a2
+  dnl Check for declarations of anything we want to poison if the
8631a2
+  dnl corresponding gnulib module is not in use.
8631a2
+  gl_WARN_ON_USE_PREPARE([[#include <sys/stat.h>
8631a2
+    ]], [fchmodat fstat fstatat futimens lchmod lstat mkdirat mkfifo mkfifoat
8631a2
+    mknod mknodat stat utimensat])
8631a2
+]) # gl_HEADER_SYS_STAT_H
8631a2
+
8631a2
+AC_DEFUN([gl_SYS_STAT_MODULE_INDICATOR],
8631a2
+[
8631a2
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
8631a2
+  AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
8631a2
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
8631a2
+  dnl Define it also as a C macro, for the benefit of the unit tests.
8631a2
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
8631a2
+])
8631a2
+
8631a2
+AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
8631a2
+[
8631a2
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl for REPLACE_FCHDIR
8631a2
+  GNULIB_FCHMODAT=0;    AC_SUBST([GNULIB_FCHMODAT])
8631a2
+  GNULIB_FSTAT=0;       AC_SUBST([GNULIB_FSTAT])
8631a2
+  GNULIB_FSTATAT=0;     AC_SUBST([GNULIB_FSTATAT])
8631a2
+  GNULIB_FUTIMENS=0;    AC_SUBST([GNULIB_FUTIMENS])
8631a2
+  GNULIB_LCHMOD=0;      AC_SUBST([GNULIB_LCHMOD])
8631a2
+  GNULIB_LSTAT=0;       AC_SUBST([GNULIB_LSTAT])
8631a2
+  GNULIB_MKDIRAT=0;     AC_SUBST([GNULIB_MKDIRAT])
8631a2
+  GNULIB_MKFIFO=0;      AC_SUBST([GNULIB_MKFIFO])
8631a2
+  GNULIB_MKFIFOAT=0;    AC_SUBST([GNULIB_MKFIFOAT])
8631a2
+  GNULIB_MKNOD=0;       AC_SUBST([GNULIB_MKNOD])
8631a2
+  GNULIB_MKNODAT=0;     AC_SUBST([GNULIB_MKNODAT])
8631a2
+  GNULIB_STAT=0;        AC_SUBST([GNULIB_STAT])
8631a2
+  GNULIB_UTIMENSAT=0;   AC_SUBST([GNULIB_UTIMENSAT])
8631a2
+  dnl Assume proper GNU behavior unless another module says otherwise.
8631a2
+  HAVE_FCHMODAT=1;      AC_SUBST([HAVE_FCHMODAT])
8631a2
+  HAVE_FSTATAT=1;       AC_SUBST([HAVE_FSTATAT])
8631a2
+  HAVE_FUTIMENS=1;      AC_SUBST([HAVE_FUTIMENS])
8631a2
+  HAVE_LCHMOD=1;        AC_SUBST([HAVE_LCHMOD])
8631a2
+  HAVE_LSTAT=1;         AC_SUBST([HAVE_LSTAT])
8631a2
+  HAVE_MKDIRAT=1;       AC_SUBST([HAVE_MKDIRAT])
8631a2
+  HAVE_MKFIFO=1;        AC_SUBST([HAVE_MKFIFO])
8631a2
+  HAVE_MKFIFOAT=1;      AC_SUBST([HAVE_MKFIFOAT])
8631a2
+  HAVE_MKNOD=1;         AC_SUBST([HAVE_MKNOD])
8631a2
+  HAVE_MKNODAT=1;       AC_SUBST([HAVE_MKNODAT])
8631a2
+  HAVE_UTIMENSAT=1;     AC_SUBST([HAVE_UTIMENSAT])
8631a2
+  REPLACE_FSTAT=0;      AC_SUBST([REPLACE_FSTAT])
8631a2
+  REPLACE_FSTATAT=0;    AC_SUBST([REPLACE_FSTATAT])
8631a2
+  REPLACE_FUTIMENS=0;   AC_SUBST([REPLACE_FUTIMENS])
8631a2
+  REPLACE_LSTAT=0;      AC_SUBST([REPLACE_LSTAT])
8631a2
+  REPLACE_MKDIR=0;      AC_SUBST([REPLACE_MKDIR])
8631a2
+  REPLACE_MKFIFO=0;     AC_SUBST([REPLACE_MKFIFO])
8631a2
+  REPLACE_MKNOD=0;      AC_SUBST([REPLACE_MKNOD])
8631a2
+  REPLACE_STAT=0;       AC_SUBST([REPLACE_STAT])
8631a2
+  REPLACE_UTIMENSAT=0;  AC_SUBST([REPLACE_UTIMENSAT])
8631a2
+])
8631a2
diff --git a/m4/sys_time_h.m4 b/m4/sys_time_h.m4
8631a2
new file mode 100644
09e3cc
index 000000000..5c79300f8
8631a2
--- /dev/null
8631a2
+++ b/m4/sys_time_h.m4
8631a2
@@ -0,0 +1,110 @@
8631a2
+# Configure a replacement for <sys/time.h>.
8631a2
+# serial 8
8631a2
+
8631a2
+# Copyright (C) 2007, 2009-2014 Free Software Foundation, Inc.
8631a2
+# This file is free software; the Free Software Foundation
8631a2
+# gives unlimited permission to copy and/or distribute it,
8631a2
+# with or without modifications, as long as this notice is preserved.
8631a2
+
8631a2
+# Written by Paul Eggert and Martin Lambers.
8631a2
+
8631a2
+AC_DEFUN([gl_HEADER_SYS_TIME_H],
8631a2
+[
8631a2
+  dnl Use AC_REQUIRE here, so that the REPLACE_GETTIMEOFDAY=0 statement
8631a2
+  dnl below is expanded once only, before all REPLACE_GETTIMEOFDAY=1
8631a2
+  dnl statements that occur in other macros.
8631a2
+  AC_REQUIRE([gl_HEADER_SYS_TIME_H_BODY])
8631a2
+])
8631a2
+
8631a2
+AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
8631a2
+[
8631a2
+  AC_REQUIRE([AC_C_RESTRICT])
8631a2
+  AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
8631a2
+  AC_CHECK_HEADERS_ONCE([sys/time.h])
8631a2
+  gl_CHECK_NEXT_HEADERS([sys/time.h])
8631a2
+
8631a2
+  if test $ac_cv_header_sys_time_h != yes; then
8631a2
+    HAVE_SYS_TIME_H=0
8631a2
+  fi
8631a2
+
8631a2
+  dnl On native Windows with MSVC, 'struct timeval' is defined in <winsock2.h>
8631a2
+  dnl only. So include that header in the list.
8631a2
+  gl_PREREQ_SYS_H_WINSOCK2
8631a2
+  AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval],
8631a2
+    [AC_COMPILE_IFELSE(
8631a2
+       [AC_LANG_PROGRAM(
8631a2
+          [[#if HAVE_SYS_TIME_H
8631a2
+             #include <sys/time.h>
8631a2
+            #endif
8631a2
+            #include <time.h>
8631a2
+            #if HAVE_WINSOCK2_H
8631a2
+            # include <winsock2.h>
8631a2
+            #endif
8631a2
+          ]],
8631a2
+          [[static struct timeval x; x.tv_sec = x.tv_usec;]])],
8631a2
+       [gl_cv_sys_struct_timeval=yes],
8631a2
+       [gl_cv_sys_struct_timeval=no])
8631a2
+    ])
8631a2
+  if test $gl_cv_sys_struct_timeval != yes; then
8631a2
+    HAVE_STRUCT_TIMEVAL=0
8631a2
+  else
8631a2
+    dnl On native Windows with a 64-bit 'time_t', 'struct timeval' is defined
8631a2
+    dnl (in <sys/time.h> and <winsock2.h> for mingw64, in <winsock2.h> only
8631a2
+    dnl for MSVC) with a tv_sec field of type 'long' (32-bit!), which is
8631a2
+    dnl smaller than the 'time_t' type mandated by POSIX.
8631a2
+    dnl On OpenBSD 5.1 amd64, tv_sec is 64 bits and time_t 32 bits, but
8631a2
+    dnl that is good enough.
8631a2
+    AC_CACHE_CHECK([for wide-enough struct timeval.tv_sec member],
8631a2
+      [gl_cv_sys_struct_timeval_tv_sec],
8631a2
+      [AC_COMPILE_IFELSE(
8631a2
+         [AC_LANG_PROGRAM(
8631a2
+            [[#if HAVE_SYS_TIME_H
8631a2
+               #include <sys/time.h>
8631a2
+              #endif
8631a2
+              #include <time.h>
8631a2
+              #if HAVE_WINSOCK2_H
8631a2
+              # include <winsock2.h>
8631a2
+              #endif
8631a2
+            ]],
8631a2
+            [[static struct timeval x;
8631a2
+              typedef int verify_tv_sec_type[
8631a2
+                sizeof (time_t) <= sizeof x.tv_sec ? 1 : -1
8631a2
+              ];
8631a2
+            ]])],
8631a2
+         [gl_cv_sys_struct_timeval_tv_sec=yes],
8631a2
+         [gl_cv_sys_struct_timeval_tv_sec=no])
8631a2
+      ])
8631a2
+    if test $gl_cv_sys_struct_timeval_tv_sec != yes; then
8631a2
+      REPLACE_STRUCT_TIMEVAL=1
8631a2
+    fi
8631a2
+  fi
8631a2
+
8631a2
+  dnl Check for declarations of anything we want to poison if the
8631a2
+  dnl corresponding gnulib module is not in use.
8631a2
+  gl_WARN_ON_USE_PREPARE([[
8631a2
+#if HAVE_SYS_TIME_H
8631a2
+# include <sys/time.h>
8631a2
+#endif
8631a2
+#include <time.h>
8631a2
+    ]], [gettimeofday])
8631a2
+])
8631a2
+
8631a2
+AC_DEFUN([gl_SYS_TIME_MODULE_INDICATOR],
8631a2
+[
8631a2
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
8631a2
+  AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
8631a2
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
8631a2
+  dnl Define it also as a C macro, for the benefit of the unit tests.
8631a2
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
8631a2
+])
8631a2
+
8631a2
+AC_DEFUN([gl_HEADER_SYS_TIME_H_DEFAULTS],
8631a2
+[
8631a2
+  GNULIB_GETTIMEOFDAY=0;     AC_SUBST([GNULIB_GETTIMEOFDAY])
8631a2
+  dnl Assume POSIX behavior unless another module says otherwise.
8631a2
+  HAVE_GETTIMEOFDAY=1;       AC_SUBST([HAVE_GETTIMEOFDAY])
8631a2
+  HAVE_STRUCT_TIMEVAL=1;     AC_SUBST([HAVE_STRUCT_TIMEVAL])
8631a2
+  HAVE_SYS_TIME_H=1;         AC_SUBST([HAVE_SYS_TIME_H])
8631a2
+  REPLACE_GETTIMEOFDAY=0;    AC_SUBST([REPLACE_GETTIMEOFDAY])
8631a2
+  REPLACE_STRUCT_TIMEVAL=0;  AC_SUBST([REPLACE_STRUCT_TIMEVAL])
8631a2
+])
8631a2
diff --git a/m4/time_h.m4 b/m4/time_h.m4
8631a2
new file mode 100644
09e3cc
index 000000000..9852778f9
8631a2
--- /dev/null
8631a2
+++ b/m4/time_h.m4
8631a2
@@ -0,0 +1,118 @@
8631a2
+# Configure a more-standard replacement for <time.h>.
8631a2
+
8631a2
+# Copyright (C) 2000-2001, 2003-2007, 2009-2014 Free Software Foundation, Inc.
8631a2
+
8631a2
+# serial 8
8631a2
+
8631a2
+# This file is free software; the Free Software Foundation
8631a2
+# gives unlimited permission to copy and/or distribute it,
8631a2
+# with or without modifications, as long as this notice is preserved.
8631a2
+
8631a2
+# Written by Paul Eggert and Jim Meyering.
8631a2
+
8631a2
+AC_DEFUN([gl_HEADER_TIME_H],
8631a2
+[
8631a2
+  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
8631a2
+  dnl once only, before all statements that occur in other macros.
8631a2
+  AC_REQUIRE([gl_HEADER_TIME_H_BODY])
8631a2
+])
8631a2
+
8631a2
+AC_DEFUN([gl_HEADER_TIME_H_BODY],
8631a2
+[
8631a2
+  AC_REQUIRE([AC_C_RESTRICT])
8631a2
+  AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
8631a2
+  gl_NEXT_HEADERS([time.h])
8631a2
+  AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
8631a2
+])
8631a2
+
8631a2
+dnl Check whether 'struct timespec' is declared
8631a2
+dnl in time.h, sys/time.h, or pthread.h.
8631a2
+
8631a2
+AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
8631a2
+[
8631a2
+  AC_CHECK_HEADERS_ONCE([sys/time.h])
8631a2
+  AC_CACHE_CHECK([for struct timespec in <time.h>],
8631a2
+    [gl_cv_sys_struct_timespec_in_time_h],
8631a2
+    [AC_COMPILE_IFELSE(
8631a2
+       [AC_LANG_PROGRAM(
8631a2
+          [[#include <time.h>
8631a2
+          ]],
8631a2
+          [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
8631a2
+       [gl_cv_sys_struct_timespec_in_time_h=yes],
8631a2
+       [gl_cv_sys_struct_timespec_in_time_h=no])])
8631a2
+
8631a2
+  TIME_H_DEFINES_STRUCT_TIMESPEC=0
8631a2
+  SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
8631a2
+  PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0
8631a2
+  if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
8631a2
+    TIME_H_DEFINES_STRUCT_TIMESPEC=1
8631a2
+  else
8631a2
+    AC_CACHE_CHECK([for struct timespec in <sys/time.h>],
8631a2
+      [gl_cv_sys_struct_timespec_in_sys_time_h],
8631a2
+      [AC_COMPILE_IFELSE(
8631a2
+         [AC_LANG_PROGRAM(
8631a2
+            [[#include <sys/time.h>
8631a2
+            ]],
8631a2
+            [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
8631a2
+         [gl_cv_sys_struct_timespec_in_sys_time_h=yes],
8631a2
+         [gl_cv_sys_struct_timespec_in_sys_time_h=no])])
8631a2
+    if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then
8631a2
+      SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
8631a2
+    else
8631a2
+      AC_CACHE_CHECK([for struct timespec in <pthread.h>],
8631a2
+        [gl_cv_sys_struct_timespec_in_pthread_h],
8631a2
+        [AC_COMPILE_IFELSE(
8631a2
+           [AC_LANG_PROGRAM(
8631a2
+              [[#include <pthread.h>
8631a2
+              ]],
8631a2
+              [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
8631a2
+           [gl_cv_sys_struct_timespec_in_pthread_h=yes],
8631a2
+           [gl_cv_sys_struct_timespec_in_pthread_h=no])])
8631a2
+      if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then
8631a2
+        PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1
8631a2
+      fi
8631a2
+    fi
8631a2
+  fi
8631a2
+  AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
8631a2
+  AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
8631a2
+  AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC])
8631a2
+])
8631a2
+
8631a2
+AC_DEFUN([gl_TIME_MODULE_INDICATOR],
8631a2
+[
8631a2
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
8631a2
+  AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
8631a2
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
8631a2
+  dnl Define it also as a C macro, for the benefit of the unit tests.
8631a2
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
8631a2
+])
8631a2
+
8631a2
+AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
8631a2
+[
8631a2
+  GNULIB_MKTIME=0;                       AC_SUBST([GNULIB_MKTIME])
8631a2
+  GNULIB_NANOSLEEP=0;                    AC_SUBST([GNULIB_NANOSLEEP])
8631a2
+  GNULIB_STRPTIME=0;                     AC_SUBST([GNULIB_STRPTIME])
8631a2
+  GNULIB_TIMEGM=0;                       AC_SUBST([GNULIB_TIMEGM])
8631a2
+  GNULIB_TIME_R=0;                       AC_SUBST([GNULIB_TIME_R])
8631a2
+  dnl Assume proper GNU behavior unless another module says otherwise.
8631a2
+  HAVE_DECL_LOCALTIME_R=1;               AC_SUBST([HAVE_DECL_LOCALTIME_R])
8631a2
+  HAVE_NANOSLEEP=1;                      AC_SUBST([HAVE_NANOSLEEP])
8631a2
+  HAVE_STRPTIME=1;                       AC_SUBST([HAVE_STRPTIME])
8631a2
+  HAVE_TIMEGM=1;                         AC_SUBST([HAVE_TIMEGM])
8631a2
+  dnl If another module says to replace or to not replace, do that.
8631a2
+  dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
8631a2
+  dnl this lets maintainers check for portability.
8631a2
+  REPLACE_LOCALTIME_R=GNULIB_PORTCHECK;  AC_SUBST([REPLACE_LOCALTIME_R])
8631a2
+  REPLACE_MKTIME=GNULIB_PORTCHECK;       AC_SUBST([REPLACE_MKTIME])
8631a2
+  REPLACE_NANOSLEEP=GNULIB_PORTCHECK;    AC_SUBST([REPLACE_NANOSLEEP])
8631a2
+  REPLACE_TIMEGM=GNULIB_PORTCHECK;       AC_SUBST([REPLACE_TIMEGM])
8631a2
+
8631a2
+  dnl Hack so that the time module doesn't depend on the sys_time module.
8631a2
+  dnl First, default GNULIB_GETTIMEOFDAY to 0 if sys_time is absent.
8631a2
+  : ${GNULIB_GETTIMEOFDAY=0};            AC_SUBST([GNULIB_GETTIMEOFDAY])
8631a2
+  dnl Second, it's OK to not use GNULIB_PORTCHECK for REPLACE_GMTIME
8631a2
+  dnl and REPLACE_LOCALTIME, as portability to Solaris 2.6 and earlier
8631a2
+  dnl is no longer a big deal.
8631a2
+  REPLACE_GMTIME=0;                      AC_SUBST([REPLACE_GMTIME])
8631a2
+  REPLACE_LOCALTIME=0;                   AC_SUBST([REPLACE_LOCALTIME])
8631a2
+])