|
5 | 5 |
|
6 | 6 | #include <inttypes.h>
|
7 | 7 |
|
8 |
| -const char* ffDetectSwap(FFlist* result) |
| 8 | +static const char* detectByProcMeminfo(FFlist* result) |
| 9 | +{ |
| 10 | + // For Android |
| 11 | + // Ref: #620 |
| 12 | + char buf[PROC_FILE_BUFFSIZ]; |
| 13 | + ssize_t nRead = ffReadFileData("/proc/meminfo", ARRAY_SIZE(buf) - 1, buf); |
| 14 | + if(nRead < 0) |
| 15 | + return "ffReadFileData(\"/proc/meminfo\", ARRAY_SIZE(buf)-1, buf)"; |
| 16 | + buf[nRead] = '\0'; |
| 17 | + |
| 18 | + uint64_t swapTotal = 0, swapFree = 0; |
| 19 | + |
| 20 | + char *token = NULL; |
| 21 | + if ((token = strstr(buf, "SwapTotal:")) != NULL) |
| 22 | + swapTotal = strtoul(token + strlen("SwapTotal:"), NULL, 10); |
| 23 | + |
| 24 | + if ((token = strstr(buf, "SwapFree:")) != NULL) |
| 25 | + swapFree = strtoul(token + strlen("SwapFree:"), NULL, 10); |
| 26 | + |
| 27 | + FFSwapResult* swap = ffListAdd(result); |
| 28 | + ffStrbufInitStatic(&swap->name, "Total"); |
| 29 | + swap->bytesTotal = swapTotal * 1024lu; |
| 30 | + swap->bytesUsed = (swapTotal - swapFree) * 1024lu; |
| 31 | + |
| 32 | + return NULL; |
| 33 | +} |
| 34 | + |
| 35 | +static const char* detectByProcSwaps(FFlist* result) |
9 | 36 | {
|
10 | 37 | // Ref: #620
|
11 | 38 | char buf[PROC_FILE_BUFFSIZ];
|
@@ -46,3 +73,10 @@ const char* ffDetectSwap(FFlist* result)
|
46 | 73 |
|
47 | 74 | return NULL;
|
48 | 75 | }
|
| 76 | + |
| 77 | +const char* ffDetectSwap(FFlist* result) |
| 78 | +{ |
| 79 | + if (detectByProcSwaps(result) == NULL) |
| 80 | + return NULL; |
| 81 | + return detectByProcMeminfo(result); |
| 82 | +} |
0 commit comments