Commit 4e5d593a authored by Guido van Rossum's avatar Guido van Rossum

Added times() (from time)

parent 003a7898
/*********************************************************** /***********************************************************
Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands. Netherlands.
All Rights Reserved All Rights Reserved
...@@ -34,12 +34,22 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -34,12 +34,22 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define NO_UNAME #define NO_UNAME
#endif #endif
#ifndef MSDOS
#define DO_TIMES /* Comment this out if it causes trouble */
#endif
#include <signal.h> #include <signal.h>
#include <string.h> #include <string.h>
#include <setjmp.h> #include <setjmp.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#ifdef DO_TIMES
#include <sys/times.h>
#include <sys/param.h>
#include <errno.h>
#endif
#ifdef SYSV #ifdef SYSV
#define UTIME_STRUCT #define UTIME_STRUCT
...@@ -58,7 +68,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -58,7 +68,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#endif /* !SYSV */ #endif /* !SYSV */
#ifndef NO_UNISTD #ifndef NO_UNISTD
#include <unistd.h> /* Take this out if it doesn't exist */ #include <unistd.h> /* Take this out and hope the best if it doesn't exist */
#endif #endif
#include "allobjects.h" #include "allobjects.h"
...@@ -691,6 +701,41 @@ posix_symlink(self, args) ...@@ -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[] = { static struct methodlist posix_methods[] = {
{"chdir", posix_chdir}, {"chdir", posix_chdir},
{"chmod", posix_chmod}, {"chmod", posix_chmod},
...@@ -715,6 +760,9 @@ static struct methodlist posix_methods[] = { ...@@ -715,6 +760,9 @@ static struct methodlist posix_methods[] = {
#endif #endif
{"unlink", posix_unlink}, {"unlink", posix_unlink},
{"utime", posix_utime}, {"utime", posix_utime},
#ifdef DO_TIMES
{"times", posix_times},
#endif
#ifndef MSDOS #ifndef MSDOS
{"_exit", posix__exit}, {"_exit", posix__exit},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment