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 /*
18 FUNCTION
19 <<time>>---get current calendar time (as single number)
20
21 INDEX
22 time
23
24 SYNOPSIS
25 #include <time.h>
26 time_t time(time_t *<[t]>);
27
28 DESCRIPTION
29 <<time>> looks up the best available representation of the current
30 time and returns it, encoded as a <<time_t>>. It stores the same
31 value at <[t]> unless the argument is <<NULL>>.
32
33 RETURNS
34 A <<-1>> result means the current time is not available; otherwise the
35 result represents the current time.
36
37 PORTABILITY
38 ANSI C requires <<time>>.
39
40 Supporting OS subroutine required: Some implementations require
41 <<gettimeofday>>.
42 */
43
44 /* Most times we have a system call in newlib/libc/sys/.. to do this job */
45
46 #include <_ansi.h>
47 #include <sys/types.h>
48 #include <sys/time.h>
49
50 time_t
time(time_t * t)51 time (time_t * t)
52 {
53 struct timeval now;
54
55 if (gettimeofday (&now, NULL) < 0)
56 now.tv_sec = (time_t) -1;
57
58 if (t)
59 *t = now.tv_sec;
60 return now.tv_sec;
61 }
62