File: clock_gettime.c

package info (click to toggle)
miredo 1.2.6-7.2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,600 kB
  • sloc: sh: 11,947; ansic: 7,823; makefile: 292; sed: 16
file content (46 lines) | stat: -rw-r--r-- 1,604 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * clock_gettime.c - clock_gettime() replacement
 */

/***********************************************************************
 *  Copyright © 2006 Rémi Denis-Courmont.                              *
 *  This program is free software; you can redistribute and/or modify  *
 *  it under the terms of the GNU General Public License as published  *
 *  by the Free Software Foundation; version 2 of the license, or (at  *
 *  your option) any later version.                                    *
 *                                                                     *
 *  This program is distributed in the hope that it will be useful,    *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of     *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               *
 *  See the GNU General Public License for more details.               *
 *                                                                     *
 *  You should have received a copy of the GNU General Public License  *
 *  along with this program; if not, you can get it from:              *
 *  http://www.gnu.org/copyleft/gpl.html                               *
 ***********************************************************************/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <time.h>
#include <sys/time.h>
#include <errno.h>

int clock_gettime (clockid_t clock, struct timespec *ts)
{
	struct timeval tv;

	if (clock != CLOCK_REALTIME)
	{
		errno = EINVAL;
		return -1;
	}

	if (gettimeofday (&tv, NULL))
		return -1;

	ts->tv_sec = tv.tv_sec;
	ts->tv_nsec = tv.tv_usec * 1000;
	return 0;
}