From 9ac2398ef958e164ecbb918547aa493818a22942 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Fri, 16 Aug 2019 20:56:02 -0400 Subject: Demote ftime to a compat symbol; don’t install sys/timeb.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ftime is an obsolete variation on gettimeofday, offering only millisecond time resolution; it was probably a system call in ooold versions of BSD Unix. It is the only function declared by sys/timeb.h. It was deprecated in POSIX.1-2001 and removed from POSIX.1-2008. In glibc 2.31, we marked its declaration with __attribute_deprecated__. Demote it to a compat symbol and stop installing sys/timeb.h. Remove the minimal test of it (time/tst-ftime.c). Rename time/tst-ftime_l.c to tst-strftime_l.c; this test program has never had anything to do with ftime, it tests strftime_l. --- conform/Makefile | 9 ++++ time/Makefile | 8 ++-- time/ftime.c | 17 ++++++- time/sys/timeb.h | 44 ----------------- time/tst-ftime.c | 65 ------------------------- time/tst-ftime_l.c | 129 -------------------------------------------------- time/tst-strftime_l.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 158 insertions(+), 243 deletions(-) delete mode 100644 time/sys/timeb.h delete mode 100644 time/tst-ftime.c delete mode 100644 time/tst-ftime_l.c create mode 100644 time/tst-strftime_l.c diff --git a/conform/Makefile b/conform/Makefile index 0b5c4cb8ce..2f986ab977 100644 --- a/conform/Makefile +++ b/conform/Makefile @@ -241,3 +241,12 @@ test-xfail-XPG42/ndbm.h/linknamespace = yes test-xfail-UNIX98/ndbm.h/linknamespace = yes test-xfail-XOPEN2K/ndbm.h/linknamespace = yes test-xfail-XOPEN2K8/ndbm.h/linknamespace = yes + +# Header no longer provided by glibc (obsoleted in newer POSIX +# standards). +test-xfail-UNIX98/sys/timeb.h/conform = yes +test-xfail-UNIX98/sys/timeb.h/linknamespace = yes +test-xfail-XOPEN2K/sys/timeb.h/conform = yes +test-xfail-XOPEN2K/sys/timeb.h/linknamespace = yes +test-xfail-XPG42/sys/timeb.h/conform = yes +test-xfail-XPG42/sys/timeb.h/linknamespace = yes diff --git a/time/Makefile b/time/Makefile index a4fb13d6a3..c72abed005 100644 --- a/time/Makefile +++ b/time/Makefile @@ -22,7 +22,7 @@ subdir := time include ../Makeconfig -headers := time.h sys/time.h sys/timeb.h bits/time.h \ +headers := time.h sys/time.h bits/time.h \ bits/types/clockid_t.h bits/types/clock_t.h \ bits/types/struct_itimerspec.h \ bits/types/struct_timespec.h bits/types/struct_timeval.h \ @@ -43,9 +43,9 @@ routines := offtime asctime clock ctime ctime_r difftime \ aux := era alt_digit lc-time-cleanup tests := test_time clocktest tst-posixtz tst-strptime tst_wcsftime \ - tst-getdate tst-mktime tst-mktime2 tst-ftime_l tst-strftime \ + tst-getdate tst-mktime tst-mktime2 tst-strftime tst-strftime_l \ tst-mktime3 tst-strptime2 bug-asctime bug-asctime_r bug-mktime1 \ - tst-strptime3 bug-getdate1 tst-strptime-whitespace tst-ftime \ + tst-strptime3 bug-getdate1 tst-strptime-whitespace \ tst-tzname tst-y2039 bug-mktime4 tst-strftime2 tst-strftime3 \ tst-clock tst-clock2 tst-clock_nanosleep tst-cpuclock1 @@ -59,7 +59,7 @@ LOCALES := de_DE.ISO-8859-1 en_US.ISO-8859-1 ja_JP.EUC-JP fr_FR.UTF-8 \ nan_TW.UTF-8 lzh_TW.UTF-8 include ../gen-locales.mk -$(objpfx)tst-ftime_l.out: $(gen-locales) +$(objpfx)tst-strftime_l.out: $(gen-locales) $(objpfx)tst-strptime.out: $(gen-locales) $(objpfx)tst-strftime2.out: $(gen-locales) $(objpfx)tst-strftime3.out: $(gen-locales) diff --git a/time/ftime.c b/time/ftime.c index 93f485bbf7..0bbd923d70 100644 --- a/time/ftime.c +++ b/time/ftime.c @@ -16,10 +16,22 @@ License along with the GNU C Library; if not, see . */ -#include +#include + +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_32) + #include +struct timeb +{ + time_t time; /* Seconds since epoch, as from `time'. */ + unsigned short int millitm; /* Additional milliseconds. */ + short int timezone; /* Minutes west of GMT. */ + short int dstflag; /* Nonzero if Daylight Savings Time used. */ +}; + int +attribute_compat_text_section ftime (struct timeb *timebuf) { struct timespec ts; @@ -31,3 +43,6 @@ ftime (struct timeb *timebuf) timebuf->dstflag = 0; return 0; } +compat_symbol (libc, __ftime, ftime, GLIBC_2_0); + +#endif diff --git a/time/sys/timeb.h b/time/sys/timeb.h deleted file mode 100644 index 641c333450..0000000000 --- a/time/sys/timeb.h +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright (C) 1994-2020 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 - . */ - -#ifndef _SYS_TIMEB_H -#define _SYS_TIMEB_H 1 - -#include - -#include - -__BEGIN_DECLS - -/* Structure returned by the `ftime' function. */ - -struct timeb - { - time_t time; /* Seconds since epoch, as from `time'. */ - unsigned short int millitm; /* Additional milliseconds. */ - short int timezone; /* Minutes west of GMT. */ - short int dstflag; /* Nonzero if Daylight Savings Time used. */ - }; - -/* Fill in TIMEBUF with information about the current time. */ - -extern int ftime (struct timeb *__timebuf) - __nonnull ((1)) __attribute_deprecated__; - -__END_DECLS - -#endif /* sys/timeb.h */ diff --git a/time/tst-ftime.c b/time/tst-ftime.c deleted file mode 100644 index 08916c0c65..0000000000 --- a/time/tst-ftime.c +++ /dev/null @@ -1,65 +0,0 @@ -/* Verify that ftime is sane. - Copyright (C) 2014-2020 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 - . */ - -#include -#include -#include - -static int -do_test (void) -{ - struct timeb prev, curr = {.time = 0, .millitm = 0}; - int sec = 0; - - while (sec != 3) - { - prev = curr; - - /* ftime was deprecated on 2.31. */ - DIAG_PUSH_NEEDS_COMMENT; - DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wdeprecated-declarations"); - - if (ftime (&curr)) - { - printf ("ftime returned an error\n"); - return 1; - } - - DIAG_POP_NEEDS_COMMENT; - - if (curr.time < prev.time) - { - printf ("ftime's time flowed backwards\n"); - return 1; - } - - if (curr.time == prev.time - && curr.millitm < prev.millitm) - { - printf ("ftime's millitm flowed backwards\n"); - return 1; - } - - if (curr.time > prev.time) - sec ++; - } - return 0; -} - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" diff --git a/time/tst-ftime_l.c b/time/tst-ftime_l.c deleted file mode 100644 index 6690efeb9c..0000000000 --- a/time/tst-ftime_l.c +++ /dev/null @@ -1,129 +0,0 @@ -#include -#include -#include -#include -#include -#include - - -static int -do_test (void) -{ - locale_t l; - locale_t old; - struct tm tm; - char buf[1000]; - wchar_t wbuf[1000]; - int result = 0; - size_t n; - - l = newlocale (LC_ALL_MASK, "de_DE.ISO-8859-1", NULL); - if (l == NULL) - { - puts ("newlocale failed"); - exit (1); - } - - memset (&tm, '\0', sizeof (tm)); - - tm.tm_year = 102; - tm.tm_mon = 2; - tm.tm_mday = 1; - - if (strftime (buf, sizeof (buf), "%e %^B %Y", &tm) == 0) - { - puts ("initial strftime failed"); - exit (1); - } - if (strcmp (buf, " 1 MARCH 2002") != 0) - { - printf ("initial strftime: expected \"%s\", got \"%s\"\n", - " 1 MARCH 2002", buf); - result = 1; - } - else - printf ("got \"%s\"\n", buf); - - /* Now using the extended locale model. */ - if (strftime_l (buf, sizeof (buf), "%e %^B %Y", &tm, l) == 0) - { - puts ("strftime_l failed"); - result = 1; - } - else if (strcmp (buf, " 1 M\xc4RZ 2002") != 0) - { - printf ("strftime_l: expected \"%s\", got \"%s\"\n", - " 1 M\xc4RZ 2002", buf); - result = 1; - } - else - { - setlocale (LC_ALL, "de_DE.ISO-8859-1"); - printf ("got \"%s\"\n", buf); - setlocale (LC_ALL, "C"); - } - - /* And the wide character version. */ - if (wcsftime_l (wbuf, sizeof (wbuf) / sizeof (wbuf[0]), L"%e %^B %Y", &tm, l) - == 0) - { - puts ("wcsftime_l failed"); - result = 1; - } - else if (wcscmp (wbuf, L" 1 M\x00c4RZ 2002") != 0) - { - printf ("wcsftime_l: expected \"%ls\", got \"%ls\"\n", - L" 1 M\x00c4RZ 2002", wbuf); - result = 1; - } - else - { - setlocale (LC_ALL, "de_DE.ISO-8859-1"); - printf ("got \"%ls\"\n", wbuf); - setlocale (LC_ALL, "C"); - } - - old = uselocale (l); - - n = strftime (buf, sizeof (buf), "%e %^B %Y", &tm); - - /* Switch back. */ - (void) uselocale (old); - - if (n == 0) - { - puts ("strftime after first uselocale failed"); - result = 1; - } - else if (strcmp (buf, " 1 M\xc4RZ 2002") != 0) - { - printf ("strftime in non-C locale: expected \"%s\", got \"%s\"\n", - " 1 M\xc4RZ 2002", buf); - result = 1; - } - else - { - setlocale (LC_ALL, "de_DE.ISO-8859-1"); - printf ("got \"%s\"\n", buf); - setlocale (LC_ALL, "C"); - } - - if (strftime (buf, sizeof (buf), "%e %^B %Y", &tm) == 0) - { - puts ("strftime after second uselocale failed"); - result = 1; - } - else if (strcmp (buf, " 1 MARCH 2002") != 0) - { - printf ("initial strftime: expected \"%s\", got \"%s\"\n", - " 1 MARCH 2002", buf); - result = 1; - } - else - printf ("got \"%s\"\n", buf); - - return result; -} - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" diff --git a/time/tst-strftime_l.c b/time/tst-strftime_l.c new file mode 100644 index 0000000000..6690efeb9c --- /dev/null +++ b/time/tst-strftime_l.c @@ -0,0 +1,129 @@ +#include +#include +#include +#include +#include +#include + + +static int +do_test (void) +{ + locale_t l; + locale_t old; + struct tm tm; + char buf[1000]; + wchar_t wbuf[1000]; + int result = 0; + size_t n; + + l = newlocale (LC_ALL_MASK, "de_DE.ISO-8859-1", NULL); + if (l == NULL) + { + puts ("newlocale failed"); + exit (1); + } + + memset (&tm, '\0', sizeof (tm)); + + tm.tm_year = 102; + tm.tm_mon = 2; + tm.tm_mday = 1; + + if (strftime (buf, sizeof (buf), "%e %^B %Y", &tm) == 0) + { + puts ("initial strftime failed"); + exit (1); + } + if (strcmp (buf, " 1 MARCH 2002") != 0) + { + printf ("initial strftime: expected \"%s\", got \"%s\"\n", + " 1 MARCH 2002", buf); + result = 1; + } + else + printf ("got \"%s\"\n", buf); + + /* Now using the extended locale model. */ + if (strftime_l (buf, sizeof (buf), "%e %^B %Y", &tm, l) == 0) + { + puts ("strftime_l failed"); + result = 1; + } + else if (strcmp (buf, " 1 M\xc4RZ 2002") != 0) + { + printf ("strftime_l: expected \"%s\", got \"%s\"\n", + " 1 M\xc4RZ 2002", buf); + result = 1; + } + else + { + setlocale (LC_ALL, "de_DE.ISO-8859-1"); + printf ("got \"%s\"\n", buf); + setlocale (LC_ALL, "C"); + } + + /* And the wide character version. */ + if (wcsftime_l (wbuf, sizeof (wbuf) / sizeof (wbuf[0]), L"%e %^B %Y", &tm, l) + == 0) + { + puts ("wcsftime_l failed"); + result = 1; + } + else if (wcscmp (wbuf, L" 1 M\x00c4RZ 2002") != 0) + { + printf ("wcsftime_l: expected \"%ls\", got \"%ls\"\n", + L" 1 M\x00c4RZ 2002", wbuf); + result = 1; + } + else + { + setlocale (LC_ALL, "de_DE.ISO-8859-1"); + printf ("got \"%ls\"\n", wbuf); + setlocale (LC_ALL, "C"); + } + + old = uselocale (l); + + n = strftime (buf, sizeof (buf), "%e %^B %Y", &tm); + + /* Switch back. */ + (void) uselocale (old); + + if (n == 0) + { + puts ("strftime after first uselocale failed"); + result = 1; + } + else if (strcmp (buf, " 1 M\xc4RZ 2002") != 0) + { + printf ("strftime in non-C locale: expected \"%s\", got \"%s\"\n", + " 1 M\xc4RZ 2002", buf); + result = 1; + } + else + { + setlocale (LC_ALL, "de_DE.ISO-8859-1"); + printf ("got \"%s\"\n", buf); + setlocale (LC_ALL, "C"); + } + + if (strftime (buf, sizeof (buf), "%e %^B %Y", &tm) == 0) + { + puts ("strftime after second uselocale failed"); + result = 1; + } + else if (strcmp (buf, " 1 MARCH 2002") != 0) + { + printf ("initial strftime: expected \"%s\", got \"%s\"\n", + " 1 MARCH 2002", buf); + result = 1; + } + else + printf ("got \"%s\"\n", buf); + + return result; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" -- cgit 1.4.1