source: trunk/libs/newlib/src/newlib/libc/time/time.c @ 543

Last change on this file since 543 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 918 bytes
Line 
1/*
2FUNCTION
3<<time>>---get current calendar time (as single number)
4
5INDEX
6        time
7
8SYNOPSIS
9        #include <time.h>
10        time_t time(time_t *<[t]>);
11
12DESCRIPTION
13<<time>> looks up the best available representation of the current
14time and returns it, encoded as a <<time_t>>.  It stores the same
15value at <[t]> unless the argument is <<NULL>>.
16
17RETURNS
18A <<-1>> result means the current time is not available; otherwise the
19result represents the current time.
20
21PORTABILITY
22ANSI C requires <<time>>.
23
24Supporting OS subroutine required: Some implementations require
25<<gettimeofday>>.
26*/
27
28/* Most times we have a system call in newlib/libc/sys/.. to do this job */
29
30#include <_ansi.h>
31#include <reent.h>
32#include <sys/types.h>
33#include <sys/time.h>
34
35time_t
36time (time_t * t)
37{
38  struct timeval now;
39
40  if (_gettimeofday_r (_REENT, &now, NULL) < 0)
41    now.tv_sec = (time_t) -1;
42
43  if (t)
44    *t = now.tv_sec;
45  return now.tv_sec;
46}
Note: See TracBrowser for help on using the repository browser.