1 /* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #if defined(LIBC_SCCS) && !defined(lint) 9 static char sccsid[] = "@(#)clock.c 8.1 (Berkeley) 06/04/93"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 #include <sys/param.h> 13 #include <sys/time.h> 14 #include <sys/resource.h> 15 16 /* 17 * Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000, 18 * but this would overflow if we switch to nanosec. 19 */ 20 #define CONVTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK)) 21 22 clock_t clock()23clock() 24 { 25 struct rusage ru; 26 27 if (getrusage(RUSAGE_SELF, &ru)) 28 return ((clock_t) -1); 29 return((clock_t)((CONVTCK(ru.ru_utime) + CONVTCK(ru.ru_stime)))); 30 } 31