FreeNOS
lib
libposix
sys
time
gettimeofday.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2015 Niek Linnenbank
3
*
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#include <FreeNOS/User.h>
19
#include <
sys/time.h
>
20
#include <
errno.h
>
21
22
int
gettimeofday
(
struct
timeval
*tv,
struct
timezone
*tz)
23
{
24
Timer::Info
timer;
25
26
// Get current system timer info
27
ProcessCtl
(
SELF
,
InfoTimer
, (
Address
) &timer);
28
29
// Check for a valid frequency
30
if
(timer.frequency == 0)
31
{
32
errno
=
ERANGE
;
33
return
-1;
34
}
35
36
// Fill the output variables
37
tv->
tv_sec
= timer.ticks / timer.frequency;
38
tv->
tv_usec
= (1000000 / timer.frequency) * (timer.ticks % timer.frequency);
39
return
0;
40
}
timezone
Time zone information.
Definition:
time.h:47
errno
C int errno
The lvalue errno is used by many functions to return error values.
timeval::tv_usec
uint tv_usec
Microseconds.
Definition:
time.h:41
Address
unsigned long Address
A memory address.
Definition:
Types.h:131
ProcessCtl
API::Result ProcessCtl(const ProcessID proc, const ProcessOperation op, const Address addr=0, const Address output=0)
Prototype for user applications.
Definition:
ProcessCtl.h:93
Timer::Info
Timer information structure.
Definition:
Timer.h:42
time.h
SELF
#define SELF
Definition:
ProcessID.h:35
InfoTimer
@ InfoTimer
Definition:
ProcessCtl.h:49
gettimeofday
int gettimeofday(struct timeval *tv, struct timezone *tz)
Get current time of day.
Definition:
gettimeofday.cpp:22
timeval::tv_sec
time_t tv_sec
Seconds.
Definition:
time.h:38
timeval
Time value information.
Definition:
time.h:35
ERANGE
#define ERANGE
Result too large.
Definition:
errno.h:259
errno.h
Generated by
1.8.17