2024-07-16 17:37:46 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
2024-07-16 17:38:58 +00:00
|
|
|
bool startswith(char *str, char *sub) {
|
2024-07-16 17:37:46 +00:00
|
|
|
size_t strl = strlen(str);
|
|
|
|
size_t subl = strlen(sub);
|
|
|
|
|
2024-07-16 17:38:58 +00:00
|
|
|
if (subl > strl)
|
2024-07-16 17:37:46 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return strncmp(sub, str, subl) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void size_to_human(char *buf, long size) {
|
|
|
|
char *suffix[] = {"B", "KB", "MB", "GB", "TB"};
|
|
|
|
char length = sizeof(suffix) / sizeof(suffix[0]);
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
double cursize = size;
|
|
|
|
|
|
|
|
if (size > 1024) {
|
|
|
|
for (i = 0; (size / 1024) > 0 && i < length - 1; i++, size /= 1024)
|
|
|
|
cursize = size / 1024.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(buf, "%.02lf%s", cursize, suffix[i]);
|
|
|
|
}
|