Put the human_size() function in util.c

This commit is contained in:
Scott Baker 2021-06-04 20:28:55 -07:00 committed by W. Felix Handte
parent 26fab1d963
commit b70175e5ec
3 changed files with 23 additions and 20 deletions

View File

@ -1527,26 +1527,6 @@ FIO_compressZstdFrame(FIO_ctx_t* const fCtx,
return compressedfilesize; return compressedfilesize;
} }
char* human_size(long size, char* str) {
if (size > 1125899906842624L) {
snprintf(str, 7, "%.1fP", (float)size / 1125899906842624L);
} else if (size > 1099511627776L) {
snprintf(str, 7, "%.1fT", (float)size / 1099511627776L);
} else if (size > 1073741824L) {
snprintf(str, 7, "%.1fG", (float)size / 1073741824L);
} else if (size > 1048576L) {
snprintf(str, 7, "%.1fM", (float)size / 1048576L);
} else if (size > 1024) {
snprintf(str, 7, "%.1fK", (float)size / 1024);
} else if (size >= 0) {
snprintf(str, 7, "%dB", size);
} else {
str[0] = '\0';
}
return str;
}
/*! FIO_compressFilename_internal() : /*! FIO_compressFilename_internal() :
* same as FIO_compressFilename_extRess(), with `ress.desFile` already opened. * same as FIO_compressFilename_extRess(), with `ress.desFile` already opened.
* @return : 0 : compression completed correctly, * @return : 0 : compression completed correctly,

View File

@ -121,6 +121,27 @@ int UTIL_requireUserConfirmation(const char* prompt, const char* abortMsg,
* Functions * Functions
***************************************/ ***************************************/
char* human_size(long size, char* str) {
if (size > 1125899906842624L) {
snprintf(str, 7, "%.1fP", (float)size / 1125899906842624L);
} else if (size > 1099511627776L) {
snprintf(str, 7, "%.1fT", (float)size / 1099511627776L);
} else if (size > 1073741824L) {
snprintf(str, 7, "%.1fG", (float)size / 1073741824L);
} else if (size > 1048576L) {
snprintf(str, 7, "%.1fM", (float)size / 1048576L);
} else if (size > 1024) {
snprintf(str, 7, "%.1fK", (float)size / 1024);
} else if (size >= 0) {
snprintf(str, 7, "%dB", size);
} else {
str[0] = '\0';
}
return str;
}
int UTIL_stat(const char* filename, stat_t* statbuf) int UTIL_stat(const char* filename, stat_t* statbuf)
{ {
#if defined(_MSC_VER) #if defined(_MSC_VER)

View File

@ -122,6 +122,8 @@ int UTIL_requireUserConfirmation(const char* prompt, const char* abortMsg, const
#define STRDUP(s) strdup(s) #define STRDUP(s) strdup(s)
#endif #endif
char* human_size(long size, char* str);
/** /**
* Calls platform's equivalent of stat() on filename and writes info to statbuf. * Calls platform's equivalent of stat() on filename and writes info to statbuf.
* Returns success (1) or failure (0). * Returns success (1) or failure (0).