Skip to content

Commit 22db57e

Browse files
committed
Added times() (from time)
1 parent 94fb82e commit 22db57e

1 file changed

Lines changed: 50 additions & 2 deletions

File tree

Modules/posixmodule.c

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***********************************************************
2-
Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
2+
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
33
Netherlands.
44
55
All Rights Reserved
@@ -34,12 +34,22 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3434
#define NO_UNAME
3535
#endif
3636

37+
#ifndef MSDOS
38+
#define DO_TIMES /* Comment this out if it causes trouble */
39+
#endif
40+
3741
#include <signal.h>
3842
#include <string.h>
3943
#include <setjmp.h>
4044
#include <sys/types.h>
4145
#include <sys/stat.h>
4246

47+
#ifdef DO_TIMES
48+
#include <sys/times.h>
49+
#include <sys/param.h>
50+
#include <errno.h>
51+
#endif
52+
4353
#ifdef SYSV
4454

4555
#define UTIME_STRUCT
@@ -58,7 +68,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5868
#endif /* !SYSV */
5969

6070
#ifndef NO_UNISTD
61-
#include <unistd.h> /* Take this out if it doesn't exist */
71+
#include <unistd.h> /* Take this out and hope the best if it doesn't exist */
6272
#endif
6373

6474
#include "allobjects.h"
@@ -691,6 +701,41 @@ posix_symlink(self, args)
691701
}
692702

693703

704+
#ifdef DO_TIMES
705+
706+
static object *
707+
posix_times(self, args)
708+
object *self;
709+
object *args;
710+
{
711+
struct tms t;
712+
clock_t c;
713+
object *tuple;
714+
if (!getnoarg(args))
715+
return NULL;
716+
errno = 0;
717+
c = times(&t);
718+
if (c == (clock_t) -1) {
719+
err_errno(IOError);
720+
return NULL;
721+
}
722+
tuple = newtupleobject(4);
723+
if (tuple == NULL)
724+
return NULL;
725+
settupleitem(tuple, 0, newfloatobject((double)t.tms_utime / HZ));
726+
settupleitem(tuple, 1, newfloatobject((double)t.tms_stime / HZ));
727+
settupleitem(tuple, 2, newfloatobject((double)t.tms_cutime / HZ));
728+
settupleitem(tuple, 3, newfloatobject((double)t.tms_cstime / HZ));
729+
if (err_occurred()) {
730+
DECREF(tuple);
731+
return NULL;
732+
}
733+
return tuple;
734+
}
735+
736+
#endif
737+
738+
694739
static struct methodlist posix_methods[] = {
695740
{"chdir", posix_chdir},
696741
{"chmod", posix_chmod},
@@ -715,6 +760,9 @@ static struct methodlist posix_methods[] = {
715760
#endif
716761
{"unlink", posix_unlink},
717762
{"utime", posix_utime},
763+
#ifdef DO_TIMES
764+
{"times", posix_times},
765+
#endif
718766

719767
#ifndef MSDOS
720768
{"_exit", posix__exit},

0 commit comments

Comments
 (0)