Przeglądaj źródła

LibC: Implement clock() and add CLOCKS_PER_SEC define.

Andreas Kling 6 lat temu
rodzic
commit
f015798af9
2 zmienionych plików z 11 dodań i 0 usunięć
  1. 8 0
      LibC/time.cpp
  2. 3 0
      LibC/time.h

+ 8 - 0
LibC/time.cpp

@@ -1,5 +1,6 @@
 #include <time.h>
 #include <sys/time.h>
+#include <sys/times.h>
 #include <errno.h>
 #include <assert.h>
 #include <Kernel/Syscall.h>
@@ -110,4 +111,11 @@ void tzset()
     ASSERT_NOT_REACHED();
 }
 
+clock_t clock()
+{
+    struct tms tms;
+    times(&tms);
+    return tms.tms_utime + tms.tms_stime;
+}
+
 }

+ 3 - 0
LibC/time.h

@@ -32,7 +32,10 @@ time_t time(time_t*);
 char* ctime(const time_t*);
 void tzset();
 char *asctime(const struct tm*);
+
+#define CLOCKS_PER_SEC 1000
 clock_t clock();
+
 double difftime(time_t, time_t);
 size_t strftime(char* s, size_t max, const char* format, const struct tm*);