File: clock_gettime.c

package info (click to toggle)
player 3.0.2%2Bdfsg-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 16,968 kB
  • sloc: cpp: 118,349; ansic: 34,116; python: 1,710; ruby: 269; tcl: 265; java: 189; makefile: 113; sh: 30; php: 3
file content (50 lines) | stat: -rw-r--r-- 1,464 bytes parent folder | download
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
47
48
49
50
/*
 *  Player - One Hell of a Robot Server
 *  Copyright (C) 2008
 *     Brian Gerkey - Player
 *     Klaas Gadeyne - clock_gettime replacement function
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either 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, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include <stddef.h>
#include <time.h>
#if defined WIN32
  // For struct timeval
  #include <Winsock2.h>
#else
  #include <sys/time.h>
#endif

#include "replace/replace.h"

/* This replacement function originally written by Klass Gadeyne
   for the Orocos Project */
int clock_gettime(int clk_id /*ignored*/, struct timespec *tp)
{
    struct timeval now;
    int rv = gettimeofday(&now, NULL);
    if (rv != 0) 
    {
        tp->tv_sec = 0;
        tp->tv_nsec = 0;
        return rv;
    }
    tp->tv_sec = now.tv_sec;
    tp->tv_nsec = now.tv_usec * 1000;
    return 0;
}