Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/*
2
 *	Lame time routines source file
3
 *
4
 *	Copyright (c) 2000 Mark Taylor
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Library General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
14
 * Library General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Library General Public
17
 * License along with this library; if not, write to the
18
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
 * Boston, MA 02111-1307, USA.
20
 */
21
 
22
/* $Id: lametime.c,v 1.10 2001/02/26 18:57:20 markt Exp $ */
23
 
24
/*
25
 * name:        GetCPUTime ( void )
26
 *
27
 * description: returns CPU time used by the process
28
 * input:       none
29
 * output:      time in seconds
30
 * known bugs:  may not work in SMP and RPC
31
 * conforming:  ANSI C
32
 *
33
 * There is some old difficult to read code at the end of this file.
34
 * Can someone integrate this into this function (if useful)?
35
 */
36
 
37
#define _BSD_EXTENSION
38
 
39
#ifdef HAVE_CONFIG_H
40
# include <config.h>
41
#endif
42
 
43
#include <stdio.h>
44
#include <stdlib.h>
45
#include <unistd.h>
46
#include <assert.h>
47
#include <time.h>
48
#include <sys/types.h>
49
#include <sys/stat.h>
50
#include <sys/time.h>
51
 
52
#include "lametime.h"
53
 
54
double GetCPUTime ( void )
55
{
56
    return clock () / (double) CLOCKS_PER_SEC;
57
}
58
 
59
/*
60
 * name:        GetRealTime ( void )
61
 *
62
 * description: returns real (human) time elapsed relative to a fixed time (mostly 1970-01-01 00:00:00)
63
 * input:       none
64
 * output:      time in seconds
65
 * known bugs:  bad precision with time()
66
 */
67
 
68
double GetRealTime ( void )			/* conforming:  SVr4, BSD 4.3 */
69
{
70
    struct timeval  t;
71
 
72
    if ( 0 != gettimeofday (&t, NULL) )
73
        assert (0);
74
    return t.tv_sec + 1.e-6 * t.tv_usec;
75
} 
76
 
77
int  lame_set_stream_binary_mode ( FILE* const fp )
78
{
79
    return 0;
80
}
81
 
82
off_t  lame_get_file_size ( const char* const filename )
83
{
84
    struct stat       sb;
85
 
86
    if ( 0 == stat ( filename, &sb ) )
87
        return sb.st_size;
88
    return (off_t) -1;
89
}