1 /*
2 Copyright (c) 1994 Cygnus Support.
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms are permitted
6 provided that the above copyright notice and this paragraph are
7 duplicated in all such forms and that any documentation,
8 and/or other materials related to such
9 distribution and use acknowledge that the software was developed
10 at Cygnus Support, Inc.  Cygnus Support, Inc. may not be used to
11 endorse or promote products derived from this software without
12 specific prior written permission.
13 THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 /* NetWare can not use this implementation of clock, since it does not
18    have times or any similar function.  It provides its own version of
19    clock in clib.nlm.  If we can not use clib.nlm, then we must write
20    clock in sys/netware.  */
21 
22 #ifdef CLOCK_PROVIDED
23 
24 int _dummy_clock = 1;
25 
26 #else
27 
28 /*
29  * clock.c
30  * Original Author:	G. Haley
31  *
32  * Determines the processor time used by the program since invocation. The time
33  * in seconds is the value returned divided by the value of the macro CLK_TCK.
34  * If the processor time used is not available, (clock_t) -1 is returned.
35  */
36 
37 /*
38 FUNCTION
39 <<clock>>---cumulative processor time
40 
41 INDEX
42 	clock
43 
44 SYNOPSIS
45 	#include <time.h>
46 	clock_t clock(void);
47 
48 DESCRIPTION
49 Calculates the best available approximation of the cumulative amount
50 of time used by your program since it started.  To convert the result
51 into seconds, divide by the macro <<CLOCKS_PER_SEC>>.
52 
53 RETURNS
54 The amount of processor time used so far by your program, in units
55 defined by the machine-dependent macro <<CLOCKS_PER_SEC>>.  If no
56 measurement is available, the result is (clock_t)<<-1>>.
57 
58 PORTABILITY
59 ANSI C requires <<clock>> and <<CLOCKS_PER_SEC>>.
60 
61 Supporting OS subroutine required: <<times>>.
62 */
63 
64 #include <time.h>
65 #include <sys/times.h>
66 
67 clock_t
clock(void)68 clock (void)
69 {
70   struct tms tim_s;
71   clock_t res;
72 
73   if ((res = (clock_t) times (&tim_s)) != (clock_t) -1)
74     res = (clock_t) (tim_s.tms_utime + tim_s.tms_stime +
75 		     tim_s.tms_cutime + tim_s.tms_cstime);
76 
77   return res;
78 }
79 
80 #endif /* CLOCK_PROVIDED */
81