r123: Merged HEAD and TEST. New stuff shall be committed to HEAD from now on.
[cinelerra_cv/mob.git] / plugins / lame / lametime.c
blob093f53c88fd5a2b6366af90681acc918e4755873
1 /*
2 * Lame time routines source file
4 * Copyright (c) 2000 Mark Taylor
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.
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.
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.
22 /* $Id: lametime.c,v 1.1.1.2 2003/06/16 20:01:21 herman Exp $ */
25 * name: GetCPUTime ( void )
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
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)?
37 #ifdef HAVE_CONFIG_H
38 # include <config.h>
39 #endif
41 #include <assert.h>
42 #include <stdio.h>
43 #include <time.h>
45 #ifdef WITH_DMALLOC
46 #include <dmalloc.h>
47 #endif
49 #include "lametime.h"
52 double GetCPUTime ( void )
54 clock_t t;
56 #if defined(_MSC_VER) || defined(__BORLANDC__)
57 t = clock ();
58 #else
59 t = clock ();
60 #endif
61 return t / (double) CLOCKS_PER_SEC;
66 * name: GetRealTime ( void )
68 * description: returns real (human) time elapsed relative to a fixed time (mostly 1970-01-01 00:00:00)
69 * input: none
70 * output: time in seconds
71 * known bugs: bad precision with time()
74 #if defined(__unix__) || defined(SVR4) || defined(BSD)
76 # include <sys/time.h>
77 # include <unistd.h>
79 double GetRealTime ( void ) /* conforming: SVr4, BSD 4.3 */
81 struct timeval t;
83 if ( 0 != gettimeofday (&t, NULL) )
84 assert (0);
85 return t.tv_sec + 1.e-6 * t.tv_usec;
88 #elif defined(WIN16) || defined(WIN32)
90 # include <stdio.h>
91 # include <sys/types.h>
92 # include <sys/timeb.h>
94 double GetRealTime ( void ) /* conforming: Win 95, Win NT */
96 struct timeb t;
98 ftime ( &t );
99 return t.time + 1.e-3 * t.millitm;
102 #else
104 double GetRealTime ( void ) /* conforming: SVr4, SVID, POSIX, X/OPEN, BSD 4.3 */
105 { /* BUT NOT GUARANTEED BY ANSI */
106 time_t t;
108 t = time (NULL);
109 return (double) t;
112 #endif
115 #if defined(_WIN32) || defined(__CYGWIN__)
116 # include <io.h>
117 # include <fcntl.h>
118 #else
119 # include <unistd.h>
120 #endif
122 int lame_set_stream_binary_mode ( FILE* const fp )
124 #if defined __EMX__
125 _fsetmode ( fp, "b" );
126 #elif defined __BORLANDC__
127 setmode (_fileno(fp), O_BINARY );
128 #elif defined __CYGWIN__
129 setmode ( fileno(fp), _O_BINARY );
130 #elif defined _WIN32
131 _setmode (_fileno(fp), _O_BINARY );
132 #endif
133 return 0;
137 #if defined(__riscos__)
138 # include <kernel.h>
139 # include <sys/swis.h>
140 #elif defined(_WIN32)
141 # include <sys/types.h>
142 # include <sys/stat.h>
143 #else
144 # include <sys/stat.h>
145 #endif
147 off_t lame_get_file_size ( const char* const filename )
149 struct stat sb;
151 if ( 0 == stat ( filename, &sb ) )
152 return sb.st_size;
153 return (off_t) -1;
156 /* End of lametime.c */