Deleted Added
full compact
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 26 unchanged lines hidden (view full) ---

35static char sccsid[] = "@(#)clock.c 8.1 (Berkeley) 6/4/93";
36#endif /* LIBC_SCCS and not lint */
37
38#include <sys/param.h>
39#include <sys/time.h>
40#include <sys/resource.h>
41
42/*
43 * Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000,
44 * but this would overflow if we switch to nanosec.
45 */
46#define CONVTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK))
47
48clock_t
49clock()
50{
51 struct rusage ru;
52
53 if (getrusage(RUSAGE_SELF, &ru))
54 return ((clock_t) -1);
55 return((clock_t)((CONVTCK(ru.ru_utime) + CONVTCK(ru.ru_stime))));
56}