summaryrefslogtreecommitdiff
path: root/utils/kl/Posix.c
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 21:39:35 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 21:39:35 +0000
commit74a4d8c26dd3c1e9febcb717cfd6cb6512991a7a (patch)
treec6e220ba61db3a6ea4052e6841296d829654e664 /utils/kl/Posix.c
parent46439007cf417cbd9ac8049bb4122c890097a0fa (diff)
20060303
Diffstat (limited to 'utils/kl/Posix.c')
-rw-r--r--utils/kl/Posix.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/utils/kl/Posix.c b/utils/kl/Posix.c
new file mode 100644
index 00000000..7c3a661f
--- /dev/null
+++ b/utils/kl/Posix.c
@@ -0,0 +1,80 @@
+#include "l.h"
+#include <sys/types.h>
+#include <sys/times.h>
+#undef getwd
+#include <unistd.h> /* For sysconf() and _SC_CLK_TCK */
+
+/*
+ * fake malloc
+ */
+void*
+malloc(size_t n)
+{
+ void *p;
+
+ while(n & 7)
+ n++;
+ while(nhunk < n)
+ gethunk();
+ p = hunk;
+ nhunk -= n;
+ hunk += n;
+ return p;
+}
+
+void
+free(void *p)
+{
+ USED(p);
+}
+
+void*
+calloc(size_t m, size_t n)
+{
+ void *p;
+
+ n *= m;
+ p = malloc(n);
+ memset(p, 0, n);
+ return p;
+}
+
+void*
+realloc(void *p, size_t n)
+{
+ fprint(2, "realloc called\n", p, n);
+ abort();
+ return 0;
+}
+
+void*
+mysbrk(ulong size)
+{
+ return (void*)sbrk(size);
+}
+
+double
+cputime(void)
+{
+
+ struct tms tmbuf;
+ double ret_val;
+
+ /*
+ * times() only fials if &tmbuf is invalid.
+ */
+ (void)times(&tmbuf);
+ /*
+ * Return the total time (in system clock ticks)
+ * spent in user code and system
+ * calls by both the calling process and its children.
+ */
+ ret_val = (double)(tmbuf.tms_utime + tmbuf.tms_stime +
+ tmbuf.tms_cutime + tmbuf.tms_cstime);
+ /*
+ * Convert to seconds.
+ */
+ ret_val *= sysconf(_SC_CLK_TCK);
+ return ret_val;
+
+}