public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/azanella/y2038] time: Add 64 bit time support for getdate
@ 2021-06-08 20:49 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-06-08 20:49 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=347cbc78bf952b8787caa43149c5896e5d23c987
commit 347cbc78bf952b8787caa43149c5896e5d23c987
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Tue Mar 2 09:02:02 2021 -0300
time: Add 64 bit time support for getdate
The getdate is basically a wrapper localtime and mktime. The 64 bit
time support is done calling the 64 bit internal functions, there is
no need to add a new symbol version.
Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
Diff:
---
include/sys/stat.h | 2 +-
include/time.h | 12 ++++++++++--
time/getdate.c | 22 ++++++++++------------
time/tst-getdate.c | 14 ++++----------
4 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/include/sys/stat.h b/include/sys/stat.h
index b4c9344628..13e777b3c7 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -46,7 +46,7 @@ hidden_proto (__lstat64)
hidden_proto (__fstatat64)
# endif
-# if __TIMESIZE == 64
+# if __TIMESIZE == 64 || defined NO_RTLD_HIDDEN
# define __stat64_time64 __stat64
# define __fstat64_time64 __fstat64
# define __lstat64_time64 __lstat64
diff --git a/include/time.h b/include/time.h
index 4372bfbd96..980c6bd924 100644
--- a/include/time.h
+++ b/include/time.h
@@ -283,8 +283,8 @@ hidden_proto (__nanosleep64)
#endif
-extern int __getdate_r (const char *__string, struct tm *__resbufp)
- attribute_hidden;
+extern int __getdate_r (const char *__string, struct tm *__resbufp);
+libc_hidden_proto (__getdate_r);
/* Determine CLK_TCK value. */
@@ -509,6 +509,14 @@ time_now (void)
return ts.tv_sec;
}
+static inline __time64_t
+time64_now (void)
+{
+ struct __timespec64 ts;
+ __clock_gettime64 (TIME_CLOCK_GETTIME_CLOCKID, &ts);
+ return ts.tv_sec;
+}
+
#define NSEC_PER_SEC 1000000000L /* Nanoseconds per second. */
#define USEC_PER_SEC 1000000L /* Microseconds per second. */
#define NSEC_PER_USEC 1000L /* Nanoseconds per microsecond. */
diff --git a/time/getdate.c b/time/getdate.c
index 6e2f75566b..cdcc898517 100644
--- a/time/getdate.c
+++ b/time/getdate.c
@@ -112,16 +112,16 @@ __getdate_r (const char *string, struct tm *tp)
size_t len;
char *datemsk;
char *result = NULL;
- time_t timer;
+ __time64_t timer;
struct tm tm;
- struct stat64 st;
- int mday_ok = 0;
+ struct __stat64_t64 st;
+ bool mday_ok = false;
datemsk = getenv ("DATEMSK");
if (datemsk == NULL || *datemsk == '\0')
return 1;
- if (__stat64 (datemsk, &st) < 0)
+ if (__stat64_time64 (datemsk, &st) < 0)
return 3;
if (!S_ISREG (st.st_mode))
@@ -219,8 +219,8 @@ __getdate_r (const char *string, struct tm *tp)
return 7;
/* Get current time. */
- timer = time_now ();
- __localtime_r (&timer, &tm);
+ timer = time64_now ();
+ __localtime64_r (&timer, &tm);
/* If only the weekday is given, today is assumed if the given day
is equal to the current day and next week if it is less. */
@@ -230,7 +230,7 @@ __getdate_r (const char *string, struct tm *tp)
tp->tm_year = tm.tm_year;
tp->tm_mon = tm.tm_mon;
tp->tm_mday = tm.tm_mday + (tp->tm_wday - tm.tm_wday + 7) % 7;
- mday_ok = 1;
+ mday_ok = true;
}
/* If only the month is given, the current month is assumed if the
@@ -242,7 +242,7 @@ __getdate_r (const char *string, struct tm *tp)
if (tp->tm_year == INT_MIN)
tp->tm_year = tm.tm_year + (((tp->tm_mon - tm.tm_mon) < 0) ? 1 : 0);
tp->tm_mday = first_wday (tp->tm_year, tp->tm_mon, tp->tm_wday);
- mday_ok = 1;
+ mday_ok = true;
}
/* If no hour, minute and second are given the current hour, minute
@@ -285,15 +285,13 @@ __getdate_r (const char *string, struct tm *tp)
call normalizes the struct tm. */
if ((!mday_ok && !check_mday (TM_YEAR_BASE + tp->tm_year, tp->tm_mon,
tp->tm_mday))
- || mktime (tp) == (time_t) -1)
+ || __mktime64 (tp) == (time_t) -1)
return 8;
return 0;
}
-#ifdef weak_alias
weak_alias (__getdate_r, getdate_r)
-#endif
-
+libc_hidden_def (__getdate_r)
struct tm *
getdate (const char *string)
diff --git a/time/tst-getdate.c b/time/tst-getdate.c
index c37ba3083a..3bb0e96707 100644
--- a/time/tst-getdate.c
+++ b/time/tst-getdate.c
@@ -115,20 +115,14 @@ do_test (void)
{
setenv ("TZ", tests[i].tz, 1);
- int expected_err;
- if (sizeof (time_t) == 4 && tests[i].time64)
- expected_err = 8;
- else
- expected_err = 0;
-
tm = getdate (tests[i].str);
- TEST_COMPARE (getdate_err, expected_err);
- if (getdate_err != expected_err)
+ TEST_COMPARE (getdate_err, 0);
+ if (getdate_err != 0)
{
support_record_failure ();
printf ("%s\n", report_date_error ());
}
- else if (getdate_err == 0)
+ else
{
TEST_COMPARE (tests[i].tm.tm_mon, tm->tm_mon);
TEST_COMPARE (tests[i].tm.tm_year, tm->tm_year);
@@ -139,7 +133,7 @@ do_test (void)
}
struct tm tms;
- TEST_COMPARE (getdate_r (tests[i].str, &tms), expected_err);
+ TEST_COMPARE (getdate_r (tests[i].str, &tms), 0);
if (getdate_err == 0)
{
TEST_COMPARE (tests[i].tm.tm_mon, tms.tm_mon);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/azanella/y2038] time: Add 64 bit time support for getdate
@ 2021-05-26 16:25 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-05-26 16:25 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=77d6a6d1936c1c5dce45653e1400c4ac66e4cb2e
commit 77d6a6d1936c1c5dce45653e1400c4ac66e4cb2e
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Tue Mar 2 09:02:02 2021 -0300
time: Add 64 bit time support for getdate
The getdate is basically a wrapper localtime and mktime. The 64 bit
time support is done calling the 64 bit internal functions, there is
no need to add a new symbol version.
Checked on x86_64-linux-gnu and i686-linux-gnu.
Diff:
---
include/sys/stat.h | 2 +-
include/time.h | 12 ++++++++++--
time/getdate.c | 22 ++++++++++------------
time/tst-getdate.c | 14 ++++----------
4 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/include/sys/stat.h b/include/sys/stat.h
index b4c9344628..13e777b3c7 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -46,7 +46,7 @@ hidden_proto (__lstat64)
hidden_proto (__fstatat64)
# endif
-# if __TIMESIZE == 64
+# if __TIMESIZE == 64 || defined NO_RTLD_HIDDEN
# define __stat64_time64 __stat64
# define __fstat64_time64 __fstat64
# define __lstat64_time64 __lstat64
diff --git a/include/time.h b/include/time.h
index 4372bfbd96..980c6bd924 100644
--- a/include/time.h
+++ b/include/time.h
@@ -283,8 +283,8 @@ hidden_proto (__nanosleep64)
#endif
-extern int __getdate_r (const char *__string, struct tm *__resbufp)
- attribute_hidden;
+extern int __getdate_r (const char *__string, struct tm *__resbufp);
+libc_hidden_proto (__getdate_r);
/* Determine CLK_TCK value. */
@@ -509,6 +509,14 @@ time_now (void)
return ts.tv_sec;
}
+static inline __time64_t
+time64_now (void)
+{
+ struct __timespec64 ts;
+ __clock_gettime64 (TIME_CLOCK_GETTIME_CLOCKID, &ts);
+ return ts.tv_sec;
+}
+
#define NSEC_PER_SEC 1000000000L /* Nanoseconds per second. */
#define USEC_PER_SEC 1000000L /* Microseconds per second. */
#define NSEC_PER_USEC 1000L /* Nanoseconds per microsecond. */
diff --git a/time/getdate.c b/time/getdate.c
index 6e2f75566b..cdcc898517 100644
--- a/time/getdate.c
+++ b/time/getdate.c
@@ -112,16 +112,16 @@ __getdate_r (const char *string, struct tm *tp)
size_t len;
char *datemsk;
char *result = NULL;
- time_t timer;
+ __time64_t timer;
struct tm tm;
- struct stat64 st;
- int mday_ok = 0;
+ struct __stat64_t64 st;
+ bool mday_ok = false;
datemsk = getenv ("DATEMSK");
if (datemsk == NULL || *datemsk == '\0')
return 1;
- if (__stat64 (datemsk, &st) < 0)
+ if (__stat64_time64 (datemsk, &st) < 0)
return 3;
if (!S_ISREG (st.st_mode))
@@ -219,8 +219,8 @@ __getdate_r (const char *string, struct tm *tp)
return 7;
/* Get current time. */
- timer = time_now ();
- __localtime_r (&timer, &tm);
+ timer = time64_now ();
+ __localtime64_r (&timer, &tm);
/* If only the weekday is given, today is assumed if the given day
is equal to the current day and next week if it is less. */
@@ -230,7 +230,7 @@ __getdate_r (const char *string, struct tm *tp)
tp->tm_year = tm.tm_year;
tp->tm_mon = tm.tm_mon;
tp->tm_mday = tm.tm_mday + (tp->tm_wday - tm.tm_wday + 7) % 7;
- mday_ok = 1;
+ mday_ok = true;
}
/* If only the month is given, the current month is assumed if the
@@ -242,7 +242,7 @@ __getdate_r (const char *string, struct tm *tp)
if (tp->tm_year == INT_MIN)
tp->tm_year = tm.tm_year + (((tp->tm_mon - tm.tm_mon) < 0) ? 1 : 0);
tp->tm_mday = first_wday (tp->tm_year, tp->tm_mon, tp->tm_wday);
- mday_ok = 1;
+ mday_ok = true;
}
/* If no hour, minute and second are given the current hour, minute
@@ -285,15 +285,13 @@ __getdate_r (const char *string, struct tm *tp)
call normalizes the struct tm. */
if ((!mday_ok && !check_mday (TM_YEAR_BASE + tp->tm_year, tp->tm_mon,
tp->tm_mday))
- || mktime (tp) == (time_t) -1)
+ || __mktime64 (tp) == (time_t) -1)
return 8;
return 0;
}
-#ifdef weak_alias
weak_alias (__getdate_r, getdate_r)
-#endif
-
+libc_hidden_def (__getdate_r)
struct tm *
getdate (const char *string)
diff --git a/time/tst-getdate.c b/time/tst-getdate.c
index c37ba3083a..3bb0e96707 100644
--- a/time/tst-getdate.c
+++ b/time/tst-getdate.c
@@ -115,20 +115,14 @@ do_test (void)
{
setenv ("TZ", tests[i].tz, 1);
- int expected_err;
- if (sizeof (time_t) == 4 && tests[i].time64)
- expected_err = 8;
- else
- expected_err = 0;
-
tm = getdate (tests[i].str);
- TEST_COMPARE (getdate_err, expected_err);
- if (getdate_err != expected_err)
+ TEST_COMPARE (getdate_err, 0);
+ if (getdate_err != 0)
{
support_record_failure ();
printf ("%s\n", report_date_error ());
}
- else if (getdate_err == 0)
+ else
{
TEST_COMPARE (tests[i].tm.tm_mon, tm->tm_mon);
TEST_COMPARE (tests[i].tm.tm_year, tm->tm_year);
@@ -139,7 +133,7 @@ do_test (void)
}
struct tm tms;
- TEST_COMPARE (getdate_r (tests[i].str, &tms), expected_err);
+ TEST_COMPARE (getdate_r (tests[i].str, &tms), 0);
if (getdate_err == 0)
{
TEST_COMPARE (tests[i].tm.tm_mon, tms.tm_mon);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/azanella/y2038] time: Add 64 bit time support for getdate
@ 2021-03-05 19:21 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-03-05 19:21 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d4371f6c7bc0aee7eb4e0dcdaa46b044f32386b0
commit d4371f6c7bc0aee7eb4e0dcdaa46b044f32386b0
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Tue Mar 2 09:02:02 2021 -0300
time: Add 64 bit time support for getdate
The getdate is basically a wrapper localtime and mktime. The 64 bit
time support is done calling the 64 bit internal functions, there is
no need to add a new symbol version.
Checked on x86_64-linux-gnu and i686-linux-gnu.
Diff:
---
include/time.h | 12 ++++++++++--
time/getdate.c | 22 ++++++++++------------
time/tst-getdate.c | 14 ++++----------
3 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/include/time.h b/include/time.h
index caf2af5e74..36754695c9 100644
--- a/include/time.h
+++ b/include/time.h
@@ -280,8 +280,8 @@ hidden_proto (__nanosleep64)
#endif
-extern int __getdate_r (const char *__string, struct tm *__resbufp)
- attribute_hidden;
+extern int __getdate_r (const char *__string, struct tm *__resbufp);
+libc_hidden_proto (__getdate_r);
/* Determine CLK_TCK value. */
@@ -502,6 +502,14 @@ time_now (void)
__clock_gettime (TIME_CLOCK_GETTIME_CLOCKID, &ts);
return ts.tv_sec;
}
+
+static inline __time64_t
+time64_now (void)
+{
+ struct __timespec64 ts;
+ __clock_gettime64 (TIME_CLOCK_GETTIME_CLOCKID, &ts);
+ return ts.tv_sec;
+}
#endif
#endif
diff --git a/time/getdate.c b/time/getdate.c
index 6e2f75566b..cdcc898517 100644
--- a/time/getdate.c
+++ b/time/getdate.c
@@ -112,16 +112,16 @@ __getdate_r (const char *string, struct tm *tp)
size_t len;
char *datemsk;
char *result = NULL;
- time_t timer;
+ __time64_t timer;
struct tm tm;
- struct stat64 st;
- int mday_ok = 0;
+ struct __stat64_t64 st;
+ bool mday_ok = false;
datemsk = getenv ("DATEMSK");
if (datemsk == NULL || *datemsk == '\0')
return 1;
- if (__stat64 (datemsk, &st) < 0)
+ if (__stat64_time64 (datemsk, &st) < 0)
return 3;
if (!S_ISREG (st.st_mode))
@@ -219,8 +219,8 @@ __getdate_r (const char *string, struct tm *tp)
return 7;
/* Get current time. */
- timer = time_now ();
- __localtime_r (&timer, &tm);
+ timer = time64_now ();
+ __localtime64_r (&timer, &tm);
/* If only the weekday is given, today is assumed if the given day
is equal to the current day and next week if it is less. */
@@ -230,7 +230,7 @@ __getdate_r (const char *string, struct tm *tp)
tp->tm_year = tm.tm_year;
tp->tm_mon = tm.tm_mon;
tp->tm_mday = tm.tm_mday + (tp->tm_wday - tm.tm_wday + 7) % 7;
- mday_ok = 1;
+ mday_ok = true;
}
/* If only the month is given, the current month is assumed if the
@@ -242,7 +242,7 @@ __getdate_r (const char *string, struct tm *tp)
if (tp->tm_year == INT_MIN)
tp->tm_year = tm.tm_year + (((tp->tm_mon - tm.tm_mon) < 0) ? 1 : 0);
tp->tm_mday = first_wday (tp->tm_year, tp->tm_mon, tp->tm_wday);
- mday_ok = 1;
+ mday_ok = true;
}
/* If no hour, minute and second are given the current hour, minute
@@ -285,15 +285,13 @@ __getdate_r (const char *string, struct tm *tp)
call normalizes the struct tm. */
if ((!mday_ok && !check_mday (TM_YEAR_BASE + tp->tm_year, tp->tm_mon,
tp->tm_mday))
- || mktime (tp) == (time_t) -1)
+ || __mktime64 (tp) == (time_t) -1)
return 8;
return 0;
}
-#ifdef weak_alias
weak_alias (__getdate_r, getdate_r)
-#endif
-
+libc_hidden_def (__getdate_r)
struct tm *
getdate (const char *string)
diff --git a/time/tst-getdate.c b/time/tst-getdate.c
index c37ba3083a..3bb0e96707 100644
--- a/time/tst-getdate.c
+++ b/time/tst-getdate.c
@@ -115,20 +115,14 @@ do_test (void)
{
setenv ("TZ", tests[i].tz, 1);
- int expected_err;
- if (sizeof (time_t) == 4 && tests[i].time64)
- expected_err = 8;
- else
- expected_err = 0;
-
tm = getdate (tests[i].str);
- TEST_COMPARE (getdate_err, expected_err);
- if (getdate_err != expected_err)
+ TEST_COMPARE (getdate_err, 0);
+ if (getdate_err != 0)
{
support_record_failure ();
printf ("%s\n", report_date_error ());
}
- else if (getdate_err == 0)
+ else
{
TEST_COMPARE (tests[i].tm.tm_mon, tm->tm_mon);
TEST_COMPARE (tests[i].tm.tm_year, tm->tm_year);
@@ -139,7 +133,7 @@ do_test (void)
}
struct tm tms;
- TEST_COMPARE (getdate_r (tests[i].str, &tms), expected_err);
+ TEST_COMPARE (getdate_r (tests[i].str, &tms), 0);
if (getdate_err == 0)
{
TEST_COMPARE (tests[i].tm.tm_mon, tms.tm_mon);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/azanella/y2038] time: Add 64 bit time support for getdate
@ 2021-03-04 17:39 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-03-04 17:39 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=90b6d3b1fbe6d52932ad1fa092a7fd99b9822beb
commit 90b6d3b1fbe6d52932ad1fa092a7fd99b9822beb
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Tue Mar 2 09:02:02 2021 -0300
time: Add 64 bit time support for getdate
The getdate is basically a wrapper localtime and mktime. The 64 bit
time support is done calling the 64 bit internal functions, there is
no need to add a new symbol version.
Checked on x86_64-linux-gnu and i686-linux-gnu.
Diff:
---
include/time.h | 12 ++++++++++--
time/getdate.c | 22 ++++++++++------------
time/tst-getdate.c | 14 ++++----------
3 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/include/time.h b/include/time.h
index caf2af5e74..36754695c9 100644
--- a/include/time.h
+++ b/include/time.h
@@ -280,8 +280,8 @@ hidden_proto (__nanosleep64)
#endif
-extern int __getdate_r (const char *__string, struct tm *__resbufp)
- attribute_hidden;
+extern int __getdate_r (const char *__string, struct tm *__resbufp);
+libc_hidden_proto (__getdate_r);
/* Determine CLK_TCK value. */
@@ -502,6 +502,14 @@ time_now (void)
__clock_gettime (TIME_CLOCK_GETTIME_CLOCKID, &ts);
return ts.tv_sec;
}
+
+static inline __time64_t
+time64_now (void)
+{
+ struct __timespec64 ts;
+ __clock_gettime64 (TIME_CLOCK_GETTIME_CLOCKID, &ts);
+ return ts.tv_sec;
+}
#endif
#endif
diff --git a/time/getdate.c b/time/getdate.c
index 6e2f75566b..cdcc898517 100644
--- a/time/getdate.c
+++ b/time/getdate.c
@@ -112,16 +112,16 @@ __getdate_r (const char *string, struct tm *tp)
size_t len;
char *datemsk;
char *result = NULL;
- time_t timer;
+ __time64_t timer;
struct tm tm;
- struct stat64 st;
- int mday_ok = 0;
+ struct __stat64_t64 st;
+ bool mday_ok = false;
datemsk = getenv ("DATEMSK");
if (datemsk == NULL || *datemsk == '\0')
return 1;
- if (__stat64 (datemsk, &st) < 0)
+ if (__stat64_time64 (datemsk, &st) < 0)
return 3;
if (!S_ISREG (st.st_mode))
@@ -219,8 +219,8 @@ __getdate_r (const char *string, struct tm *tp)
return 7;
/* Get current time. */
- timer = time_now ();
- __localtime_r (&timer, &tm);
+ timer = time64_now ();
+ __localtime64_r (&timer, &tm);
/* If only the weekday is given, today is assumed if the given day
is equal to the current day and next week if it is less. */
@@ -230,7 +230,7 @@ __getdate_r (const char *string, struct tm *tp)
tp->tm_year = tm.tm_year;
tp->tm_mon = tm.tm_mon;
tp->tm_mday = tm.tm_mday + (tp->tm_wday - tm.tm_wday + 7) % 7;
- mday_ok = 1;
+ mday_ok = true;
}
/* If only the month is given, the current month is assumed if the
@@ -242,7 +242,7 @@ __getdate_r (const char *string, struct tm *tp)
if (tp->tm_year == INT_MIN)
tp->tm_year = tm.tm_year + (((tp->tm_mon - tm.tm_mon) < 0) ? 1 : 0);
tp->tm_mday = first_wday (tp->tm_year, tp->tm_mon, tp->tm_wday);
- mday_ok = 1;
+ mday_ok = true;
}
/* If no hour, minute and second are given the current hour, minute
@@ -285,15 +285,13 @@ __getdate_r (const char *string, struct tm *tp)
call normalizes the struct tm. */
if ((!mday_ok && !check_mday (TM_YEAR_BASE + tp->tm_year, tp->tm_mon,
tp->tm_mday))
- || mktime (tp) == (time_t) -1)
+ || __mktime64 (tp) == (time_t) -1)
return 8;
return 0;
}
-#ifdef weak_alias
weak_alias (__getdate_r, getdate_r)
-#endif
-
+libc_hidden_def (__getdate_r)
struct tm *
getdate (const char *string)
diff --git a/time/tst-getdate.c b/time/tst-getdate.c
index c37ba3083a..3bb0e96707 100644
--- a/time/tst-getdate.c
+++ b/time/tst-getdate.c
@@ -115,20 +115,14 @@ do_test (void)
{
setenv ("TZ", tests[i].tz, 1);
- int expected_err;
- if (sizeof (time_t) == 4 && tests[i].time64)
- expected_err = 8;
- else
- expected_err = 0;
-
tm = getdate (tests[i].str);
- TEST_COMPARE (getdate_err, expected_err);
- if (getdate_err != expected_err)
+ TEST_COMPARE (getdate_err, 0);
+ if (getdate_err != 0)
{
support_record_failure ();
printf ("%s\n", report_date_error ());
}
- else if (getdate_err == 0)
+ else
{
TEST_COMPARE (tests[i].tm.tm_mon, tm->tm_mon);
TEST_COMPARE (tests[i].tm.tm_year, tm->tm_year);
@@ -139,7 +133,7 @@ do_test (void)
}
struct tm tms;
- TEST_COMPARE (getdate_r (tests[i].str, &tms), expected_err);
+ TEST_COMPARE (getdate_r (tests[i].str, &tms), 0);
if (getdate_err == 0)
{
TEST_COMPARE (tests[i].tm.tm_mon, tms.tm_mon);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/azanella/y2038] time: Add 64 bit time support for getdate
@ 2021-03-04 11:32 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-03-04 11:32 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=90b6d3b1fbe6d52932ad1fa092a7fd99b9822beb
commit 90b6d3b1fbe6d52932ad1fa092a7fd99b9822beb
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Tue Mar 2 09:02:02 2021 -0300
time: Add 64 bit time support for getdate
The getdate is basically a wrapper localtime and mktime. The 64 bit
time support is done calling the 64 bit internal functions, there is
no need to add a new symbol version.
Checked on x86_64-linux-gnu and i686-linux-gnu.
Diff:
---
include/time.h | 12 ++++++++++--
time/getdate.c | 22 ++++++++++------------
time/tst-getdate.c | 14 ++++----------
3 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/include/time.h b/include/time.h
index caf2af5e74..36754695c9 100644
--- a/include/time.h
+++ b/include/time.h
@@ -280,8 +280,8 @@ hidden_proto (__nanosleep64)
#endif
-extern int __getdate_r (const char *__string, struct tm *__resbufp)
- attribute_hidden;
+extern int __getdate_r (const char *__string, struct tm *__resbufp);
+libc_hidden_proto (__getdate_r);
/* Determine CLK_TCK value. */
@@ -502,6 +502,14 @@ time_now (void)
__clock_gettime (TIME_CLOCK_GETTIME_CLOCKID, &ts);
return ts.tv_sec;
}
+
+static inline __time64_t
+time64_now (void)
+{
+ struct __timespec64 ts;
+ __clock_gettime64 (TIME_CLOCK_GETTIME_CLOCKID, &ts);
+ return ts.tv_sec;
+}
#endif
#endif
diff --git a/time/getdate.c b/time/getdate.c
index 6e2f75566b..cdcc898517 100644
--- a/time/getdate.c
+++ b/time/getdate.c
@@ -112,16 +112,16 @@ __getdate_r (const char *string, struct tm *tp)
size_t len;
char *datemsk;
char *result = NULL;
- time_t timer;
+ __time64_t timer;
struct tm tm;
- struct stat64 st;
- int mday_ok = 0;
+ struct __stat64_t64 st;
+ bool mday_ok = false;
datemsk = getenv ("DATEMSK");
if (datemsk == NULL || *datemsk == '\0')
return 1;
- if (__stat64 (datemsk, &st) < 0)
+ if (__stat64_time64 (datemsk, &st) < 0)
return 3;
if (!S_ISREG (st.st_mode))
@@ -219,8 +219,8 @@ __getdate_r (const char *string, struct tm *tp)
return 7;
/* Get current time. */
- timer = time_now ();
- __localtime_r (&timer, &tm);
+ timer = time64_now ();
+ __localtime64_r (&timer, &tm);
/* If only the weekday is given, today is assumed if the given day
is equal to the current day and next week if it is less. */
@@ -230,7 +230,7 @@ __getdate_r (const char *string, struct tm *tp)
tp->tm_year = tm.tm_year;
tp->tm_mon = tm.tm_mon;
tp->tm_mday = tm.tm_mday + (tp->tm_wday - tm.tm_wday + 7) % 7;
- mday_ok = 1;
+ mday_ok = true;
}
/* If only the month is given, the current month is assumed if the
@@ -242,7 +242,7 @@ __getdate_r (const char *string, struct tm *tp)
if (tp->tm_year == INT_MIN)
tp->tm_year = tm.tm_year + (((tp->tm_mon - tm.tm_mon) < 0) ? 1 : 0);
tp->tm_mday = first_wday (tp->tm_year, tp->tm_mon, tp->tm_wday);
- mday_ok = 1;
+ mday_ok = true;
}
/* If no hour, minute and second are given the current hour, minute
@@ -285,15 +285,13 @@ __getdate_r (const char *string, struct tm *tp)
call normalizes the struct tm. */
if ((!mday_ok && !check_mday (TM_YEAR_BASE + tp->tm_year, tp->tm_mon,
tp->tm_mday))
- || mktime (tp) == (time_t) -1)
+ || __mktime64 (tp) == (time_t) -1)
return 8;
return 0;
}
-#ifdef weak_alias
weak_alias (__getdate_r, getdate_r)
-#endif
-
+libc_hidden_def (__getdate_r)
struct tm *
getdate (const char *string)
diff --git a/time/tst-getdate.c b/time/tst-getdate.c
index c37ba3083a..3bb0e96707 100644
--- a/time/tst-getdate.c
+++ b/time/tst-getdate.c
@@ -115,20 +115,14 @@ do_test (void)
{
setenv ("TZ", tests[i].tz, 1);
- int expected_err;
- if (sizeof (time_t) == 4 && tests[i].time64)
- expected_err = 8;
- else
- expected_err = 0;
-
tm = getdate (tests[i].str);
- TEST_COMPARE (getdate_err, expected_err);
- if (getdate_err != expected_err)
+ TEST_COMPARE (getdate_err, 0);
+ if (getdate_err != 0)
{
support_record_failure ();
printf ("%s\n", report_date_error ());
}
- else if (getdate_err == 0)
+ else
{
TEST_COMPARE (tests[i].tm.tm_mon, tm->tm_mon);
TEST_COMPARE (tests[i].tm.tm_year, tm->tm_year);
@@ -139,7 +133,7 @@ do_test (void)
}
struct tm tms;
- TEST_COMPARE (getdate_r (tests[i].str, &tms), expected_err);
+ TEST_COMPARE (getdate_r (tests[i].str, &tms), 0);
if (getdate_err == 0)
{
TEST_COMPARE (tests[i].tm.tm_mon, tms.tm_mon);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/azanella/y2038] time: Add 64 bit time support for getdate
@ 2021-03-02 12:34 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-03-02 12:34 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a00009a7470970e32f88287fdee7e97667999240
commit a00009a7470970e32f88287fdee7e97667999240
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Tue Mar 2 09:02:02 2021 -0300
time: Add 64 bit time support for getdate
The getdate is basically a wrapper localtime and mktime. The 64 bit
time support is done calling the 64 bit internal functions, there is
no need to add a new symbol version.
Checked on x86_64-linux-gnu and i686-linux-gnu.
Diff:
---
include/time.h | 12 ++++++++++--
time/getdate.c | 22 ++++++++++------------
time/tst-getdate.c | 14 ++++----------
3 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/include/time.h b/include/time.h
index caf2af5e74..36754695c9 100644
--- a/include/time.h
+++ b/include/time.h
@@ -280,8 +280,8 @@ hidden_proto (__nanosleep64)
#endif
-extern int __getdate_r (const char *__string, struct tm *__resbufp)
- attribute_hidden;
+extern int __getdate_r (const char *__string, struct tm *__resbufp);
+libc_hidden_proto (__getdate_r);
/* Determine CLK_TCK value. */
@@ -502,6 +502,14 @@ time_now (void)
__clock_gettime (TIME_CLOCK_GETTIME_CLOCKID, &ts);
return ts.tv_sec;
}
+
+static inline __time64_t
+time64_now (void)
+{
+ struct __timespec64 ts;
+ __clock_gettime64 (TIME_CLOCK_GETTIME_CLOCKID, &ts);
+ return ts.tv_sec;
+}
#endif
#endif
diff --git a/time/getdate.c b/time/getdate.c
index 6e2f75566b..cdcc898517 100644
--- a/time/getdate.c
+++ b/time/getdate.c
@@ -112,16 +112,16 @@ __getdate_r (const char *string, struct tm *tp)
size_t len;
char *datemsk;
char *result = NULL;
- time_t timer;
+ __time64_t timer;
struct tm tm;
- struct stat64 st;
- int mday_ok = 0;
+ struct __stat64_t64 st;
+ bool mday_ok = false;
datemsk = getenv ("DATEMSK");
if (datemsk == NULL || *datemsk == '\0')
return 1;
- if (__stat64 (datemsk, &st) < 0)
+ if (__stat64_time64 (datemsk, &st) < 0)
return 3;
if (!S_ISREG (st.st_mode))
@@ -219,8 +219,8 @@ __getdate_r (const char *string, struct tm *tp)
return 7;
/* Get current time. */
- timer = time_now ();
- __localtime_r (&timer, &tm);
+ timer = time64_now ();
+ __localtime64_r (&timer, &tm);
/* If only the weekday is given, today is assumed if the given day
is equal to the current day and next week if it is less. */
@@ -230,7 +230,7 @@ __getdate_r (const char *string, struct tm *tp)
tp->tm_year = tm.tm_year;
tp->tm_mon = tm.tm_mon;
tp->tm_mday = tm.tm_mday + (tp->tm_wday - tm.tm_wday + 7) % 7;
- mday_ok = 1;
+ mday_ok = true;
}
/* If only the month is given, the current month is assumed if the
@@ -242,7 +242,7 @@ __getdate_r (const char *string, struct tm *tp)
if (tp->tm_year == INT_MIN)
tp->tm_year = tm.tm_year + (((tp->tm_mon - tm.tm_mon) < 0) ? 1 : 0);
tp->tm_mday = first_wday (tp->tm_year, tp->tm_mon, tp->tm_wday);
- mday_ok = 1;
+ mday_ok = true;
}
/* If no hour, minute and second are given the current hour, minute
@@ -285,15 +285,13 @@ __getdate_r (const char *string, struct tm *tp)
call normalizes the struct tm. */
if ((!mday_ok && !check_mday (TM_YEAR_BASE + tp->tm_year, tp->tm_mon,
tp->tm_mday))
- || mktime (tp) == (time_t) -1)
+ || __mktime64 (tp) == (time_t) -1)
return 8;
return 0;
}
-#ifdef weak_alias
weak_alias (__getdate_r, getdate_r)
-#endif
-
+libc_hidden_def (__getdate_r)
struct tm *
getdate (const char *string)
diff --git a/time/tst-getdate.c b/time/tst-getdate.c
index c37ba3083a..3bb0e96707 100644
--- a/time/tst-getdate.c
+++ b/time/tst-getdate.c
@@ -115,20 +115,14 @@ do_test (void)
{
setenv ("TZ", tests[i].tz, 1);
- int expected_err;
- if (sizeof (time_t) == 4 && tests[i].time64)
- expected_err = 8;
- else
- expected_err = 0;
-
tm = getdate (tests[i].str);
- TEST_COMPARE (getdate_err, expected_err);
- if (getdate_err != expected_err)
+ TEST_COMPARE (getdate_err, 0);
+ if (getdate_err != 0)
{
support_record_failure ();
printf ("%s\n", report_date_error ());
}
- else if (getdate_err == 0)
+ else
{
TEST_COMPARE (tests[i].tm.tm_mon, tm->tm_mon);
TEST_COMPARE (tests[i].tm.tm_year, tm->tm_year);
@@ -139,7 +133,7 @@ do_test (void)
}
struct tm tms;
- TEST_COMPARE (getdate_r (tests[i].str, &tms), expected_err);
+ TEST_COMPARE (getdate_r (tests[i].str, &tms), 0);
if (getdate_err == 0)
{
TEST_COMPARE (tests[i].tm.tm_mon, tms.tm_mon);
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-06-08 20:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-08 20:49 [glibc/azanella/y2038] time: Add 64 bit time support for getdate Adhemerval Zanella
-- strict thread matches above, loose matches on Subject: below --
2021-05-26 16:25 Adhemerval Zanella
2021-03-05 19:21 Adhemerval Zanella
2021-03-04 17:39 Adhemerval Zanella
2021-03-04 11:32 Adhemerval Zanella
2021-03-02 12:34 Adhemerval Zanella
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).