From 22db57e4a2e5b649d8cb4c7619a6c0ff04c70cd1 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sun, 5 Apr 1992 14:25:30 +0000 Subject: [PATCH] Added times() (from time) --- Modules/posixmodule.c | 52 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index df4d888b6d7..992147fc74c 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1,5 +1,5 @@ /*********************************************************** -Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The +Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The Netherlands. All Rights Reserved @@ -34,12 +34,22 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define NO_UNAME #endif +#ifndef MSDOS +#define DO_TIMES /* Comment this out if it causes trouble */ +#endif + #include #include #include #include #include +#ifdef DO_TIMES +#include +#include +#include +#endif + #ifdef SYSV #define UTIME_STRUCT @@ -58,7 +68,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #endif /* !SYSV */ #ifndef NO_UNISTD -#include /* Take this out if it doesn't exist */ +#include /* Take this out and hope the best if it doesn't exist */ #endif #include "allobjects.h" @@ -691,6 +701,41 @@ posix_symlink(self, args) } +#ifdef DO_TIMES + +static object * +posix_times(self, args) + object *self; + object *args; +{ + struct tms t; + clock_t c; + object *tuple; + if (!getnoarg(args)) + return NULL; + errno = 0; + c = times(&t); + if (c == (clock_t) -1) { + err_errno(IOError); + return NULL; + } + tuple = newtupleobject(4); + if (tuple == NULL) + return NULL; + settupleitem(tuple, 0, newfloatobject((double)t.tms_utime / HZ)); + settupleitem(tuple, 1, newfloatobject((double)t.tms_stime / HZ)); + settupleitem(tuple, 2, newfloatobject((double)t.tms_cutime / HZ)); + settupleitem(tuple, 3, newfloatobject((double)t.tms_cstime / HZ)); + if (err_occurred()) { + DECREF(tuple); + return NULL; + } + return tuple; +} + +#endif + + static struct methodlist posix_methods[] = { {"chdir", posix_chdir}, {"chmod", posix_chmod}, @@ -715,6 +760,9 @@ static struct methodlist posix_methods[] = { #endif {"unlink", posix_unlink}, {"utime", posix_utime}, +#ifdef DO_TIMES + {"times", posix_times}, +#endif #ifndef MSDOS {"_exit", posix__exit},