Deleted Added
full compact
clock.c (1574) clock.c (6167)
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/*
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,
43 * Convert usec to clock ticks; could do (usec * CLOCKS_PER_SEC) / 1000000,
44 * but this would overflow if we switch to nanosec.
45 */
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))
46#define CONVTCK(r) ((r).tv_sec * CLOCKS_PER_SEC \
47 + (r).tv_usec / (1000000 / CLOCKS_PER_SEC))
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}
48
49clock_t
50clock()
51{
52 struct rusage ru;
53
54 if (getrusage(RUSAGE_SELF, &ru))
55 return ((clock_t) -1);
56 return((clock_t)((CONVTCK(ru.ru_utime) + CONVTCK(ru.ru_stime))));
57}