Mercurial > hg > svcore
comparison system/System.cpp @ 1356:39ce813e185c 3.0-integration
Untabify
author | Chris Cannam |
---|---|
date | Mon, 09 Jan 2017 16:39:55 +0000 |
parents | 6b847a59d908 |
children | dca12b13d90b |
comparison
equal
deleted
inserted
replaced
1355:1a7687631136 | 1356:39ce813e185c |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ |
2 | 2 |
3 /* | 3 /* |
4 Sonic Visualiser | 4 Sonic Visualiser |
5 An audio file viewer and annotation editor. | 5 An audio file viewer and annotation editor. |
6 Centre for Digital Music, Queen Mary, University of London. | 6 Centre for Digital Music, Queen Mary, University of London. |
7 This file copyright 2006 Chris Cannam and QMUL. | 7 This file copyright 2006 Chris Cannam and QMUL. |
8 | 8 |
9 This program is free software; you can redistribute it and/or | 9 This program is free software; you can redistribute it and/or |
10 modify it under the terms of the GNU General Public License as | 10 modify it under the terms of the GNU General Public License as |
11 published by the Free Software Foundation; either version 2 of the | 11 published by the Free Software Foundation; either version 2 of the |
12 License, or (at your option) any later version. See the file | 12 License, or (at your option) any later version. See the file |
13 COPYING included with this distribution for more information. | 13 COPYING included with this distribution for more information. |
14 */ | 14 */ |
15 | 15 |
16 #include "System.h" | 16 #include "System.h" |
17 | 17 |
18 #include <QStringList> | 18 #include <QStringList> |
37 | 37 |
38 #include <iostream> | 38 #include <iostream> |
39 | 39 |
40 #ifdef __APPLE__ | 40 #ifdef __APPLE__ |
41 extern "C" { | 41 extern "C" { |
42 void * | 42 void * |
43 rpl_realloc (void *p, size_t n) | 43 rpl_realloc (void *p, size_t n) |
44 { | |
45 p = realloc(p, n); | |
46 if (p == 0 && n == 0) | |
47 { | 44 { |
48 p = malloc(0); | 45 p = realloc(p, n); |
49 } | 46 if (p == 0 && n == 0) |
50 return p; | 47 { |
51 } | 48 p = malloc(0); |
49 } | |
50 return p; | |
51 } | |
52 } | 52 } |
53 #endif | 53 #endif |
54 | 54 |
55 #ifdef _WIN32 | 55 #ifdef _WIN32 |
56 | 56 |
57 extern "C" { | 57 extern "C" { |
58 | 58 |
59 #ifdef _MSC_VER | 59 #ifdef _MSC_VER |
60 void usleep(unsigned long usec) | 60 void usleep(unsigned long usec) |
61 { | 61 { |
62 ::Sleep(usec / 1000); | 62 ::Sleep(usec / 1000); |
63 } | 63 } |
64 #endif | 64 #endif |
65 | 65 |
66 int gettimeofday(struct timeval *tv, void *tz) | 66 int gettimeofday(struct timeval *tv, void *tz) |
67 { | 67 { |
68 union { | 68 union { |
69 long long ns100; | 69 long long ns100; |
70 FILETIME ft; | 70 FILETIME ft; |
71 } now; | 71 } now; |
72 | 72 |
73 ::GetSystemTimeAsFileTime(&now.ft); | 73 ::GetSystemTimeAsFileTime(&now.ft); |
74 tv->tv_usec = (long)((now.ns100 / 10LL) % 1000000LL); | 74 tv->tv_usec = (long)((now.ns100 / 10LL) % 1000000LL); |
75 tv->tv_sec = (long)((now.ns100 - 116444736000000000LL) / 10000000LL); | 75 tv->tv_sec = (long)((now.ns100 - 116444736000000000LL) / 10000000LL); |
76 return 0; | 76 return 0; |
77 } | 77 } |
78 | 78 |
79 } | 79 } |
80 | 80 |
81 #endif | 81 #endif |
82 | 82 |
151 DWORDLONG wtotal = 0; | 151 DWORDLONG wtotal = 0; |
152 | 152 |
153 if (exFound) { | 153 if (exFound) { |
154 | 154 |
155 lMEMORYSTATUSEX lms; | 155 lMEMORYSTATUSEX lms; |
156 lms.dwLength = sizeof(lms); | 156 lms.dwLength = sizeof(lms); |
157 if (!ex(&lms)) { | 157 if (!ex(&lms)) { |
158 cerr << "WARNING: GlobalMemoryStatusEx failed: error code " | 158 cerr << "WARNING: GlobalMemoryStatusEx failed: error code " |
159 << GetLastError() << endl; | 159 << GetLastError() << endl; |
160 return; | 160 return; |
161 } | 161 } |
162 wavail = lms.ullAvailPhys; | 162 wavail = lms.ullAvailPhys; |
163 wtotal = lms.ullTotalPhys; | 163 wtotal = lms.ullTotalPhys; |
164 | 164 |
165 } else { | 165 } else { |
166 | 166 |
167 /* Fall back to GlobalMemoryStatus which is always available. | 167 /* Fall back to GlobalMemoryStatus which is always available. |
168 but returns wrong results for physical memory > 4GB */ | 168 but returns wrong results for physical memory > 4GB */ |
169 | 169 |
170 MEMORYSTATUS ms; | 170 MEMORYSTATUS ms; |
171 GlobalMemoryStatus(&ms); | 171 GlobalMemoryStatus(&ms); |
172 wavail = ms.dwAvailPhys; | 172 wavail = ms.dwAvailPhys; |
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; |
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 ssize_t(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 } |
261 #else | 261 #else |
262 struct statvfs buf; | 262 struct statvfs buf; |
263 if (!statvfs(path, &buf)) { | 263 if (!statvfs(path, &buf)) { |