1 #include "l.h" 2 #include <sys/types.h> 3 #include <sys/stat.h> 4 #include <sys/times.h> 5 #undef getwd 6 #include <unistd.h> /* For sysconf() and _SC_CLK_TCK */ 7 8 void* mysbrk(usize size)9mysbrk(usize size) 10 { 11 return (void*)sbrk(size); 12 } 13 14 double cputime(void)15cputime(void) 16 { 17 18 struct tms tmbuf; 19 double ret_val; 20 21 /* 22 * times() only fails if &tmbuf is invalid. 23 */ 24 (void)times(&tmbuf); 25 /* 26 * Return the total time (in system clock ticks) 27 * spent in user code and system 28 * calls by both the calling process and its children. 29 */ 30 ret_val = (double)(tmbuf.tms_utime + tmbuf.tms_stime + 31 tmbuf.tms_cutime + tmbuf.tms_cstime); 32 /* 33 * Convert to seconds. 34 */ 35 ret_val *= sysconf(_SC_CLK_TCK); 36 return ret_val; 37 38 } 39 40 int fileexists(char * name)41fileexists(char *name) 42 { 43 struct stat sb; 44 45 return stat(name, &sb) >= 0; 46 } 47