This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GNU C Library master sources branch aaribaud/y2038 created. glibc-2.24-400-g8ae1104


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, aaribaud/y2038 has been created
        at  8ae1104e5ea753219cb7d4fd01b6bd1d8cf4a509 (commit)

- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=8ae1104e5ea753219cb7d4fd01b6bd1d8cf4a509

commit 8ae1104e5ea753219cb7d4fd01b6bd1d8cf4a509
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date:   Wed Feb 1 08:43:29 2017 +0100

    Add 64-bit versions for 'broken-up time' APIs
    
    This consists in the following API additions:
    ([file] 32-bit function -> [file] 64-bit variant)
    
    time/ctime.c ctime() -> ctime64()
    time/gmtime.c gmtime() -> gmtime64()
    time/gmtime.c gmtime_r() -> gmtime64_r()
    time/localtime.c localtime() -> localtime64()
    time/localtime.c localtime_r() -> localtime64_r()
    
    which require the following internal additions
    
    time/bits/types/time_t.h time_t -> time64_t
    time/tzset.c __tz_convert() -> time/tzset64.c __tz64_convert()

diff --git a/time/Makefile b/time/Makefile
index 326a81b..6bd7929 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -32,6 +32,7 @@ headers := time.h sys/time.h sys/timeb.h bits/time.h			\
 routines := offtime asctime clock ctime ctime_r difftime \
 	    gmtime localtime mktime time		 \
 	    gettimeofday settimeofday adjtime tzset	 \
+	    tzset64 \
 	    tzfile getitimer setitimer			 \
 	    stime dysize timegm ftime			 \
 	    getdate strptime strptime_l			 \
diff --git a/time/bits/types/time_t.h b/time/bits/types/time_t.h
index 16e5269..906dcf9 100644
--- a/time/bits/types/time_t.h
+++ b/time/bits/types/time_t.h
@@ -11,4 +11,11 @@ __END_NAMESPACE_STD
 __USING_NAMESPACE_STD(time_t)
 #endif
 
+/* Returned by `time64'.  */
+typedef __time64_t time64_t;
+__END_NAMESPACE_STD
+#ifdef __USE_POSIX
+__USING_NAMESPACE_STD(time64_t)
+#endif
+
 #endif
diff --git a/time/ctime.c b/time/ctime.c
index 451d7b9..450ad26 100644
--- a/time/ctime.c
+++ b/time/ctime.c
@@ -26,3 +26,13 @@ ctime (const time_t *t)
      In particular, ctime and asctime must yield the same pointer.  */
   return asctime (localtime (t));
 }
+
+/* Return a string as returned by asctime which
+   is the representation of *T in that form.  */
+char *
+ctime64 (const time64_t *t)
+{
+  /* Apply the same rule as ctime:
+     make ctime64 (t) is equivalent to asctime (localtime64 (t)).  */
+  return asctime (localtime64 (t));
+}
diff --git a/time/gmtime.c b/time/gmtime.c
index b3b5d0d..cc51cf4 100644
--- a/time/gmtime.c
+++ b/time/gmtime.c
@@ -35,3 +35,21 @@ gmtime (const time_t *t)
 {
   return __tz_convert (t, 0, &_tmbuf);
 }
+
+/* Return the `struct tm' representation of 64-bit-time *T
+   in UTC, using *TP to store the result.  */
+struct tm *
+__gmtime64_r (const time64_t *t, struct tm *tp)
+{
+  return __tz_convert64 (t, 0, tp);
+}
+libc_hidden_def (__gmtime64_r)
+weak_alias (__gmtime64_r, gmtime64_r)
+
+
+/* Return the `struct tm' representation of 64-bit-time *T in UTC.	*/
+struct tm *
+gmtime64 (const time64_t *t)
+{
+  return __tz_convert64 (t, 0, &_tmbuf);
+}
diff --git a/time/localtime.c b/time/localtime.c
index 8ec40cf..7b147a1 100644
--- a/time/localtime.c
+++ b/time/localtime.c
@@ -39,3 +39,23 @@ localtime (const time_t *t)
   return __tz_convert (t, 1, &_tmbuf);
 }
 libc_hidden_def (localtime)
+
+/* 64-bit-time versions */
+
+/* Return the `struct tm' representation of *T in local time,
+   using *TP to store the result.  */
+struct tm *
+__localtime64_r (const time64_t *t, struct tm *tp)
+{
+  return __tz64_convert (t, 1, tp);
+}
+weak_alias (__localtime64_r, localtime64_r)
+
+
+/* Return the `struct tm' representation of *T in local time.  */
+struct tm *
+localtime64 (const time64_t *t)
+{
+  return __tz64_convert (t, 1, &_tmbuf);
+}
+libc_hidden_def (localtime64)
diff --git a/time/time.h b/time/time.h
index 860aab7..894b72d 100644
--- a/time/time.h
+++ b/time/time.h
@@ -121,9 +121,17 @@ __BEGIN_NAMESPACE_STD
    in Universal Coordinated Time (aka Greenwich Mean Time).  */
 extern struct tm *gmtime (const time_t *__timer) __THROW;
 
+/* Return the `struct tm' representation of 64-bit-time *TIMER
+   in Universal Coordinated Time (aka Greenwich Mean Time).  */
+extern struct tm *gmtime (const time_t *__timer) __THROW;
+
 /* Return the `struct tm' representation
    of *TIMER in the local timezone.  */
 extern struct tm *localtime (const time_t *__timer) __THROW;
+
+/* Return the `struct tm' representation
+   of the 64-bit-time *TIMER in the local timezone.  */
+extern struct tm *localtime64 (const time64_t *__timer) __THROW;
 __END_NAMESPACE_STD
 
 #ifdef __USE_POSIX
@@ -132,10 +140,20 @@ __END_NAMESPACE_STD
 extern struct tm *gmtime_r (const time_t *__restrict __timer,
 			    struct tm *__restrict __tp) __THROW;
 
+/* Return the `struct tm' representation of 64-bit-time *TIMER
+   in UTC, using *TP to store the result.  */
+extern struct tm *gmtime64_r (const time64_t *__restrict __timer,
+			    struct tm *__restrict __tp) __THROW;
+
 /* Return the `struct tm' representation of *TIMER in local time,
    using *TP to store the result.  */
 extern struct tm *localtime_r (const time_t *__restrict __timer,
 			       struct tm *__restrict __tp) __THROW;
+
+/* Return the `struct tm' representation of the 64-bit-time *TIMER
+   in local time, using *TP to store the result.  */
+extern struct tm *localtime64_r (const time64_t *__restrict __timer,
+			       struct tm *__restrict __tp) __THROW;
 #endif	/* POSIX */
 
 __BEGIN_NAMESPACE_STD
@@ -145,6 +163,9 @@ extern char *asctime (const struct tm *__tp) __THROW;
 
 /* Equivalent to `asctime (localtime (timer))'.  */
 extern char *ctime (const time_t *__timer) __THROW;
+
+/* Equivalent to `asctime (localtime64 (timer))'.  */
+extern char *ctime64 (const time64_t *__timer) __THROW;
 __END_NAMESPACE_STD
 
 #ifdef __USE_POSIX
diff --git a/time/tzset64.c b/time/tzset64.c
new file mode 100644
index 0000000..d43c749
--- /dev/null
+++ b/time/tzset64.c
@@ -0,0 +1,668 @@
+/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <ctype.h>
+#include <errno.h>
+#include <libc-lock.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+
+#define NOID
+#include <timezone/tzfile.h>
+
+char *__tzname[2] = { (char *) "GMT", (char *) "GMT" };
+int __daylight = 0;
+long int __timezone = 0L;
+
+weak_alias (__tzname, tzname)
+weak_alias (__daylight, daylight)
+weak_alias (__timezone, timezone)
+
+/* This locks all the state variables in tzfile.c and this file.  */
+__libc_lock_define_initialized (static, tzset_lock)
+
+
+#define	min(a, b)	((a) < (b) ? (a) : (b))
+#define	max(a, b)	((a) > (b) ? (a) : (b))
+#define	sign(x)		((x) < 0 ? -1 : 1)
+
+
+/* This structure contains all the information about a
+   timezone given in the POSIX standard TZ envariable.  */
+typedef struct
+  {
+    const char *name;
+
+    /* When to change.  */
+    enum { J0, J1, M } type;	/* Interpretation of:  */
+    unsigned short int m, n, d;	/* Month, week, day.  */
+    int secs;			/* Time of day.  */
+
+    long int offset;		/* Seconds east of GMT (west if < 0).  */
+
+    /* We cache the computed time of change for a
+       given year so we don't have to recompute it.  */
+    time64_t change;	/* When to change to this zone.  */
+    int computed_for;	/* Year above is computed for.  */
+  } tz_rule;
+
+/* tz_rules[0] is standard, tz_rules[1] is daylight.  */
+static tz_rule tz_rules[2];
+
+
+static void compute_change (tz_rule *rule, int year) __THROW internal_function;
+static void tzset_internal (int always, int explicit)
+     __THROW internal_function;
+
+/* List of buffers containing time zone strings. */
+struct tzstring_l
+{
+  struct tzstring_l *next;
+  size_t len;  /* strlen(data) - doesn't count terminating NUL! */
+  char data[0];
+};
+
+static struct tzstring_l *tzstring_list;
+
+/* Allocate a permanent home for the first LEN characters of S.  It
+   will never be moved or deallocated, but may share space with other
+   strings.  Don't modify the returned string. */
+static char *
+__tzstring_len (const char *s, size_t len)
+{
+  char *p;
+  struct tzstring_l *t, *u, *new;
+
+  /* Walk the list and look for a match.  If this string is the same
+     as the end of an already-allocated string, it can share space. */
+  for (u = t = tzstring_list; t; u = t, t = t->next)
+    if (len <= t->len)
+      {
+	p = &t->data[t->len - len];
+	if (memcmp (s, p, len) == 0)
+	  return p;
+      }
+
+  /* Not found; allocate a new buffer. */
+  new = malloc (sizeof (struct tzstring_l) + len + 1);
+  if (!new)
+    return NULL;
+
+  new->next = NULL;
+  new->len = len;
+  memcpy (new->data, s, len);
+  new->data[len] = '\0';
+
+  if (u)
+    u->next = new;
+  else
+    tzstring_list = new;
+
+  return new->data;
+}
+
+/* Allocate a permanent home for S.  It will never be moved or
+   deallocated, but may share space with other strings.  Don't modify
+   the returned string. */
+char *
+__tzstring (const char *s)
+{
+  return __tzstring_len (s, strlen (s));
+}
+
+/* Maximum length of a timezone name.  tzset_internal keeps this up to date
+   (never decreasing it) when ! __use_tzfile.
+   tzfile.c keeps it up to date when __use_tzfile.  */
+size_t __tzname_cur_max;
+
+long int
+__tzname_max (void)
+{
+  __libc_lock_lock (tzset_lock);
+
+  tzset_internal (0, 0);
+
+  __libc_lock_unlock (tzset_lock);
+
+  return __tzname_cur_max;
+}
+
+static char *old_tz;
+
+static void
+internal_function
+update_vars (void)
+{
+  __daylight = tz_rules[0].offset != tz_rules[1].offset;
+  __timezone = -tz_rules[0].offset;
+  __tzname[0] = (char *) tz_rules[0].name;
+  __tzname[1] = (char *) tz_rules[1].name;
+
+  /* Keep __tzname_cur_max up to date.  */
+  size_t len0 = strlen (__tzname[0]);
+  size_t len1 = strlen (__tzname[1]);
+  if (len0 > __tzname_cur_max)
+    __tzname_cur_max = len0;
+  if (len1 > __tzname_cur_max)
+    __tzname_cur_max = len1;
+}
+
+
+static unsigned int
+__attribute_noinline__
+compute_offset (unsigned int ss, unsigned int mm, unsigned int hh)
+{
+  return min (ss, 59) + min (mm, 59) * 60 + min (hh, 24) * 60 * 60;
+}
+
+/* Parses the time zone name at *TZP, and writes a pointer to an
+   interned string to tz_rules[WHICHRULE].name.  On success, advances
+   *TZP, and returns true.  Returns false otherwise.  */
+static bool
+parse_tzname (const char **tzp, int whichrule)
+{
+  const char *start = *tzp;
+  const char *p = start;
+  while (('a' <= *p && *p <= 'z')
+	 || ('A' <= *p && *p <= 'Z'))
+      ++p;
+  size_t len = p - start;
+  if (len < 3)
+    {
+      p = *tzp;
+      if (__glibc_unlikely (*p++ != '<'))
+	return false;
+      start = p;
+      while (('a' <= *p && *p <= 'z')
+	     || ('A' <= *p && *p <= 'Z')
+	     || ('0' <= *p && *p <= '9')
+	     || *p == '+' || *p == '-')
+	++p;
+      len = p - start;
+      if (*p++ != '>' || len < 3)
+	return false;
+    }
+
+  const char *name = __tzstring_len (start, len);
+  if (name == NULL)
+    return false;
+  tz_rules[whichrule].name = name;
+
+  *tzp = p;
+  return true;
+}
+
+/* Parses the time zone offset at *TZP, and writes it to
+   tz_rules[WHICHRULE].offset.  Returns true if the parse was
+   successful.  */
+static bool
+parse_offset (const char **tzp, int whichrule)
+{
+  const char *tz = *tzp;
+  if (whichrule == 0
+      && (*tz == '\0' || (*tz != '+' && *tz != '-' && !isdigit (*tz))))
+    return false;
+
+  long sign;
+  if (*tz == '-' || *tz == '+')
+    sign = *tz++ == '-' ? 1L : -1L;
+  else
+    sign = -1L;
+  *tzp = tz;
+
+  unsigned short int hh;
+  unsigned short mm = 0;
+  unsigned short ss = 0;
+  int consumed = 0;
+  if (sscanf (tz, "%hu%n:%hu%n:%hu%n",
+	      &hh, &consumed, &mm, &consumed, &ss, &consumed) > 0)
+    tz_rules[whichrule].offset = sign * compute_offset (ss, mm, hh);
+  else
+    /* Nothing could be parsed. */
+    if (whichrule == 0)
+      {
+	/* Standard time defaults to offset zero.  */
+	tz_rules[0].offset = 0;
+	return false;
+      }
+      else
+	/* DST defaults to one hour later than standard time.  */
+	tz_rules[1].offset = tz_rules[0].offset + (60 * 60);
+  *tzp = tz + consumed;
+  return true;
+}
+
+/* Parses the standard <-> DST rules at *TZP.  Updates
+   tz_rule[WHICHRULE].  On success, advances *TZP and returns true.
+   Otherwise, returns false.  */
+static bool
+parse_rule (const char **tzp, int whichrule)
+{
+  const char *tz = *tzp;
+  tz_rule *tzr = &tz_rules[whichrule];
+
+  /* Ignore comma to support string following the incorrect
+     specification in early POSIX.1 printings.  */
+  tz += *tz == ',';
+
+  /* Get the date of the change.  */
+  if (*tz == 'J' || isdigit (*tz))
+    {
+      char *end;
+      tzr->type = *tz == 'J' ? J1 : J0;
+      if (tzr->type == J1 && !isdigit (*++tz))
+	return false;
+      unsigned long int d = strtoul (tz, &end, 10);
+      if (end == tz || d > 365)
+	return false;
+      if (tzr->type == J1 && d == 0)
+	return false;
+      tzr->d = d;
+      tz = end;
+    }
+  else if (*tz == 'M')
+    {
+      tzr->type = M;
+      int consumed;
+      if (sscanf (tz, "M%hu.%hu.%hu%n",
+		  &tzr->m, &tzr->n, &tzr->d, &consumed) != 3
+	  || tzr->m < 1 || tzr->m > 12
+	  || tzr->n < 1 || tzr->n > 5 || tzr->d > 6)
+	return false;
+      tz += consumed;
+    }
+  else if (*tz == '\0')
+    {
+      /* Daylight time rules in the U.S. are defined in the U.S. Code,
+	 Title 15, Chapter 6, Subchapter IX - Standard Time.  These
+	 dates were established by Congress in the Energy Policy Act
+	 of 2005 [Pub. L. no. 109-58, 119 Stat 594 (2005)].
+	 Below is the equivalent of "M3.2.0,M11.1.0" [/2 not needed
+	 since 2:00AM is the default].  */
+      tzr->type = M;
+      if (tzr == &tz_rules[0])
+	{
+	  tzr->m = 3;
+	  tzr->n = 2;
+	  tzr->d = 0;
+	}
+      else
+	{
+	  tzr->m = 11;
+	  tzr->n = 1;
+	  tzr->d = 0;
+	}
+    }
+  else
+    return false;
+
+  if (*tz != '\0' && *tz != '/' && *tz != ',')
+    return false;
+  else if (*tz == '/')
+    {
+      /* Get the time of day of the change.  */
+      int negative;
+      ++tz;
+      if (*tz == '\0')
+	return false;
+      negative = *tz == '-';
+      tz += negative;
+      /* Default to 2:00 AM.  */
+      unsigned short hh = 2;
+      unsigned short mm = 0;
+      unsigned short ss = 0;
+      int consumed = 0;
+      sscanf (tz, "%hu%n:%hu%n:%hu%n",
+	      &hh, &consumed, &mm, &consumed, &ss, &consumed);;
+      tz += consumed;
+      tzr->secs = (negative ? -1 : 1) * ((hh * 60 * 60) + (mm * 60) + ss);
+    }
+  else
+    /* Default to 2:00 AM.  */
+    tzr->secs = 2 * 60 * 60;
+
+  tzr->computed_for = -1;
+  *tzp = tz;
+  return true;
+}
+
+/* Parse the POSIX TZ-style string.  */
+void
+__tzset_parse_tz (const char *tz)
+{
+  /* Clear out old state and reset to unnamed UTC.  */
+  memset (tz_rules, '\0', sizeof tz_rules);
+  tz_rules[0].name = tz_rules[1].name = "";
+
+  /* Get the standard timezone name.  */
+  if (parse_tzname (&tz, 0) && parse_offset (&tz, 0))
+    {
+      /* Get the DST timezone name (if any).  */
+      if (*tz != '\0')
+	{
+	  if (parse_tzname (&tz, 1))
+	    {
+	      parse_offset (&tz, 1);
+	      if (*tz == '\0' || (tz[0] == ',' && tz[1] == '\0'))
+		{
+		  /* There is no rule.  See if there is a default rule
+		     file.  */
+		  __tzfile_default (tz_rules[0].name, tz_rules[1].name,
+				    tz_rules[0].offset, tz_rules[1].offset);
+		  if (__use_tzfile)
+		    {
+		      free (old_tz);
+		      old_tz = NULL;
+		      return;
+		    }
+		}
+	    }
+	  /* Figure out the standard <-> DST rules.  */
+	  if (parse_rule (&tz, 0))
+	    parse_rule (&tz, 1);
+	}
+      else
+	{
+	  /* There is no DST.  */
+	  tz_rules[1].name = tz_rules[0].name;
+	  tz_rules[1].offset = tz_rules[0].offset;
+	}
+    }
+
+  update_vars ();
+}
+
+/* Interpret the TZ envariable.  */
+static void
+internal_function
+tzset_internal (int always, int explicit)
+{
+  static int is_initialized;
+  const char *tz;
+
+  if (is_initialized && !always)
+    return;
+  is_initialized = 1;
+
+  /* Examine the TZ environment variable.  */
+  tz = getenv ("TZ");
+  if (tz == NULL && !explicit)
+    /* Use the site-wide default.  This is a file name which means we
+       would not see changes to the file if we compare only the file
+       name for change.  We want to notice file changes if tzset() has
+       been called explicitly.  Leave TZ as NULL in this case.  */
+    tz = TZDEFAULT;
+  if (tz && *tz == '\0')
+    /* User specified the empty string; use UTC explicitly.  */
+    tz = "Universal";
+
+  /* A leading colon means "implementation defined syntax".
+     We ignore the colon and always use the same algorithm:
+     try a data file, and if none exists parse the 1003.1 syntax.  */
+  if (tz && *tz == ':')
+    ++tz;
+
+  /* Check whether the value changed since the last run.  */
+  if (old_tz != NULL && tz != NULL && strcmp (tz, old_tz) == 0)
+    /* No change, simply return.  */
+    return;
+
+  if (tz == NULL)
+    /* No user specification; use the site-wide default.  */
+    tz = TZDEFAULT;
+
+  tz_rules[0].name = NULL;
+  tz_rules[1].name = NULL;
+
+  /* Save the value of `tz'.  */
+  free (old_tz);
+  old_tz = tz ? __strdup (tz) : NULL;
+
+  /* Try to read a data file.  */
+  __tzfile_read (tz, 0, NULL);
+  if (__use_tzfile)
+    return;
+
+  /* No data file found.  Default to UTC if nothing specified.  */
+
+  if (tz == NULL || *tz == '\0'
+      || (TZDEFAULT != NULL && strcmp (tz, TZDEFAULT) == 0))
+    {
+      memset (tz_rules, '\0', sizeof tz_rules);
+      tz_rules[0].name = tz_rules[1].name = "UTC";
+      if (J0 != 0)
+	tz_rules[0].type = tz_rules[1].type = J0;
+      tz_rules[0].change = tz_rules[1].change = (time64_t) -1;
+      update_vars ();
+      return;
+    }
+
+  __tzset_parse_tz (tz);
+}
+
+/* Figure out the exact time (as a time64_t) in YEAR
+   when the change described by RULE will occur and
+   put it in RULE->change, saving YEAR in RULE->computed_for.  */
+static void
+internal_function
+compute_change (tz_rule *rule, int year)
+{
+  time64_t t;
+
+  if (year != -1 && rule->computed_for == year)
+    /* Operations on times in 2 BC will be slower.  Oh well.  */
+    return;
+
+  /* First set T to January 1st, 0:00:00 GMT in YEAR.  */
+  if (year > 1970)
+    t = ((year - 1970) * 365
+	 + /* Compute the number of leapdays between 1970 and YEAR
+	      (exclusive).  There is a leapday every 4th year ...  */
+	 + ((year - 1) / 4 - 1970 / 4)
+	 /* ... except every 100th year ... */
+	 - ((year - 1) / 100 - 1970 / 100)
+	 /* ... but still every 400th year.  */
+	 + ((year - 1) / 400 - 1970 / 400)) * SECSPERDAY;
+  else
+    t = 0;
+
+  switch (rule->type)
+    {
+    case J1:
+      /* Jn - Julian day, 1 == January 1, 60 == March 1 even in leap years.
+	 In non-leap years, or if the day number is 59 or less, just
+	 add SECSPERDAY times the day number-1 to the time of
+	 January 1, midnight, to get the day.  */
+      t += (rule->d - 1) * SECSPERDAY;
+      if (rule->d >= 60 && __isleap (year))
+	t += SECSPERDAY;
+      break;
+
+    case J0:
+      /* n - Day of year.
+	 Just add SECSPERDAY times the day number to the time of Jan 1st.  */
+      t += rule->d * SECSPERDAY;
+      break;
+
+    case M:
+      /* Mm.n.d - Nth "Dth day" of month M.  */
+      {
+	unsigned int i;
+	int d, m1, yy0, yy1, yy2, dow;
+	const unsigned short int *myday =
+	  &__mon_yday[__isleap (year)][rule->m];
+
+	/* First add SECSPERDAY for each day in months before M.  */
+	t += myday[-1] * SECSPERDAY;
+
+	/* Use Zeller's Congruence to get day-of-week of first day of month. */
+	m1 = (rule->m + 9) % 12 + 1;
+	yy0 = (rule->m <= 2) ? (year - 1) : year;
+	yy1 = yy0 / 100;
+	yy2 = yy0 % 100;
+	dow = ((26 * m1 - 2) / 10 + 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
+	if (dow < 0)
+	  dow += 7;
+
+	/* DOW is the day-of-week of the first day of the month.  Get the
+	   day-of-month (zero-origin) of the first DOW day of the month.  */
+	d = rule->d - dow;
+	if (d < 0)
+	  d += 7;
+	for (i = 1; i < rule->n; ++i)
+	  {
+	    if (d + 7 >= (int) myday[0] - myday[-1])
+	      break;
+	    d += 7;
+	  }
+
+	/* D is the day-of-month (zero-origin) of the day we want.  */
+	t += d * SECSPERDAY;
+      }
+      break;
+    }
+
+  /* T is now the Epoch-relative time of 0:00:00 GMT on the day we want.
+     Just add the time of day and local offset from GMT, and we're done.  */
+
+  rule->change = t - rule->offset + rule->secs;
+  rule->computed_for = year;
+}
+
+
+/* Figure out the correct timezone for TM and set `__tzname',
+   `__timezone', and `__daylight' accordingly.  */
+void
+internal_function
+__tz_compute (time64_t timer, struct tm *tm, int use_localtime)
+{
+  compute_change (&tz_rules[0], 1900 + tm->tm_year);
+  compute_change (&tz_rules[1], 1900 + tm->tm_year);
+
+  if (use_localtime)
+    {
+      int isdst;
+
+      /* We have to distinguish between northern and southern
+	 hemisphere.  For the latter the daylight saving time
+	 ends in the next year.  */
+      if (__builtin_expect (tz_rules[0].change
+			    > tz_rules[1].change, 0))
+	isdst = (timer < tz_rules[1].change
+		 || timer >= tz_rules[0].change);
+      else
+	isdst = (timer >= tz_rules[0].change
+		 && timer < tz_rules[1].change);
+      tm->tm_isdst = isdst;
+      tm->tm_zone = __tzname[isdst];
+      tm->tm_gmtoff = tz_rules[isdst].offset;
+    }
+}
+
+/* Reinterpret the TZ environment variable and set `tzname'.  */
+#undef tzset
+
+void
+__tzset (void)
+{
+  __libc_lock_lock (tzset_lock);
+
+  tzset_internal (1, 1);
+
+  if (!__use_tzfile)
+    {
+      /* Set `tzname'.  */
+      __tzname[0] = (char *) tz_rules[0].name;
+      __tzname[1] = (char *) tz_rules[1].name;
+    }
+
+  __libc_lock_unlock (tzset_lock);
+}
+weak_alias (__tzset, tzset)
+
+/* Return the `struct tm' representation of *TIMER in the local timezone.
+   Use local time if USE_LOCALTIME is nonzero, UTC otherwise.  */
+struct tm *
+__tz_convert (const time64_t *timer, int use_localtime, struct tm *tp)
+{
+  long int leap_correction;
+  int leap_extra_secs;
+
+  if (timer == NULL)
+    {
+      __set_errno (EINVAL);
+      return NULL;
+    }
+
+  __libc_lock_lock (tzset_lock);
+
+  /* Update internal database according to current TZ setting.
+     POSIX.1 8.3.7.2 says that localtime_r is not required to set tzname.
+     This is a good idea since this allows at least a bit more parallelism.  */
+  tzset_internal (tp == &_tmbuf && use_localtime, 1);
+
+  if (__use_tzfile)
+    __tzfile_compute (*timer, use_localtime, &leap_correction,
+		      &leap_extra_secs, tp);
+  else
+    {
+      if (! __offtime (timer, 0, tp))
+	tp = NULL;
+      else
+	__tz_compute (*timer, tp, use_localtime);
+      leap_correction = 0L;
+      leap_extra_secs = 0;
+    }
+
+  __libc_lock_unlock (tzset_lock);
+
+  if (tp)
+    {
+      if (! use_localtime)
+	{
+	  tp->tm_isdst = 0;
+	  tp->tm_zone = "GMT";
+	  tp->tm_gmtoff = 0L;
+	}
+
+      if (__offtime (timer, tp->tm_gmtoff - leap_correction, tp))
+        tp->tm_sec += leap_extra_secs;
+      else
+	tp = NULL;
+    }
+
+  return tp;
+}
+
+
+libc_freeres_fn (free_mem)
+{
+  while (tzstring_list != NULL)
+    {
+      struct tzstring_l *old = tzstring_list;
+
+      tzstring_list = tzstring_list->next;
+      free (old);
+    }
+  free (old_tz);
+  old_tz = NULL;
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=248b20957b3fd2e6359fb310f482b575e42d8eab

commit 248b20957b3fd2e6359fb310f482b575e42d8eab
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date:   Sun Nov 13 10:40:51 2016 +0100

    Support 64-bit syscalls from 32-bit GLIBC clock_gettime and vice versa

diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c
index 19458ba..35a6f59 100644
--- a/sysdeps/unix/sysv/linux/clock_gettime.c
+++ b/sysdeps/unix/sysv/linux/clock_gettime.c
@@ -29,10 +29,23 @@
 /* The REALTIME and MONOTONIC clock are definitely supported in the
    kernel.  */
 #define SYSDEP_GETTIME \
-  SYSDEP_GETTIME_CPUTIME;						      \
-  case CLOCK_REALTIME:							      \
-  case CLOCK_MONOTONIC:							      \
-    retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp);		      \
+  SYSDEP_GETTIME_CPUTIME;						                      \
+  case CLOCK_REALTIME:							                      \
+  case CLOCK_MONOTONIC:							                      \
+    retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp);        \
+    if (retval == ENOSYS)                                             \
+    {                                                                 \
+      struct timespec64 tp64;                                         \
+      retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, &tp64); \
+      if (retval >= 0)                                                \
+      {                                                               \
+        if (tp64.tv_sec < 0x80000000)                                 \
+        {                                                             \
+          tp->tv_sec = (__time_t) tp64.tv_sec;                        \
+          tp->tv_nsec = (__syscall_slong_t) tp64.tv_nsec;             \
+        }                                                             \
+      }                                                               \
+    }                                                                 \
     break
 
 /* We handled the REALTIME clock here.  */
@@ -40,7 +53,20 @@
 #define HANDLED_CPUTIME	1
 
 #define SYSDEP_GETTIME_CPU(clock_id, tp) \
-  retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \
+  retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp);        \
+  if (retval == ENOSYS)                                             \
+  {                                                                 \
+    struct timespec64 tp64;                                         \
+    retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, &tp64); \
+    if (retval >= 0)                                                \
+    {                                                               \
+      if (tp64.tv_sec < 0x80000000)                                 \
+      {                                                             \
+        tp->tv_sec = (__time_t) tp64.tv_sec;                        \
+        tp->tv_nsec = (__syscall_slong_t) tp64.tv_nsec;             \
+      }                                                             \
+    }                                                               \
+  }                                                                 \
   break
 #define SYSDEP_GETTIME_CPUTIME	/* Default catches them too.  */
 
@@ -49,10 +75,21 @@
 /* The REALTIME and MONOTONIC clock are definitely supported in the
    kernel.  */
 #define SYSDEP_GETTIME64 \
-  SYSDEP_GETTIME64_CPUTIME;						      \
-  case CLOCK_REALTIME:							      \
-  case CLOCK_MONOTONIC:							      \
-    retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);		      \
+  SYSDEP_GETTIME64_CPUTIME;						                    \
+  case CLOCK_REALTIME:							                    \
+  case CLOCK_MONOTONIC:							                    \
+    retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);    \
+    if (retval == ENOSYS)                                           \
+    {                                                               \
+      struct timespec tp32;                                         \
+      retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &tp32); \
+      if (retval >= 0)                                              \
+      {                                                             \
+        tp->tv_sec = tp32.tv_sec;                                   \
+        if (tp->tv_sec < 0) tp->tv_sec += 0x100000000;              \
+        tp->tv_nsec = tp32.tv_nsec;                                 \
+      }                                                             \
+    }                                                               \
     break
 
 /* We handled the REALTIME clock here.  */
@@ -60,7 +97,18 @@
 #define HANDLED_CPUTIME	1
 
 #define SYSDEP_GETTIME64_CPU(clock_id, tp) \
-  retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); \
+  retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);    \
+  if (retval == ENOSYS)                                           \
+  {                                                               \
+    struct timespec tp32;                                         \
+    retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &tp32); \
+    if (retval >= 0)                                              \
+    {                                                             \
+      tp->tv_sec = tp32.tv_sec;                                   \
+      if (tp->tv_sec < 0) tp->tv_sec += 0x100000000;              \
+      tp->tv_nsec = tp32.tv_nsec;                                 \
+    }                                                             \
+  }                                                               \
   break
 #define SYSDEP_GETTIME64_CPUTIME	/* Default catches them too.  */
 

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=fb6d3288edc288884fead5a3c7dbcbf06fc30dfa

commit fb6d3288edc288884fead5a3c7dbcbf06fc30dfa
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date:   Sun Nov 13 10:40:51 2016 +0100

    Fix wrong ifdef SYSDEP_GETTIME in __clock_gettime64

diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c
index f11f663..c7c9ef6 100644
--- a/sysdeps/unix/clock_gettime.c
+++ b/sysdeps/unix/clock_gettime.c
@@ -143,7 +143,7 @@ __clock_gettime64 (clockid_t clock_id, struct timespec64 *tp)
 
   switch (clock_id)
     {
-#ifdef SYSDEP_GETTIME
+#ifdef SYSDEP_GETTIME64
       SYSDEP_GETTIME64;
 #endif
 

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=ee7ed5c855ca8eb1e47c5bc94844cb314d5529ed

commit ee7ed5c855ca8eb1e47c5bc94844cb314d5529ed
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date:   Sun Nov 6 18:36:51 2016 +0100

    WIP: Y2038: support 64-bit clock_gettime and clock_settime

diff --git a/bits/types.h b/bits/types.h
index 01753bd..596f4e5 100644
--- a/bits/types.h
+++ b/bits/types.h
@@ -136,7 +136,8 @@ __STD_TYPE __CLOCK_T_TYPE __clock_t;	/* Type of CPU usage counts.  */
 __STD_TYPE __RLIM_T_TYPE __rlim_t;	/* Type for resource measurement.  */
 __STD_TYPE __RLIM64_T_TYPE __rlim64_t;	/* Type for resource measurement (LFS).  */
 __STD_TYPE __ID_T_TYPE __id_t;		/* General type for IDs.  */
-__STD_TYPE __TIME_T_TYPE __time_t;	/* Seconds since the Epoch.  */
+__STD_TYPE __TIME_T_TYPE __time_t;	/* Seconds since the Epoch, Y2038-unsafe.  */
+__STD_TYPE __TIME64_T_TYPE __time64_t;	/* Seconds since the Epoch, Y2038-safe.  */
 __STD_TYPE __USECONDS_T_TYPE __useconds_t; /* Count of microseconds.  */
 __STD_TYPE __SUSECONDS_T_TYPE __suseconds_t; /* Signed count of microseconds.  */
 
@@ -175,6 +176,8 @@ __STD_TYPE __SSIZE_T_TYPE __ssize_t; /* Type of a byte count, or error.  */
 __STD_TYPE __SYSCALL_SLONG_TYPE __syscall_slong_t;
 /* Unsigned long type used in system calls.  */
 __STD_TYPE __SYSCALL_ULONG_TYPE __syscall_ulong_t;
+/* Signed quad type used in system calls.  */
+__STD_TYPE __SYSCALL_SQUAD_TYPE __syscall_squad_t;
 
 /* These few don't really vary by system, they always correspond
    to one of the other defined types.  */
diff --git a/bits/typesizes.h b/bits/typesizes.h
index ff20601..2dc41b0 100644
--- a/bits/typesizes.h
+++ b/bits/typesizes.h
@@ -48,6 +48,7 @@
 #define	__ID_T_TYPE		__U32_TYPE
 #define __CLOCK_T_TYPE		__SLONGWORD_TYPE
 #define __TIME_T_TYPE		__SLONGWORD_TYPE
+#define __TIME64_T_TYPE		__SQUAD_TYPE
 #define __USECONDS_T_TYPE	__U32_TYPE
 #define __SUSECONDS_T_TYPE	__SLONGWORD_TYPE
 #define __DADDR_T_TYPE		__S32_TYPE
@@ -59,6 +60,7 @@
 #define __SSIZE_T_TYPE		__SWORD_TYPE
 #define __SYSCALL_SLONG_TYPE	__SLONGWORD_TYPE
 #define __SYSCALL_ULONG_TYPE	__ULONGWORD_TYPE
+#define __SYSCALL_SQUAD_TYPE	__SQUAD_TYPE
 #define __CPU_MASK_TYPE 	__ULONGWORD_TYPE
 
 #ifdef __LP64__
diff --git a/include/features.h b/include/features.h
index 650d4c5..d35f7b0 100644
--- a/include/features.h
+++ b/include/features.h
@@ -339,6 +339,10 @@
 # define __USE_FILE_OFFSET64	1
 #endif
 
+#if defined _TIME_BITS && _TIME_BITS == 64
+# define __USE_TIME_BITS64	1
+#endif
+
 #if defined _DEFAULT_SOURCE
 # define __USE_MISC	1
 #endif
diff --git a/include/time.h b/include/time.h
index 684ceb8..2fa0764 100644
--- a/include/time.h
+++ b/include/time.h
@@ -21,7 +21,10 @@ libc_hidden_proto (strptime)
 extern __typeof (clock_getres) __clock_getres;
 extern __typeof (clock_gettime) __clock_gettime;
 libc_hidden_proto (__clock_gettime)
+extern __typeof (clock_gettime64) __clock_gettime64;
+libc_hidden_proto (__clock_gettime64)
 extern __typeof (clock_settime) __clock_settime;
+extern __typeof (clock_settime64) __clock_settime64;
 extern __typeof (clock_nanosleep) __clock_nanosleep;
 extern __typeof (clock_getcpuclockid) __clock_getcpuclockid;
 
diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c
index ffd6426..f11f663 100644
--- a/sysdeps/unix/clock_gettime.c
+++ b/sysdeps/unix/clock_gettime.c
@@ -134,3 +134,51 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp)
 }
 weak_alias (__clock_gettime, clock_gettime)
 libc_hidden_def (__clock_gettime)
+
+/* Get current value of CLOCK and store it in TP, 64-bit version.  */
+int
+__clock_gettime64 (clockid_t clock_id, struct timespec64 *tp)
+{
+  int retval = -1;
+
+  switch (clock_id)
+    {
+#ifdef SYSDEP_GETTIME
+      SYSDEP_GETTIME64;
+#endif
+
+#ifndef HANDLED_REALTIME
+    case CLOCK_REALTIME:
+      {
+	struct timeval tv;
+	retval = gettimeofday (&tv, NULL);
+	if (retval == 0)
+	  TIMEVAL_TO_TIMESPEC (&tv, tp);
+      }
+      break;
+#endif
+
+    default:
+#ifdef SYSDEP_GETTIME64_CPU
+      SYSDEP_GETTIME64_CPU (clock_id, tp);
+#endif
+#if HP_TIMING_AVAIL
+      if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))
+	  == CLOCK_THREAD_CPUTIME_ID)
+	retval = hp_timing_gettime (clock_id, tp);
+      else
+#endif
+	__set_errno (EINVAL);
+      break;
+
+#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
+    case CLOCK_PROCESS_CPUTIME_ID:
+      retval = hp_timing_gettime (clock_id, tp);
+      break;
+#endif
+    }
+
+  return retval;
+}
+weak_alias (__clock_gettime64, clock_gettime64)
+libc_hidden_def (__clock_gettime64)
diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c
index a3fd267..22044e7 100644
--- a/sysdeps/unix/clock_settime.c
+++ b/sysdeps/unix/clock_settime.c
@@ -69,8 +69,77 @@ hp_timing_settime (clockid_t clock_id, const struct timespec *tp)
 }
 #endif
 
+/*
+ * We define the 64- and 32-bit versions of clock_gettime. The client
+ * code determines which one is called:
+ *
+ * - if client code defines ___USE_TIME_BITS64, then GLIBC defines
+ *   _TIME_BITS equal to 64, and the 64-bit version of clock_gettime
+ *   gets declared and used.
+ *
+ * - if client code does not define ___USE_TIME_BITS64, then GLIBC does
+ *   not define _TIME_BITS and the 32-bit version of clock_gettime gets
+ *   declared and used.
+ */
+
+
+/* Set CLOCK to value TP, 64-bit Y2038-safe version.  */
+int
+__clock_settime64 (clockid_t clock_id, const struct timespec64 *tp)
+{
+  int retval;
+
+  /* Make sure the time cvalue is OK.  */
+  if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  switch (clock_id)
+    {
+#define HANDLE_REALTIME \
+      do {								      \
+	struct timeval tv;						      \
+	TIMESPEC_TO_TIMEVAL (&tv, tp);					      \
+									      \
+	retval = settimeofday (&tv, NULL);				      \
+      } while (0)
+
+#ifdef SYSDEP_SETTIME64
+      SYSDEP_SETTIME64;
+#endif
+
+#ifndef HANDLED_REALTIME
+    case CLOCK_REALTIME:
+      HANDLE_REALTIME;
+      break;
+#endif
+
+    default:
+#ifdef SYSDEP_SETTIME64_CPU
+      SYSDEP_SETTIME64_CPU;
+#endif
+#ifndef HANDLED_CPUTIME
+# if HP_TIMING_AVAIL
+      if (CPUCLOCK_WHICH (clock_id) == CLOCK_PROCESS_CPUTIME_ID
+	  || CPUCLOCK_WHICH (clock_id) == CLOCK_THREAD_CPUTIME_ID)
+	retval = hp_timing_settime (clock_id, tp);
+      else
+# endif
+	{
+	  __set_errno (EINVAL);
+	  retval = -1;
+	}
+#endif
+      break;
+    }
+
+  return retval;
+}
+weak_alias (__clock_settime64, clock_settime64)
 
-/* Set CLOCK to value TP.  */
+/* Set CLOCK to value TP, 64-bit Y2038-safe version.  */
 int
 __clock_settime (clockid_t clock_id, const struct timespec *tp)
 {
diff --git a/sysdeps/unix/sysv/linux/arm/Versions b/sysdeps/unix/sysv/linux/arm/Versions
index 7e5ba53..7410904 100644
--- a/sysdeps/unix/sysv/linux/arm/Versions
+++ b/sysdeps/unix/sysv/linux/arm/Versions
@@ -9,11 +9,16 @@ libc {
   }
   GLIBC_2.24 {
     recvmsg; sendmsg;
+    clock_gettime64; clock_settime64;
   }
   GLIBC_PRIVATE {
     # A copy of sigaction lives in libpthread, and needs these.
     __default_sa_restorer; __default_rt_sa_restorer;
     # nptl/pthread_cond_timedwait.c uses INTERNAL_VSYSCALL(clock_gettime).
     __vdso_clock_gettime;
+    # (aaribaud) do we need this?
+    __clock_gettime64;
+    __clock_settime64;
+    __vdso_clock_gettime64;
   }
 }
diff --git a/sysdeps/unix/sysv/linux/arm/init-first.c b/sysdeps/unix/sysv/linux/arm/init-first.c
index 6338200..b99c24b 100644
--- a/sysdeps/unix/sysv/linux/arm/init-first.c
+++ b/sysdeps/unix/sysv/linux/arm/init-first.c
@@ -23,6 +23,7 @@
 
 int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) attribute_hidden;
 int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
+int (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct timespec64 *);
 
 static inline void
 _libc_vdso_platform_setup (void)
@@ -36,6 +37,11 @@ _libc_vdso_platform_setup (void)
   p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux26);
   PTR_MANGLE (p);
   VDSO_SYMBOL (clock_gettime) = p;
+
+  /* (aaribaud) TODO: map to version where clock_gettime64 officially appears */
+  p = _dl_vdso_vsym ("__vdso_clock_gettime64", NULL);
+  PTR_MANGLE (p);
+  VDSO_SYMBOL (clock_gettime64) = p;
 }
 
 # define VDSO_SETUP _libc_vdso_platform_setup
diff --git a/sysdeps/unix/sysv/linux/arm/libc-vdso.h b/sysdeps/unix/sysv/linux/arm/libc-vdso.h
index bf5f012..1c86b90 100644
--- a/sysdeps/unix/sysv/linux/arm/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/arm/libc-vdso.h
@@ -27,6 +27,7 @@
 extern int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *)
    attribute_hidden;
 extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
+extern int (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct timespec64 *);
 
 #endif
 
diff --git a/sysdeps/unix/sysv/linux/arm/libc.abilist b/sysdeps/unix/sysv/linux/arm/libc.abilist
index 8bc979a..9445f8a 100644
--- a/sysdeps/unix/sysv/linux/arm/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/libc.abilist
@@ -90,6 +90,8 @@ GLIBC_2.23 fts64_read F
 GLIBC_2.23 fts64_set F
 GLIBC_2.24 GLIBC_2.24 A
 GLIBC_2.24 quick_exit F
+GLIBC_2.24 clock_gettime64 F
+GLIBC_2.24 clock_settime64 F
 GLIBC_2.25 GLIBC_2.25 A
 GLIBC_2.25 strfromd F
 GLIBC_2.25 strfromf F
diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c
index f6be61b..19458ba 100644
--- a/sysdeps/unix/sysv/linux/clock_gettime.c
+++ b/sysdeps/unix/sysv/linux/clock_gettime.c
@@ -44,4 +44,24 @@
   break
 #define SYSDEP_GETTIME_CPUTIME	/* Default catches them too.  */
 
+/* 64-bit versions */
+
+/* The REALTIME and MONOTONIC clock are definitely supported in the
+   kernel.  */
+#define SYSDEP_GETTIME64 \
+  SYSDEP_GETTIME64_CPUTIME;						      \
+  case CLOCK_REALTIME:							      \
+  case CLOCK_MONOTONIC:							      \
+    retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);		      \
+    break
+
+/* We handled the REALTIME clock here.  */
+#define HANDLED_REALTIME	1
+#define HANDLED_CPUTIME	1
+
+#define SYSDEP_GETTIME64_CPU(clock_id, tp) \
+  retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); \
+  break
+#define SYSDEP_GETTIME64_CPUTIME	/* Default catches them too.  */
+
 #include <sysdeps/unix/clock_gettime.c>
diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c
index bfd3064..01c5989 100644
--- a/sysdeps/unix/sysv/linux/clock_settime.c
+++ b/sysdeps/unix/sysv/linux/clock_settime.c
@@ -23,6 +23,11 @@
 
 
 /* The REALTIME clock is definitely supported in the kernel.  */
+#define SYSDEP_SETTIME64 \
+  case CLOCK_REALTIME:							      \
+    retval = INLINE_SYSCALL (clock_settime64, 2, clock_id, tp);		      \
+    break
+
 #define SYSDEP_SETTIME \
   case CLOCK_REALTIME:							      \
     retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp);		      \
@@ -32,6 +37,9 @@
 #define HANDLED_REALTIME	1
 
 #define HANDLED_CPUTIME 1
+#define SYSDEP_SETTIME64_CPU \
+  retval = INLINE_SYSCALL (clock_settime64, 2, clock_id, tp)
+
 #define SYSDEP_SETTIME_CPU \
   retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp)
 
diff --git a/time/bits/types/struct_timespec.h b/time/bits/types/struct_timespec.h
index 644db9f..dcb0ab5 100644
--- a/time/bits/types/struct_timespec.h
+++ b/time/bits/types/struct_timespec.h
@@ -11,4 +11,11 @@ struct timespec
   __syscall_slong_t tv_nsec;	/* Nanoseconds.  */
 };
 
+/* This one is for holding a Y2038-safe time value.  */
+struct timespec64
+{
+  __time64_t tv_sec;			/* Seconds.  */
+  __syscall_squad_t tv_nsec;	/* Nanoseconds.  */
+};
+
 #endif
diff --git a/time/time.h b/time/time.h
index c38fac7..860aab7 100644
--- a/time/time.h
+++ b/time/time.h
@@ -223,10 +223,19 @@ extern int clock_getres (clockid_t __clock_id, struct timespec *__res) __THROW;
 
 /* Get current value of clock CLOCK_ID and store it in TP.  */
 extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW;
+extern int clock_gettime64 (clockid_t __clock_id, struct timespec64 *__tp) __THROW;
 
 /* Set clock CLOCK_ID to value TP.  */
 extern int clock_settime (clockid_t __clock_id, const struct timespec *__tp)
      __THROW;
+extern int clock_settime64 (clockid_t __clock_id, const struct timespec64 *__tp)
+     __THROW;
+
+#ifdef __USE_TIME_BITS64
+#define timespec timespec64
+#define clock_gettime clock_gettime64
+#define clock_settime clock_settime64
+#endif
 
 # ifdef __USE_XOPEN2K
 /* High-resolution sleep with the specified clock.

-----------------------------------------------------------------------


hooks/post-receive
-- 
GNU C Library master sources


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]