]> 4ch.mooo.com Git - 16.git/blob - src/lib/dl/ext/lame/lametime.c
refresh wwww
[16.git] / src / lib / dl / ext / lame / lametime.c
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.21 2011/05/07 16:05:17 rbrito 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 #ifdef HAVE_CONFIG_H
38 # include <config.h>
39 #endif
40
41 #include <assert.h>
42 #include <stdio.h>
43 #include <time.h>
44
45 #ifdef WITH_DMALLOC
46 #include <dmalloc.h>
47 #endif
48
49 #include "lametime.h"
50
51 #if !defined(CLOCKS_PER_SEC)
52 # warning Your system does not define CLOCKS_PER_SEC, guessing one...
53 # define CLOCKS_PER_SEC 1000000
54 #endif
55
56
57 double
58 GetCPUTime(void)
59 {
60     clock_t t;
61
62 #if defined(_MSC_VER)  ||  defined(__BORLANDC__)
63     t = clock();
64 #else
65     t = clock();
66 #endif
67     return t / (double) CLOCKS_PER_SEC;
68 }
69
70
71 /*
72  * name:        GetRealTime ( void )
73  *
74  * description: returns real (human) time elapsed relative to a fixed time (mostly 1970-01-01 00:00:00)
75  * input:       none
76  * output:      time in seconds
77  * known bugs:  bad precision with time()
78  */
79
80 #if defined(__unix__)  ||  defined(SVR4)  ||  defined(BSD)
81
82 # include <sys/time.h>
83 # include <unistd.h>
84
85 double
86 GetRealTime(void)
87 {                       /* conforming:  SVr4, BSD 4.3 */
88     struct timeval t;
89
90     if (0 != gettimeofday(&t, NULL))
91         assert(0);
92     return t.tv_sec + 1.e-6 * t.tv_usec;
93 }
94
95 #elif defined(WIN16)  ||  defined(WIN32)
96
97 # include <stdio.h>
98 # include <sys/types.h>
99 # include <sys/timeb.h>
100
101 double
102 GetRealTime(void)
103 {                       /* conforming:  Win 95, Win NT */
104     struct timeb t;
105
106     ftime(&t);
107     return t.time + 1.e-3 * t.millitm;
108 }
109
110 #else
111
112 double
113 GetRealTime(void)
114 {                       /* conforming:  SVr4, SVID, POSIX, X/OPEN, BSD 4.3 */ /* BUT NOT GUARANTEED BY ANSI */
115     time_t  t;
116
117     t = time(NULL);
118     return (double) t;
119 }
120
121 #endif
122
123
124 #if defined(_WIN32) || defined(__CYGWIN__)
125 # include <io.h>
126 # include <fcntl.h>
127 #else
128 # include <unistd.h>
129 #endif
130
131 int
132 lame_set_stream_binary_mode(FILE * const fp)
133 {
134 #if   defined __EMX__
135     _fsetmode(fp, "b");
136 #elif defined __BORLANDC__
137     setmode(_fileno(fp), O_BINARY);
138 #elif defined __CYGWIN__
139     setmode(fileno(fp), _O_BINARY);
140 #elif defined _WIN32
141     _setmode(_fileno(fp), _O_BINARY);
142 #else
143     (void) fp;          /* doing nothing here, silencing the compiler only. */
144 #endif
145     return 0;
146 }
147
148
149 /* End of lametime.c */