irst version on that git repo

This commit is contained in:
patricus 2025-06-17 09:55:07 +02:00
commit 46ccebf956
13 changed files with 844 additions and 0 deletions

19
bytes.c Normal file
View file

@ -0,0 +1,19 @@
#include <stdio.h>
char* format_bytes(size_t bytes) {
static char result[50]; // Static buffer to hold the result string
if (bytes < 1024) {
snprintf(result, sizeof(result), "%zu B", bytes);
} else if (bytes < 1024 * 1024) {
snprintf(result, sizeof(result), "%.2f KB", bytes / 1024.0);
} else if (bytes < 1024 * 1024 * 1024) {
snprintf(result, sizeof(result), "%.2f MB", bytes / (1024.0 * 1024.0));
} else if (bytes < 1024LL * 1024 * 1024 * 1024) {
snprintf(result, sizeof(result), "%.2f GB", bytes / (1024.0 * 1024.0 * 1024.0));
} else {
snprintf(result, sizeof(result), "%.2f TB", bytes / (1024.0 * 1024.0 * 1024.0 * 1024.0));
}
return result;
}