Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Version times() so that programs compiled before the recent ...



details:   https://anonhg.NetBSD.org/src/rev/7cec5e76c3ae
branches:  trunk
changeset: 533432:7cec5e76c3ae
user:      bjh21 <bjh21%NetBSD.org@localhost>
date:      Sun Jun 30 09:45:39 2002 +0000

description:
Version times() so that programs compiled before the recent change to make
sysconf(_SC_CLK_TCK) return hz will work.

In detail:
__times13() returns values scaled by hz.
times() returns values scaled by 100.
<sys/times.h> renames times() to __times13().

_SC_CLK_TCK has changed from 3 to 39.
sysconf(3) returns 100.
sysconf(39) returns hz.
CLK_TCK is defined as sysconf(39).

diffstat:

 include/time.h            |   12 ++++-
 lib/libc/gen/Makefile.inc |   12 ++--
 lib/libc/gen/__times13.c  |  100 ++++++++++++++++++++++++++++++++++++++++++++++
 lib/libc/gen/sysconf.c    |   10 +++-
 lib/libc/gen/times.c      |   95 ++----------------------------------------
 sys/sys/times.h           |    6 ++-
 sys/sys/unistd.h          |    5 +-
 7 files changed, 137 insertions(+), 103 deletions(-)

diffs (truncated from 342 to 300 lines):

diff -r ada373820e27 -r 7cec5e76c3ae include/time.h
--- a/include/time.h    Sun Jun 30 08:10:40 2002 +0000
+++ b/include/time.h    Sun Jun 30 09:45:39 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: time.h,v 1.28 2002/06/23 19:41:04 perry Exp $  */
+/*     $NetBSD: time.h,v 1.29 2002/06/30 09:45:39 bjh21 Exp $  */
 
 /*
  * Copyright (c) 1989, 1993
@@ -104,13 +104,19 @@
 
 #if !defined(_ANSI_SOURCE)
 
+#ifdef __LIBC12_SOURCE__
+#define CLK_TCK 100
+#else
+
 /*
  * CLK_TCK uses libc's internal __sysconf() to retrieve the machine's
- * HZ. The value of _SC_CLK_TCK is 3 -- we hard code it so we do not
+ * HZ. The value of _SC_CLK_TCK is 39 -- we hard code it so we do not
  * need to include unistd.h
  */
 long __sysconf __P((int));
-#define CLK_TCK                (__sysconf(3))
+#define CLK_TCK                (__sysconf(39))
+
+#endif
 
 extern __aconst char *tzname[2];
 void tzset __P((void));
diff -r ada373820e27 -r 7cec5e76c3ae lib/libc/gen/Makefile.inc
--- a/lib/libc/gen/Makefile.inc Sun Jun 30 08:10:40 2002 +0000
+++ b/lib/libc/gen/Makefile.inc Sun Jun 30 09:45:39 2002 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.111 2002/05/24 04:01:43 itojun Exp $
+#      $NetBSD: Makefile.inc,v 1.112 2002/06/30 09:45:39 bjh21 Exp $
 #      from: @(#)Makefile.inc  8.6 (Berkeley) 5/4/95
 
 # gen sources
@@ -20,11 +20,11 @@
        sethostname.c setjmperr.c setmode.c setproctitle.c setprogname.c \
        shquote.c shquotev.c siginterrupt.c __siglist14.c siglist.c signal.c \
        __signame14.c signame.c __sigsetops14.c sigsetops.c sleep.c \
-       stringlist.c sysconf.c sysctl.c syslog.c telldir.c time.c times.c \
-       timezone.c toascii.c tolower_.c ttyname.c ttyslot.c toupper_.c \
-       ualarm.c ulimit.c uname.c unvis.c usleep.c utime.c utmpx.c valloc.c \
-       vis.c wait.c wait3.c waitpid.c warn.c warnx.c vwarn.c vwarnx.c verr.c \
-       verrx.c
+       stringlist.c sysconf.c sysctl.c syslog.c telldir.c time.c __times13.c \
+       times.c timezone.c toascii.c tolower_.c ttyname.c ttyslot.c \
+       toupper_.c ualarm.c ulimit.c uname.c unvis.c usleep.c utime.c utmpx.c \
+       valloc.c vis.c wait.c wait3.c waitpid.c warn.c warnx.c vwarn.c \
+       vwarnx.c verr.c verrx.c
 
 # indirect reference stubs, to be removed soon.
 SRCS+= _err.c _errx.c _sys_errlist.c _sys_nerr.c _sys_siglist.c \
diff -r ada373820e27 -r 7cec5e76c3ae lib/libc/gen/__times13.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/gen/__times13.c  Sun Jun 30 09:45:39 2002 +0000
@@ -0,0 +1,100 @@
+/*     $NetBSD: __times13.c,v 1.1 2002/06/30 09:45:39 bjh21 Exp $      */
+
+/*-
+ * Copyright (c) 1990, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)times.c    8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: __times13.c,v 1.1 2002/06/30 09:45:39 bjh21 Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/times.h>
+#include <sys/resource.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <time.h>
+
+#ifdef __weak_alias
+#ifdef __LIBC12_SOURCE__
+__weak_alias(times,_times)
+#endif
+#endif
+
+#ifdef __LIBC12_SOURCE__
+__warn_references(times,
+    "warning: reference to compatibility times(); include <sys/times.h> for correct reference")
+#endif
+
+/*
+ * Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000,
+ * but this would overflow if we switch to nanosec.
+ */
+#define        CONVTCK(r)      (r.tv_sec * clk_tck + r.tv_usec / (1000000 / clk_tck))
+
+clock_t
+times(tp)
+       struct tms *tp;
+{
+       struct rusage ru;
+       struct timeval t;
+       static long clk_tck;
+       
+       _DIAGASSERT(tp != NULL);
+
+       /*
+        * we use a local copy of CLK_TCK because it expands to a
+        * moderately expensive function call.
+        */
+       if (clk_tck == 0)
+               clk_tck = CLK_TCK;
+
+       if (getrusage(RUSAGE_SELF, &ru) < 0)
+               return ((clock_t)-1);
+       tp->tms_utime = CONVTCK(ru.ru_utime);
+       tp->tms_stime = CONVTCK(ru.ru_stime);
+       if (getrusage(RUSAGE_CHILDREN, &ru) < 0)
+               return ((clock_t)-1);
+       tp->tms_cutime = CONVTCK(ru.ru_utime);
+       tp->tms_cstime = CONVTCK(ru.ru_stime);
+       if (gettimeofday(&t, (struct timezone *)0))
+               return ((clock_t)-1);
+       return ((clock_t)(CONVTCK(t)));
+}
diff -r ada373820e27 -r 7cec5e76c3ae lib/libc/gen/sysconf.c
--- a/lib/libc/gen/sysconf.c    Sun Jun 30 08:10:40 2002 +0000
+++ b/lib/libc/gen/sysconf.c    Sun Jun 30 09:45:39 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysconf.c,v 1.15 2002/06/23 19:19:01 perry Exp $       */
+/*     $NetBSD: sysconf.c,v 1.16 2002/06/30 09:45:40 bjh21 Exp $       */
 
 /*-
  * Copyright (c) 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)sysconf.c  8.2 (Berkeley) 3/20/94";
 #else
-__RCSID("$NetBSD: sysconf.c,v 1.15 2002/06/23 19:19:01 perry Exp $");
+__RCSID("$NetBSD: sysconf.c,v 1.16 2002/06/30 09:45:40 bjh21 Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -91,6 +91,12 @@
                break;
        case _SC_CHILD_MAX:
                return (getrlimit(RLIMIT_NPROC, &rl) ? -1 : (long)rl.rlim_cur);
+       case _O_SC_CLK_TCK:
+               /*
+                * For applications compiled when CLK_TCK was a compile-time
+                * constant.
+                */
+               return 100;
        case _SC_CLK_TCK:
                /*
                 * Has to be handled specially because it returns a
diff -r ada373820e27 -r 7cec5e76c3ae lib/libc/gen/times.c
--- a/lib/libc/gen/times.c      Sun Jun 30 08:10:40 2002 +0000
+++ b/lib/libc/gen/times.c      Sun Jun 30 09:45:39 2002 +0000
@@ -1,93 +1,10 @@
-/*     $NetBSD: times.c,v 1.12 2002/06/23 20:21:08 perry Exp $ */
+/*     $NetBSD: times.c,v 1.13 2002/06/30 09:45:40 bjh21 Exp $ */
 
-/*-
- * Copyright (c) 1990, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+/*
+ * Ben Harris, 2002.
+ * This file is in the Public Domain.
  */
 
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)times.c    8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: times.c,v 1.12 2002/06/23 20:21:08 perry Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-#include "namespace.h"
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/times.h>
-#include <sys/resource.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <time.h>
-
-#ifdef __weak_alias
-__weak_alias(times,_times)
-#endif
-
-/*
- * Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000,
- * but this would overflow if we switch to nanosec.
- */
-#define        CONVTCK(r)      (r.tv_sec * clk_tck + r.tv_usec / (1000000 / clk_tck))
+#define __LIBC12_SOURCE__
 
-clock_t
-times(tp)
-       struct tms *tp;
-{
-       struct rusage ru;
-       struct timeval t;
-       static long clk_tck;
-       
-       _DIAGASSERT(tp != NULL);
-
-       /*
-        * we use a local copy of CLK_TCK because it expands to a
-        * moderately expensive function call.
-        */
-       if (clk_tck == 0)
-               clk_tck = CLK_TCK;
-
-       if (getrusage(RUSAGE_SELF, &ru) < 0)
-               return ((clock_t)-1);
-       tp->tms_utime = CONVTCK(ru.ru_utime);
-       tp->tms_stime = CONVTCK(ru.ru_stime);
-       if (getrusage(RUSAGE_CHILDREN, &ru) < 0)
-               return ((clock_t)-1);
-       tp->tms_cutime = CONVTCK(ru.ru_utime);
-       tp->tms_cstime = CONVTCK(ru.ru_stime);
-       if (gettimeofday(&t, (struct timezone *)0))
-               return ((clock_t)-1);
-       return ((clock_t)(CONVTCK(t)));
-}
+#include "__times13.c"
diff -r ada373820e27 -r 7cec5e76c3ae sys/sys/times.h
--- a/sys/sys/times.h   Sun Jun 30 08:10:40 2002 +0000
+++ b/sys/sys/times.h   Sun Jun 30 09:45:39 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: times.h,v 1.8 1995/03/26 20:24:54 jtc Exp $    */



Home | Main Index | Thread Index | Old Index