00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifdef HAVE_CONFIG_H
00038 # include <config.h>
00039 #endif
00040
00041 #include <assert.h>
00042 #include <stdio.h>
00043 #include <time.h>
00044
00045 #ifdef WITH_DMALLOC
00046 #include <dmalloc.h>
00047 #endif
00048
00049 #include "lametime.h"
00050
00051 #if !defined(CLOCKS_PER_SEC)
00052 # warning Your system does not define CLOCKS_PER_SEC, guessing one...
00053 # define CLOCKS_PER_SEC 1000000
00054 #endif
00055
00056
00057 double
00058 GetCPUTime(void)
00059 {
00060 clock_t t;
00061
00062 #if defined(_MSC_VER) || defined(__BORLANDC__)
00063 t = clock();
00064 #else
00065 t = clock();
00066 #endif
00067 return t / (double) CLOCKS_PER_SEC;
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 #if defined(__unix__) || defined(SVR4) || defined(BSD)
00081
00082 # include <sys/time.h>
00083 # include <unistd.h>
00084
00085 double
00086 GetRealTime(void)
00087 {
00088 struct timeval t;
00089
00090 if (0 != gettimeofday(&t, NULL))
00091 assert(0);
00092 return t.tv_sec + 1.e-6 * t.tv_usec;
00093 }
00094
00095 #elif defined(WIN16) || defined(WIN32)
00096
00097 # include <stdio.h>
00098 # include <sys/types.h>
00099 # include <sys/timeb.h>
00100
00101 double
00102 GetRealTime(void)
00103 {
00104 struct timeb t;
00105
00106 ftime(&t);
00107 return t.time + 1.e-3 * t.millitm;
00108 }
00109
00110 #else
00111
00112 double
00113 GetRealTime(void)
00114 {
00115 time_t t;
00116
00117 t = time(NULL);
00118 return (double) t;
00119 }
00120
00121 #endif
00122
00123
00124 #if defined(_WIN32) || defined(__CYGWIN__)
00125 # include <io.h>
00126 # include <fcntl.h>
00127 #else
00128 # include <unistd.h>
00129 #endif
00130
00131 int
00132 lame_set_stream_binary_mode(FILE * const fp)
00133 {
00134 #if defined __EMX__
00135 _fsetmode(fp, "b");
00136 #elif defined __BORLANDC__
00137 setmode(_fileno(fp), O_BINARY);
00138 #elif defined __CYGWIN__
00139 setmode(fileno(fp), _O_BINARY);
00140 #elif defined _WIN32
00141 _setmode(_fileno(fp), _O_BINARY);
00142 #else
00143 (void) fp;
00144 #endif
00145 return 0;
00146 }
00147
00148
00149 #if defined(__riscos__)
00150 # include <kernel.h>
00151 # include <sys/swis.h>
00152 #elif defined(_WIN32)
00153 # include <sys/types.h>
00154 # include <sys/stat.h>
00155 #else
00156 # include <sys/stat.h>
00157 #endif
00158
00159 off_t
00160 lame_get_file_size(const char *const filename)
00161 {
00162 struct stat sb;
00163
00164 if (0 == stat(filename, &sb))
00165 return sb.st_size;
00166 return (off_t) - 1;
00167 }
00168
00169