mirror of
https://github.com/Tha14/toxic.git
synced 2025-06-30 03:56:45 +02:00
convert bytes for file transfer message, general fixes
This commit is contained in:
@ -31,6 +31,7 @@
|
||||
#include "windows.h"
|
||||
#include "misc_tools.h"
|
||||
#include "settings.h"
|
||||
#include "file_senders.h"
|
||||
|
||||
extern ToxWindow *prompt;
|
||||
extern struct user_settings *user_settings_;
|
||||
@ -261,3 +262,25 @@ int char_rfind(const char *s, char ch, int len)
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/* Converts bytes to appropriate unit and puts in buf as a string */
|
||||
void bytes_convert_str(char *buf, int size, uint64_t bytes)
|
||||
{
|
||||
double conv = bytes;
|
||||
const char *unit;
|
||||
|
||||
if (conv < KiB) {
|
||||
unit = "Bytes";
|
||||
} else if (conv < MiB) {
|
||||
unit = "KiB";
|
||||
conv /= (double) KiB;
|
||||
} else if (conv < GiB) {
|
||||
unit = "MiB";
|
||||
conv /= (double) MiB;
|
||||
} else {
|
||||
unit = "GiB";
|
||||
conv /= (double) GiB;
|
||||
}
|
||||
|
||||
snprintf(buf, size, "%.1f %s", conv, unit);
|
||||
}
|
||||
|
Reference in New Issue
Block a user