diff options
author | Guido van Rossum <guido@python.org> | 1992-03-12 17:33:14 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1992-03-12 17:33:14 (GMT) |
commit | 27aaa6daa941ed945a0d200c1598b467e7a8bc3b (patch) | |
tree | fb1ac111cc49ec2b1061cc1d585f9a680fb806aa | |
parent | b83241c0bd65bd4a7b129b8401550a2c44bb8d7e (diff) | |
download | cpython-27aaa6daa941ed945a0d200c1598b467e7a8bc3b.zip cpython-27aaa6daa941ed945a0d200c1598b467e7a8bc3b.tar.gz cpython-27aaa6daa941ed945a0d200c1598b467e7a8bc3b.tar.bz2 |
Add interface to times(2).
-rw-r--r-- | Modules/timemodule.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 848e322..78724f0 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -58,6 +58,20 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <time.h> #endif /* !unix */ +#ifdef sgi +#define DO_TIMES +#endif + +#ifdef sun +#define DO_TIMES +#endif + +#ifdef DO_TIMES +#include <sys/times.h> +#include <sys/param.h> +#include <errno.h> +#endif + /* Time methods */ static object * @@ -169,12 +183,47 @@ time_millitimer(self, args) #endif /* DO_MILLI */ +#ifdef DO_TIMES + +static object * +time_times(self, args) + object *self; + object *args; +{ + struct tms t; + clock_t c; + object *tuple; + 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 time_methods[] = { #ifdef DO_MILLI {"millisleep", time_millisleep}, {"millitimer", time_millitimer}, #endif /* DO_MILLI */ +#ifdef DO_TIMES + {"times", time_times}, +#endif {"sleep", time_sleep}, {"time", time_time}, {NULL, NULL} /* sentinel */ |