comparison system/System.cpp @ 1038:cc27f35aa75c cxx11

Introducing the signed 64-bit frame index type, and fixing build failures from inclusion of -Wconversion with -Werror. Not finished yet.
author Chris Cannam
date Tue, 03 Mar 2015 15:18:24 +0000
parents e802e550a1f2
children b14064bd1f97
comparison
equal deleted inserted replaced
1037:bf0e5944289b 1038:cc27f35aa75c
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