From 772f20abb0a3a0979c440114bf3a1cff5b3cef03 Mon Sep 17 00:00:00 2001 From: cvpcs Date: Wed, 2 Jun 2010 11:02:31 -0500 Subject: initial import of bash 4.1 --- lib/sh/times.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 lib/sh/times.c (limited to 'lib/sh/times.c') diff --git a/lib/sh/times.c b/lib/sh/times.c new file mode 100644 index 0000000..47ddf57 --- /dev/null +++ b/lib/sh/times.c @@ -0,0 +1,77 @@ +/* times.c - times(3) library function */ + +/* Copyright (C) 1999 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see . +*/ + +#include + +#if !defined (HAVE_TIMES) + +#include +#include +#include + +#if defined (HAVE_SYS_RESOURCE_H) && defined (HAVE_GETRUSAGE) +# include +#endif /* HAVE_SYS_RESOURCE_H && HAVE_GETRUSAGE */ + +extern long get_clk_tck __P((void)); + +#define CONVTCK(r) (r.tv_sec * clk_tck + r.tv_usec / (1000000 / clk_tck)) + +clock_t +times(tms) + struct tms *tms; +{ + clock_t rv; + static long clk_tck = -1; + +#if defined (HAVE_GETRUSAGE) + struct timeval tv; + struct rusage ru; + + if (clk_tck == -1) + clk_tck = get_clk_tck(); + + if (getrusage(RUSAGE_SELF, &ru) < 0) + return ((clock_t)-1); + tms->tms_utime = CONVTCK(ru.ru_utime); + tms->tms_stime = CONVTCK(ru.ru_stime); + + if (getrusage(RUSAGE_CHILDREN, &ru) < 0) + return ((clock_t)-1); + tms->tms_cutime = CONVTCK(ru.ru_utime); + tms->tms_cstime = CONVTCK(ru.ru_stime); + + if (gettimeofday(&tv, (struct timezone *) 0) < 0) + return ((clock_t)-1); + rv = (clock_t)(CONVTCK(tv)); +#else /* !HAVE_GETRUSAGE */ + if (clk_tck == -1) + clk_tck = get_clk_tck(); + + /* We can't do anything. */ + tms->tms_utime = tms->tms_stime = (clock_t)0; + tms->tms_cutime = tms->tms_cstime = (clock_t)0; + + rv = (clock_t)time((time_t *)0) * clk_tck; +# endif /* HAVE_GETRUSAGE */ + + return rv; +} +#endif /* !HAVE_TIMES */ -- cgit v1.1