~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to dttools/src/timestamp.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
 
3
Copyright (C) 2005- The University of Notre Dame
 
4
This software is distributed under the GNU General Public License.
 
5
See the file COPYING for details.
 
6
*/
 
7
 
 
8
 
 
9
#include "timestamp.h"
 
10
 
 
11
#include <sys/time.h>
 
12
#include <sys/select.h>
 
13
#include <sys/stat.h>
 
14
 
 
15
time_t timestamp_file( const char *filename )
 
16
{
 
17
        struct stat buf;
 
18
        if(stat(filename,&buf)==0) {
 
19
                return buf.st_mtime;
 
20
        } else {
 
21
                return 0;
 
22
        }
 
23
}
 
24
 
 
25
timestamp_t timestamp_get()
 
26
{
 
27
        struct timeval current;
 
28
        timestamp_t stamp;
 
29
 
 
30
        gettimeofday(&current,0);
 
31
        stamp = ((timestamp_t)current.tv_sec)*1000000 + current.tv_usec;
 
32
 
 
33
        return stamp;
 
34
}
 
35
 
 
36
void timestamp_sleep( timestamp_t interval )
 
37
{
 
38
        struct timeval t;
 
39
 
 
40
        t.tv_sec = interval / 1000000;
 
41
        t.tv_usec = interval % 1000000;
 
42
 
 
43
        select(0,0,0,0,&t);
 
44
}