summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/ap/plan9/times.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/ape/lib/ap/plan9/times.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/ape/lib/ap/plan9/times.c')
-rwxr-xr-xsys/src/ape/lib/ap/plan9/times.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/sys/src/ape/lib/ap/plan9/times.c b/sys/src/ape/lib/ap/plan9/times.c
new file mode 100755
index 000000000..2d1e95c8c
--- /dev/null
+++ b/sys/src/ape/lib/ap/plan9/times.c
@@ -0,0 +1,51 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/times.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+
+static
+char*
+skip(char *p)
+{
+
+ while(*p == ' ')
+ p++;
+ while(*p != ' ' && *p != 0)
+ p++;
+ return p;
+}
+
+clock_t
+times(struct tms *buf)
+{
+ char b[200], *p;
+ int f;
+ unsigned long r;
+
+ memset(b, 0, sizeof(b));
+ f = open("/dev/cputime", O_RDONLY);
+ if(f >= 0) {
+ lseek(f, SEEK_SET, 0);
+ read(f, b, sizeof(b));
+ close(f);
+ }
+ p = b;
+ if(buf)
+ buf->tms_utime = atol(p);
+ p = skip(p);
+ if(buf)
+ buf->tms_stime = atol(p);
+ p = skip(p);
+ r = atol(p);
+ if(buf){
+ p = skip(p);
+ buf->tms_cutime = atol(p);
+ p = skip(p);
+ buf->tms_cstime = atol(p);
+ }
+ return r;
+}