From patchwork Mon Jan 5 20:46:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lu, Hongjiu" X-Patchwork-Id: 4512 Received: (qmail 16137 invoked by alias); 5 Jan 2015 20:47:21 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 16124 invoked by uid 89); 5 Jan 2015 20:47:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL, BAYES_00, NO_DNS_FOR_FROM, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mga14.intel.com X-ExtLoop1: 1 Date: Mon, 5 Jan 2015 12:46:54 -0800 From: "H.J. Lu" To: GNU C Library Subject: [PATCH] Define CLOCKS_PER_SEC type to the type clock_t Message-ID: <20150105204653.GA31001@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) C99 specifies that CLOCKS_PER_SEC is a constant expression with the type clock_t. This patch adds a generic to define CLOCKS_PER_SEC and provides the Linux/x86-64 version of to support x32. Tested on i686, x32 and x86-64. OK to install? Thanks. H.J. --- [BZ #17797] * bits/time2.h: New file. * sysdeps/unix/sysv/linux/x86/bits/time2.h: Likewise. * bits/time.h: Include . (CLOCKS_PER_SEC): Removed. * sysdeps/unix/sysv/linux/bits/time.h: Likewise. * time/Makefile (headers): Add bits/time2.h. * time/clocktest.c (main): Replace %ld with %jd and cast to intmax_t. --- ChangeLog | 12 ++++++++++ bits/time.h | 9 ++------ bits/time2.h | 34 ++++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/bits/time.h | 9 ++------ sysdeps/unix/sysv/linux/x86/bits/time2.h | 38 ++++++++++++++++++++++++++++++++ time/Makefile | 2 +- time/clocktest.c | 4 ++-- 7 files changed, 91 insertions(+), 17 deletions(-) create mode 100644 bits/time2.h create mode 100644 sysdeps/unix/sysv/linux/x86/bits/time2.h diff --git a/ChangeLog b/ChangeLog index 4674e72..f97ee98 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2015-01-05 H.J. Lu + + [BZ #17797] + * bits/time2.h: New file. + * sysdeps/unix/sysv/linux/x86/bits/time2.h: Likewise. + * bits/time.h: Include . + (CLOCKS_PER_SEC): Removed. + * sysdeps/unix/sysv/linux/bits/time.h: Likewise. + * time/Makefile (headers): Add bits/time2.h. + * time/clocktest.c (main): Replace %ld with %jd and cast to + intmax_t. + 2015-01-05 Joseph Myers [BZ #17796] diff --git a/bits/time.h b/bits/time.h index ae17b7f..8ea1ce9 100644 --- a/bits/time.h +++ b/bits/time.h @@ -24,13 +24,8 @@ # ifndef _BITS_TIME_H # define _BITS_TIME_H 1 -/* ISO/IEC 9899:1990 7.12.1: - The macro `CLOCKS_PER_SEC' is the number per second of the value - returned by the `clock' function. */ -/* CAE XSH, Issue 4, Version 2: - The value of CLOCKS_PER_SEC is required to be 1 million on all - XSI-conformant systems. */ -# define CLOCKS_PER_SEC 1000000l +/* Get CLOCKS_PER_SEC. */ +# include # if !defined __STRICT_ANSI__ && !defined __USE_XOPEN2K /* Even though CLOCKS_PER_SEC has such a strange value CLK_TCK diff --git a/bits/time2.h b/bits/time2.h new file mode 100644 index 0000000..1d1203d --- /dev/null +++ b/bits/time2.h @@ -0,0 +1,34 @@ +/* CLOCKS_PER_SEC. Generic version. + Copyright (C) 2015 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 + . */ + +/* + * Never include this file directly; use instead. + */ + +#ifndef _BITS_TIME_H +# error "Never include directly; use instead." +#endif + +/* ISO/IEC 9899:1999 7.23: Date and time + The macro `CLOCKS_PER_SEC' is a constant expression with type `clock_t' + that is the number per second of the value returned by the `clock' + function. */ +/* CAE XSH, Issue 4, Version 2: + The value of CLOCKS_PER_SEC is required to be 1 million on all + XSI-conformant systems. */ +#define CLOCKS_PER_SEC 1000000l diff --git a/sysdeps/unix/sysv/linux/bits/time.h b/sysdeps/unix/sysv/linux/bits/time.h index 226d6dd..6207f07 100644 --- a/sysdeps/unix/sysv/linux/bits/time.h +++ b/sysdeps/unix/sysv/linux/bits/time.h @@ -39,13 +39,8 @@ struct timeval # ifndef _BITS_TIME_H # define _BITS_TIME_H 1 -/* ISO/IEC 9899:1990 7.12.1: - The macro `CLOCKS_PER_SEC' is the number per second of the value - returned by the `clock' function. */ -/* CAE XSH, Issue 4, Version 2: - The value of CLOCKS_PER_SEC is required to be 1 million on all - XSI-conformant systems. */ -# define CLOCKS_PER_SEC 1000000l +/* Get CLOCKS_PER_SEC. */ +# include # if (!defined __STRICT_ANSI__ || defined __USE_POSIX) \ && !defined __USE_XOPEN2K diff --git a/sysdeps/unix/sysv/linux/x86/bits/time2.h b/sysdeps/unix/sysv/linux/x86/bits/time2.h new file mode 100644 index 0000000..6cce326 --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86/bits/time2.h @@ -0,0 +1,38 @@ +/* CLOCKS_PER_SEC. Linux/x86-64 version. + Copyright (C) 2015 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 + . */ + +/* + * Never include this file directly; use instead. + */ + +#ifndef _BITS_TIME_H +# error "Never include directly; use instead." +#endif + +/* ISO/IEC 9899:1999 7.23: Date and time + The macro `CLOCKS_PER_SEC' is a constant expression with type `clock_t' + that is the number per second of the value returned by the `clock' + function. */ +/* CAE XSH, Issue 4, Version 2: + The value of CLOCKS_PER_SEC is required to be 1 million on all + XSI-conformant systems. */ +#if defined __x86_64__ && defined __ILP32__ +# define CLOCKS_PER_SEC 1000000ll +#else +# define CLOCKS_PER_SEC 1000000l +#endif diff --git a/time/Makefile b/time/Makefile index a411f62..da2ff6b 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 sys/timeb.h bits/time.h bits/time2.h routines := offtime asctime clock ctime ctime_r difftime \ gmtime localtime mktime time \ diff --git a/time/clocktest.c b/time/clocktest.c index 2e6457d..13b7420 100644 --- a/time/clocktest.c +++ b/time/clocktest.c @@ -30,7 +30,7 @@ main (int argc, char ** argv) printf ("%jd clock ticks per second (start=%jd,stop=%jd)\n", (intmax_t) (stop - start), (intmax_t) start, (intmax_t) stop); - printf ("CLOCKS_PER_SEC=%ld, sysconf(_SC_CLK_TCK)=%ld\n", - CLOCKS_PER_SEC, sysconf(_SC_CLK_TCK)); + printf ("CLOCKS_PER_SEC=%jd, sysconf(_SC_CLK_TCK)=%ld\n", + (intmax_t) CLOCKS_PER_SEC, sysconf(_SC_CLK_TCK)); return 0; }