Mercurial > hg > svcore
comparison system/System.cpp @ 1069:32ab6c48efaa
Merge from branch tonioni
author | Chris Cannam |
---|---|
date | Mon, 20 Apr 2015 09:11:34 +0100 |
parents | b14064bd1f97 |
children | 9cdb4206aceb |
comparison
equal
deleted
inserted
replaced
1036:682d64f05e72 | 1069:32ab6c48efaa |
---|---|
121 } lMEMORYSTATUSEX; | 121 } lMEMORYSTATUSEX; |
122 typedef WINBOOL (WINAPI *PFN_MS_EX) (lMEMORYSTATUSEX*); | 122 typedef WINBOOL (WINAPI *PFN_MS_EX) (lMEMORYSTATUSEX*); |
123 #endif | 123 #endif |
124 | 124 |
125 void | 125 void |
126 GetRealMemoryMBAvailable(int &available, int &total) | 126 GetRealMemoryMBAvailable(ssize_t &available, ssize_t &total) |
127 { | 127 { |
128 available = -1; | 128 available = -1; |
129 total = -1; | 129 total = -1; |
130 | 130 |
131 #ifdef _WIN32 | 131 #ifdef _WIN32 |
173 wtotal = ms.dwTotalPhys; | 173 wtotal = ms.dwTotalPhys; |
174 } | 174 } |
175 | 175 |
176 DWORDLONG size = wavail / 1048576; | 176 DWORDLONG size = wavail / 1048576; |
177 if (size > INT_MAX) size = INT_MAX; | 177 if (size > INT_MAX) size = INT_MAX; |
178 available = int(size); | 178 available = ssize_t(size); |
179 | 179 |
180 size = wtotal / 1048576; | 180 size = wtotal / 1048576; |
181 if (size > INT_MAX) size = INT_MAX; | 181 if (size > INT_MAX) size = INT_MAX; |
182 total = int(size); | 182 total = ssize_t(size); |
183 | 183 |
184 return; | 184 return; |
185 | 185 |
186 #else | 186 #else |
187 #ifdef __APPLE__ | 187 #ifdef __APPLE__ |
241 | 241 |
242 #endif | 242 #endif |
243 #endif | 243 #endif |
244 } | 244 } |
245 | 245 |
246 int | 246 ssize_t |
247 GetDiscSpaceMBAvailable(const char *path) | 247 GetDiscSpaceMBAvailable(const char *path) |
248 { | 248 { |
249 #ifdef _WIN32 | 249 #ifdef _WIN32 |
250 ULARGE_INTEGER available, total, totalFree; | 250 ULARGE_INTEGER available, total, totalFree; |
251 if (GetDiskFreeSpaceExA(path, &available, &total, &totalFree)) { | 251 if (GetDiskFreeSpaceExA(path, &available, &total, &totalFree)) { |
252 __int64 a = available.QuadPart; | 252 __int64 a = available.QuadPart; |
253 a /= 1048576; | 253 a /= 1048576; |
254 if (a > INT_MAX) a = INT_MAX; | 254 if (a > INT_MAX) a = INT_MAX; |
255 return int(a); | 255 return ssize_t(a); |
256 } else { | 256 } else { |
257 cerr << "WARNING: GetDiskFreeSpaceEx failed: error code " | 257 cerr << "WARNING: GetDiskFreeSpaceEx failed: error code " |
258 << GetLastError() << endl; | 258 << GetLastError() << endl; |
259 return -1; | 259 return -1; |
260 } | 260 } |
264 // do the multiplies and divides in this order to reduce the | 264 // do the multiplies and divides in this order to reduce the |
265 // likelihood of arithmetic overflow | 265 // likelihood of arithmetic overflow |
266 // cerr << "statvfs(" << path << ") says available: " << buf.f_bavail << ", block size: " << buf.f_bsize << endl; | 266 // cerr << "statvfs(" << path << ") says available: " << buf.f_bavail << ", block size: " << buf.f_bsize << endl; |
267 uint64_t available = ((buf.f_bavail / 1024) * buf.f_bsize) / 1024; | 267 uint64_t available = ((buf.f_bavail / 1024) * buf.f_bsize) / 1024; |
268 if (available > INT_MAX) available = INT_MAX; | 268 if (available > INT_MAX) available = INT_MAX; |
269 return int(available); | 269 return ssize_t(available); |
270 } else { | 270 } else { |
271 perror("statvfs failed"); | 271 perror("statvfs failed"); |
272 return -1; | 272 return -1; |
273 } | 273 } |
274 #endif | 274 #endif |
321 | 321 |
322 double mod(double x, double y) { return x - (y * floor(x / y)); } | 322 double mod(double x, double y) { return x - (y * floor(x / y)); } |
323 float modf(float x, float y) { return x - (y * floorf(x / y)); } | 323 float modf(float x, float y) { return x - (y * floorf(x / y)); } |
324 | 324 |
325 double princarg(double a) { return mod(a + M_PI, -2 * M_PI) + M_PI; } | 325 double princarg(double a) { return mod(a + M_PI, -2 * M_PI) + M_PI; } |
326 float princargf(float a) { return modf(a + M_PI, -2 * M_PI) + M_PI; } | 326 float princargf(float a) { return float(princarg(a)); } |
327 | 327 |