nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0145-Add-grub_util_readlink.patch

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