int disableprints;
-int printe(PrintType type)
+int printe(const PrintType type)
{
int result = 1;
return result;
}
-int logprint(PrintType type)
+int logprint(const PrintType type)
{
/* buffer needs some extra space for timestamp + infor compared to errorstring */
char timestamp[22], buffer[1060];
return 1;
}
-int dmonth(int month)
+int dmonth(const int month)
{
static int dmon[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int year;
}
}
-int isleapyear(int year)
+int isleapyear(const int year)
{
if (year % 4 != 0) {
return 0;
} PrintType;
/* common functions */
-int printe(PrintType type);
-int logprint(PrintType type);
+int printe(const PrintType type);
+int logprint(const PrintType type);
int verifylogaccess(void);
-int dmonth(int month);
-int isleapyear(int year);
+int dmonth(const int month);
+int isleapyear(const int year);
time_t mosecs(time_t month, time_t updated);
uint64_t countercalc(const uint64_t *a, const uint64_t *b, const short is64bit);
char *strncpy_nt(char *dest, const char *src, size_t n);
printf(" since %s\n\n", datebuff);
indent(10);
- printf("rx: %s", getvalue(interface->rxtotal, 1, 1));
+ printf("rx: %s", getvalue(interface->rxtotal, 1, RT_Normal));
indent(3);
- printf(" tx: %s", getvalue(interface->txtotal, 1, 1));
+ printf(" tx: %s", getvalue(interface->txtotal, 1, RT_Normal));
indent(3);
- printf(" total: %s\n\n", getvalue(interface->rxtotal+interface->txtotal, 1, 1));
+ printf(" total: %s\n\n", getvalue(interface->rxtotal+interface->txtotal, 1, RT_Normal));
indent(3);
printf("monthly\n");
indent(5);
d = localtime(&datalist_i->timestamp);
if (strftime(datebuff, DATEBUFFLEN, cfg.mformat, d)<=8) {
- printf("%*s %s", getpadding(9, datebuff), datebuff, getvalue(datalist_i->rx, 11, 1));
+ printf("%*s %s", getpadding(9, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal));
} else {
- printf("%-*s %s", getpadding(11, datebuff), datebuff, getvalue(datalist_i->rx, 11, 1));
+ printf("%-*s %s", getpadding(11, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal));
}
- printf("%s%s", fieldseparator, getvalue(datalist_i->tx, 11, 1));
- printf("%s%s", fieldseparator, getvalue(datalist_i->rx+datalist_i->tx, 11, 1));
+ printf("%s%s", fieldseparator, getvalue(datalist_i->tx, 11, RT_Normal));
+ printf("%s%s", fieldseparator, getvalue(datalist_i->rx+datalist_i->tx, 11, RT_Normal));
if (cfg.ostyle >= 2) {
if (datalist_i->next == NULL) {
if ( datalist_i->rx == 0 || datalist_i->tx == 0 || (interface->updated-datalist_i->timestamp) == 0 ) {
e_tx = (uint64_t)(datalist_i->tx/(float)(mosecs(datalist_i->timestamp, interface->updated)))*(uint64_t)(dmonth(d->tm_mon)*86400);
}
if (shortmode && cfg.ostyle != 0) {
- printf("%s%s", fieldseparator, getvalue(e_rx+e_tx, 11, 2));
+ printf("%s%s", fieldseparator, getvalue(e_rx+e_tx, 11, RT_Estimate));
} else if (!shortmode) {
printf("%s%s", fieldseparator, gettrafficrate(datalist_i->rx+datalist_i->tx, mosecs(datalist_i->timestamp, interface->updated), 14));
}
printf("------------------------+-------------+------------\n");
}
indent(5);
- printf("estimated %s", getvalue(e_rx, 11, 2));
- printf(" | %s", getvalue(e_tx, 11, 2));
- printf(" | %s", getvalue(e_rx+e_tx, 11, 2));
+ printf("estimated %s", getvalue(e_rx, 11, RT_Estimate));
+ printf(" | %s", getvalue(e_tx, 11, RT_Estimate));
+ printf(" | %s", getvalue(e_rx+e_tx, 11, RT_Estimate));
if (cfg.ostyle >= 2) {
printf(" |\n\n");
} else {
snprintf(datebuff, DATEBUFFLEN, "yesterday");
}
if (strlen(datebuff) <= 8) {
- printf("%*s %s", getpadding(9, datebuff), datebuff, getvalue(datalist_i->rx, 11, 1));
+ printf("%*s %s", getpadding(9, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal));
} else {
- printf("%-*s %s", getpadding(11, datebuff), datebuff, getvalue(datalist_i->rx, 11, 1));
+ printf("%-*s %s", getpadding(11, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal));
}
- printf("%s%s", fieldseparator, getvalue(datalist_i->tx, 11, 1));
- printf("%s%s", fieldseparator, getvalue(datalist_i->rx+datalist_i->tx, 11, 1));
+ printf("%s%s", fieldseparator, getvalue(datalist_i->tx, 11, RT_Normal));
+ printf("%s%s", fieldseparator, getvalue(datalist_i->rx+datalist_i->tx, 11, RT_Normal));
if (cfg.ostyle >= 2) {
if (datalist_i->next == NULL) {
d = localtime(&interface->updated);
e_tx = (uint64_t)((datalist_i->tx)/(float)(d->tm_hour*60+d->tm_min))*1440;
}
if (shortmode && cfg.ostyle != 0) {
- printf("%s%s", fieldseparator, getvalue(e_rx+e_tx, 11, 2));
+ printf("%s%s", fieldseparator, getvalue(e_rx+e_tx, 11, RT_Estimate));
} else if (!shortmode) {
printf("%s%s", fieldseparator, gettrafficrate(datalist_i->rx+datalist_i->tx, d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600), 14));
}
printf("------------------------+-------------+------------\n");
}
indent(5);
- printf("estimated %s", getvalue(e_rx, 11, 2));
- printf(" | %s", getvalue(e_tx, 11, 2));
- printf(" | %s", getvalue(e_rx+e_tx, 11, 2));
+ printf("estimated %s", getvalue(e_rx, 11, RT_Estimate));
+ printf(" | %s", getvalue(e_tx, 11, RT_Estimate));
+ printf(" | %s", getvalue(e_rx+e_tx, 11, RT_Estimate));
if (cfg.ostyle >= 2) {
printf(" |\n");
} else {
}
if (strlen(datebuff)<=9 && listtype != 4) {
- printf(" %*s %s", getpadding(9, datebuff), datebuff, getvalue(datalist_i->rx, 11, 1));
+ printf(" %*s %s", getpadding(9, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal));
} else {
- printf(" %-*s %s", getpadding(11, datebuff), datebuff, getvalue(datalist_i->rx, 11, 1));
+ printf(" %-*s %s", getpadding(11, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal));
}
- printf(" | %s", getvalue(datalist_i->tx, 11, 1));
- printf(" | %s", getvalue(datalist_i->rx+datalist_i->tx, 11, 1));
+ printf(" | %s", getvalue(datalist_i->tx, 11, RT_Normal));
+ printf(" | %s", getvalue(datalist_i->rx+datalist_i->tx, 11, RT_Normal));
if (cfg.ostyle == 3) {
if (datalist_i->next == NULL) {
d = localtime(&interface->updated);
printf(" ");
}
if (strlen(dataend) == 0) {
- printf(" estimated %s", getvalue(e_rx, 11, 2));
- printf(" | %s", getvalue(e_tx, 11, 2));
- printf(" | %s", getvalue(e_rx + e_tx, 11, 2));
+ printf(" estimated %s", getvalue(e_rx, 11, RT_Estimate));
+ printf(" | %s", getvalue(e_tx, 11, RT_Estimate));
+ printf(" | %s", getvalue(e_rx + e_tx, 11, RT_Estimate));
} else {
if (datainfo.count < 100) {
snprintf(datebuff, DATEBUFFLEN, "sum of %"PRIu32"", datainfo.count);
} else {
snprintf(datebuff, DATEBUFFLEN, "sum");
}
- printf(" %9s %s", datebuff, getvalue(datainfo.sumrx, 11, 1));
- printf(" | %s", getvalue(datainfo.sumtx, 11, 1));
- printf(" | %s", getvalue(datainfo.sumrx + datainfo.sumtx, 11, 1));
+ printf(" %9s %s", datebuff, getvalue(datainfo.sumrx, 11, RT_Normal));
+ printf(" | %s", getvalue(datainfo.sumtx, 11, RT_Normal));
+ printf(" | %s", getvalue(datainfo.sumrx + datainfo.sumtx, 11, RT_Normal));
}
if (cfg.ostyle == 3) {
printf(" |");
}
printf("%"PRIu64";", (datalist->rx+datalist->tx)/div);
} else {
- printf("%s;", getvalue(datalist->rx, 1, 1));
- printf("%s;", getvalue(datalist->tx, 1, 1));
- printf("%s;", getvalue(datalist->rx+datalist->tx, 1, 1));
+ printf("%s;", getvalue(datalist->rx, 1, RT_Normal));
+ printf("%s;", getvalue(datalist->tx, 1, RT_Normal));
+ printf("%s;", getvalue(datalist->rx+datalist->tx, 1, RT_Normal));
printf("%s;", gettrafficrate(datalist->rx+datalist->tx, (time_t)(d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600)), 1));
}
} else {
}
printf("%"PRIu64";", (datalist->rx+datalist->tx)/div);
} else {
- printf("%s;", getvalue(datalist->rx, 1, 1));
- printf("%s;", getvalue(datalist->tx, 1, 1));
- printf("%s;", getvalue(datalist->rx+datalist->tx, 1, 1));
+ printf("%s;", getvalue(datalist->rx, 1, RT_Normal));
+ printf("%s;", getvalue(datalist->tx, 1, RT_Normal));
+ printf("%s;", getvalue(datalist->rx+datalist->tx, 1, RT_Normal));
printf("%s;", gettrafficrate(datalist->rx+datalist->tx, mosecs(datalist->timestamp, interface->updated), 1));
}
} else {
printf("%"PRIu64";", interface->txtotal);
printf("%"PRIu64"\n", interface->rxtotal+interface->txtotal);
} else {
- printf("%s;", getvalue(interface->rxtotal, 1, 1));
- printf("%s;", getvalue(interface->txtotal, 1, 1));
- printf("%s\n", getvalue(interface->rxtotal+interface->txtotal, 1, 1));
+ printf("%s;", getvalue(interface->rxtotal, 1, RT_Normal));
+ printf("%s;", getvalue(interface->txtotal, 1, RT_Normal));
+ printf("%s\n", getvalue(interface->rxtotal+interface->txtotal, 1, RT_Normal));
}
timeused(__func__, 0);
}
snprintf(buffer, 32, " %-*s ", getpadding(11, datebuff), datebuff);
}
}
- strncat(buffer, getvalue(datalist_i->rx, 10, 1), 32);
+ strncat(buffer, getvalue(datalist_i->rx, 10, RT_Normal), 32);
strcat(buffer, " ");
- strncat(buffer, getvalue(datalist_i->tx, 10, 1), 32);
+ strncat(buffer, getvalue(datalist_i->tx, 10, RT_Normal), 32);
strcat(buffer, " ");
- strncat(buffer, getvalue(datalist_i->rx+datalist_i->tx, 10, 1), 32);
+ strncat(buffer, getvalue(datalist_i->rx+datalist_i->tx, 10, RT_Normal), 32);
if (cfg.ostyle>2) {
strcat(buffer, " ");
if (datalist_i->next == NULL) {
}
if (strlen(ic->dataend) == 0) {
snprintf(buffer, 32, " estimated ");
- strncat(buffer, getvalue(e_rx, 10, 2), 32);
+ strncat(buffer, getvalue(e_rx, 10, RT_Estimate), 32);
strcat(buffer, " ");
- strncat(buffer, getvalue(e_tx, 10, 2), 32);
+ strncat(buffer, getvalue(e_tx, 10, RT_Estimate), 32);
strcat(buffer, " ");
- strncat(buffer, getvalue(e_rx+e_tx, 10, 2), 32);
+ strncat(buffer, getvalue(e_rx+e_tx, 10, RT_Estimate), 32);
} else {
if (datainfo.count < 100) {
snprintf(datebuff, 16, "sum of %"PRIu32"", datainfo.count);
snprintf(datebuff, 16, "sum");
}
snprintf(buffer, 32, " %9s ", datebuff);
- strncat(buffer, getvalue(datainfo.sumrx, 10, 2), 32);
+ strncat(buffer, getvalue(datainfo.sumrx, 10, RT_Normal), 32);
strcat(buffer, " ");
- strncat(buffer, getvalue(datainfo.sumtx, 10, 2), 32);
+ strncat(buffer, getvalue(datainfo.sumtx, 10, RT_Normal), 32);
strcat(buffer, " ");
- strncat(buffer, getvalue(datainfo.sumrx + datainfo.sumtx, 10, 2), 32);
+ strncat(buffer, getvalue(datainfo.sumrx + datainfo.sumtx, 10, RT_Normal), 32);
}
gdImageString(ic->im, gdFontGetSmall(), textx, texty+8, (unsigned char*)buffer, ic->ctext);
}
snprintf(buffer, 4, "rx ");
- strncat(buffer, getvalue(data_current->rx, 12, 1), 32);
+ strncat(buffer, getvalue(data_current->rx, 12, RT_Normal), 32);
gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+18, (unsigned char*)buffer, ic->ctext);
snprintf(buffer, 4, "tx ");
- strncat(buffer, getvalue(data_current->tx, 12, 1), 32);
+ strncat(buffer, getvalue(data_current->tx, 12, RT_Normal), 32);
gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+30, (unsigned char*)buffer, ic->ctext);
snprintf(buffer, 4, " = ");
- strncat(buffer, getvalue(data_current->rx+data_current->tx, 12, 1), 32);
+ strncat(buffer, getvalue(data_current->rx+data_current->tx, 12, RT_Normal), 32);
gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+44, (unsigned char*)buffer, ic->ctext);
/* yesterday */
}
snprintf(buffer, 4, "rx ");
- strncat(buffer, getvalue(data_previous->rx, 12, 1), 32);
+ strncat(buffer, getvalue(data_previous->rx, 12, RT_Normal), 32);
gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+18, (unsigned char*)buffer, ic->ctext);
snprintf(buffer, 4, "tx ");
- strncat(buffer, getvalue(data_previous->tx, 12, 1), 32);
+ strncat(buffer, getvalue(data_previous->tx, 12, RT_Normal), 32);
gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+30, (unsigned char*)buffer, ic->ctext);
snprintf(buffer, 4, " = ");
- strncat(buffer, getvalue(data_previous->rx+data_previous->tx, 12, 1), 32);
+ strncat(buffer, getvalue(data_previous->rx+data_previous->tx, 12, RT_Normal), 32);
gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+44, (unsigned char*)buffer, ic->ctext);
}
}
snprintf(buffer, 4, "rx ");
- strncat(buffer, getvalue(data_current->rx, 12, 1), 32);
+ strncat(buffer, getvalue(data_current->rx, 12, RT_Normal), 32);
gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+18, (unsigned char*)buffer, ic->ctext);
snprintf(buffer, 4, "tx ");
- strncat(buffer, getvalue(data_current->tx, 12, 1), 32);
+ strncat(buffer, getvalue(data_current->tx, 12, RT_Normal), 32);
gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+30, (unsigned char*)buffer, ic->ctext);
snprintf(buffer, 4, " = ");
- strncat(buffer, getvalue(data_current->rx+data_current->tx, 12, 1), 32);
+ strncat(buffer, getvalue(data_current->rx+data_current->tx, 12, RT_Normal), 32);
gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+44, (unsigned char*)buffer, ic->ctext);
/* previous month */
}
snprintf(buffer, 4, "rx ");
- strncat(buffer, getvalue(data_previous->rx, 12, 1), 32);
+ strncat(buffer, getvalue(data_previous->rx, 12, RT_Normal), 32);
gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+18, (unsigned char*)buffer, ic->ctext);
snprintf(buffer, 4, "tx ");
- strncat(buffer, getvalue(data_previous->tx, 12, 1), 32);
+ strncat(buffer, getvalue(data_previous->tx, 12, RT_Normal), 32);
gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+30, (unsigned char*)buffer, ic->ctext);
snprintf(buffer, 4, " = ");
- strncat(buffer, getvalue(data_previous->rx+data_previous->tx, 12, 1), 32);
+ strncat(buffer, getvalue(data_previous->rx+data_previous->tx, 12, RT_Normal), 32);
gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+44, (unsigned char*)buffer, ic->ctext);
}
gdImageString(ic->im, gdFontGetLarge(), textx+12, texty, (unsigned char*)"all time", ic->ctext);
snprintf(buffer, 4, "rx ");
- strncat(buffer, getvalue(ic->interface.rxtotal, 12, 1), 32);
+ strncat(buffer, getvalue(ic->interface.rxtotal, 12, RT_Normal), 32);
gdImageString(ic->im, gdFontGetSmall(), textx, texty+24, (unsigned char*)buffer, ic->ctext);
snprintf(buffer, 4, "tx ");
- strncat(buffer, getvalue(ic->interface.txtotal, 12, 1), 32);
+ strncat(buffer, getvalue(ic->interface.txtotal, 12, RT_Normal), 32);
gdImageString(ic->im, gdFontGetSmall(), textx, texty+36, (unsigned char*)buffer, ic->ctext);
snprintf(buffer, 4, " = ");
- strncat(buffer, getvalue(ic->interface.rxtotal+ic->interface.txtotal, 12, 1), 32);
+ strncat(buffer, getvalue(ic->interface.rxtotal+ic->interface.txtotal, 12, RT_Normal), 32);
gdImageString(ic->im, gdFontGetSmall(), textx, texty+50, (unsigned char*)buffer, ic->ctext);
d = localtime(&ic->interface.created);
strftime(datebuff, 16, cfg.tformat, d);
return result;
}
-char *getvalue(const uint64_t bytes, const int len, const int type)
+char *getvalue(const uint64_t bytes, const int len, const RequestType type)
{
static char buffer[64];
int i, declen = cfg.defaultdecimals, p = 1024;
uint64_t limit;
- /* request types: 1) normal 2) estimate 3) image scale */
- if (type == 3) {
+ if (type == RT_ImageScale) {
declen = 0;
}
p = 1000;
}
- if ( (type == 2) && (bytes == 0) ){
+ if ( (type == RT_Estimate) && (bytes == 0) ) {
declen = len-(int)strlen(getunitprefix(2))-2;
if (declen < 2) {
declen = 2;
if (i>1) {
snprintf(buffer, 64, "%"DECCONV"*.*f %s", getunitspacing(len, 5), declen, bytes/(double)(getunitdivisor(cfg.unitmode, i+1)), getunitprefix(i+1));
} else {
- if (type == 2) {
+ if (type == RT_Estimate) {
declen = 0;
}
snprintf(buffer, 64, "%"DECCONV"*.*f %s", getunitspacing(len, 2), declen, bytes/(double)(getunitdivisor(cfg.unitmode, i+1)), getunitprefix(i+1));
#define UNITPREFIXCOUNT 7
+typedef enum RequestType {
+ RT_Normal = 1,
+ RT_Estimate,
+ RT_ImageScale
+} RequestType;
+
int spacecheck(const char *path);
void sighandler(int sig);
uint64_t getbtime(void);
-char *getvalue(const uint64_t bytes, const int len, const int type);
+char *getvalue(const uint64_t bytes, const int len, const RequestType type);
int getunitspacing(const int len, const int index);
char *gettrafficrate(const uint64_t bytes, const time_t interval, const int len);
const char *getunitprefix(const int index);
snprintf(buffer2, 128, " %*s tx: %s %*"PRIu64" p/s", paddingwidth, " ", gettrafficrate(tx, LIVETIME, ratewidth), ppswidth, (uint64_t)txp/LIVETIME);
} else {
/* total transfer amount visible */
- snprintf(buffer, 128, " rx: %s %s", gettrafficrate(rx, LIVETIME, ratewidth), getvalue(rxtotal, 1, 1));
- snprintf(buffer2, 128, " %*s tx: %s %s", paddingwidth, " ", gettrafficrate(tx, LIVETIME, ratewidth), getvalue(txtotal, 1, 1));
+ snprintf(buffer, 128, " rx: %s %s", gettrafficrate(rx, LIVETIME, ratewidth), getvalue(rxtotal, 1, RT_Normal));
+ snprintf(buffer2, 128, " %*s tx: %s %s", paddingwidth, " ", gettrafficrate(tx, LIVETIME, ratewidth), getvalue(txtotal, 1, RT_Normal));
}
strcat(buffer, buffer2);
printf(" rx | tx\n");
printf("--------------------------------------+------------------\n");
- printf(" bytes %s", getvalue(rxtotal, 15, 1));
- printf(" | %s", getvalue(txtotal, 15, 1));
+ printf(" bytes %s", getvalue(rxtotal, 15, RT_Normal));
+ printf(" | %s", getvalue(txtotal, 15, RT_Normal));
printf("\n");
printf("--------------------------------------+------------------\n");
printf(" max %s", gettrafficrate(rxmax, LIVETIME, 15));
{
cfg.defaultdecimals = 2;
cfg.unitmode = 0;
- ck_assert_str_eq(getvalue(100, 0, 1), "100 B");
- ck_assert_str_eq(getvalue(1024, 0, 1), "1.00 KiB");
- ck_assert_str_eq(getvalue(1048576, 0, 1), "1.00 MiB");
- ck_assert_str_eq(getvalue(1073741824, 0, 1), "1.00 GiB");
- ck_assert_str_eq(getvalue(1099511627776ULL, 0, 1), "1.00 TiB");
- ck_assert_str_eq(getvalue(1125899906842624ULL, 0, 1), "1.00 PiB");
- ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, 1), "1.00 EiB");
+ ck_assert_str_eq(getvalue(100, 0, RT_Normal), "100 B");
+ ck_assert_str_eq(getvalue(1024, 0, RT_Normal), "1.00 KiB");
+ ck_assert_str_eq(getvalue(1048576, 0, RT_Normal), "1.00 MiB");
+ ck_assert_str_eq(getvalue(1073741824, 0, RT_Normal), "1.00 GiB");
+ ck_assert_str_eq(getvalue(1099511627776ULL, 0, RT_Normal), "1.00 TiB");
+ ck_assert_str_eq(getvalue(1125899906842624ULL, 0, RT_Normal), "1.00 PiB");
+ ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, RT_Normal), "1.00 EiB");
cfg.unitmode = 1;
- ck_assert_str_eq(getvalue(100, 0, 1), "100 B");
- ck_assert_str_eq(getvalue(1024, 0, 1), "1.00 KB");
- ck_assert_str_eq(getvalue(1048576, 0, 1), "1.00 MB");
- ck_assert_str_eq(getvalue(1073741824, 0, 1), "1.00 GB");
- ck_assert_str_eq(getvalue(1099511627776ULL, 0, 1), "1.00 TB");
- ck_assert_str_eq(getvalue(1125899906842624ULL, 0, 1), "1.00 PB");
- ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, 1), "1.00 EB");
+ ck_assert_str_eq(getvalue(100, 0, RT_Normal), "100 B");
+ ck_assert_str_eq(getvalue(1024, 0, RT_Normal), "1.00 KB");
+ ck_assert_str_eq(getvalue(1048576, 0, RT_Normal), "1.00 MB");
+ ck_assert_str_eq(getvalue(1073741824, 0, RT_Normal), "1.00 GB");
+ ck_assert_str_eq(getvalue(1099511627776ULL, 0, RT_Normal), "1.00 TB");
+ ck_assert_str_eq(getvalue(1125899906842624ULL, 0, RT_Normal), "1.00 PB");
+ ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, RT_Normal), "1.00 EB");
cfg.unitmode = 2;
- ck_assert_str_eq(getvalue(100, 0, 1), "100 B");
- ck_assert_str_eq(getvalue(1000, 0, 1), "1.00 kB");
- ck_assert_str_eq(getvalue(1000000, 0, 1), "1.00 MB");
- ck_assert_str_eq(getvalue(1000000000, 0, 1), "1.00 GB");
- ck_assert_str_eq(getvalue(1000000000000ULL, 0, 1), "1.00 TB");
- ck_assert_str_eq(getvalue(1000000000000000ULL, 0, 1), "1.00 PB");
- ck_assert_str_eq(getvalue(1000000000000000000ULL, 0, 1), "1.00 EB");
+ ck_assert_str_eq(getvalue(100, 0, RT_Normal), "100 B");
+ ck_assert_str_eq(getvalue(1000, 0, RT_Normal), "1.00 kB");
+ ck_assert_str_eq(getvalue(1000000, 0, RT_Normal), "1.00 MB");
+ ck_assert_str_eq(getvalue(1000000000, 0, RT_Normal), "1.00 GB");
+ ck_assert_str_eq(getvalue(1000000000000ULL, 0, RT_Normal), "1.00 TB");
+ ck_assert_str_eq(getvalue(1000000000000000ULL, 0, RT_Normal), "1.00 PB");
+ ck_assert_str_eq(getvalue(1000000000000000000ULL, 0, RT_Normal), "1.00 EB");
}
END_TEST
{
cfg.defaultdecimals = 2;
cfg.unitmode = 0;
- ck_assert_str_eq(getvalue(100, 0, 2), "100 B");
- ck_assert_str_eq(getvalue(1024, 0, 2), "1 KiB");
- ck_assert_str_eq(getvalue(1048576, 0, 2), "1.00 MiB");
- ck_assert_str_eq(getvalue(1073741824, 0, 2), "1.00 GiB");
- ck_assert_str_eq(getvalue(1099511627776ULL, 0, 2), "1.00 TiB");
- ck_assert_str_eq(getvalue(1125899906842624ULL, 0, 2), "1.00 PiB");
- ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, 2), "1.00 EiB");
+ ck_assert_str_eq(getvalue(100, 0, RT_Estimate), "100 B");
+ ck_assert_str_eq(getvalue(1024, 0, RT_Estimate), "1 KiB");
+ ck_assert_str_eq(getvalue(1048576, 0, RT_Estimate), "1.00 MiB");
+ ck_assert_str_eq(getvalue(1073741824, 0, RT_Estimate), "1.00 GiB");
+ ck_assert_str_eq(getvalue(1099511627776ULL, 0, RT_Estimate), "1.00 TiB");
+ ck_assert_str_eq(getvalue(1125899906842624ULL, 0, RT_Estimate), "1.00 PiB");
+ ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, RT_Estimate), "1.00 EiB");
cfg.unitmode = 1;
- ck_assert_str_eq(getvalue(100, 0, 2), "100 B");
- ck_assert_str_eq(getvalue(1024, 0, 2), "1 KB");
- ck_assert_str_eq(getvalue(1048576, 0, 2), "1.00 MB");
- ck_assert_str_eq(getvalue(1073741824, 0, 2), "1.00 GB");
- ck_assert_str_eq(getvalue(1099511627776ULL, 0, 2), "1.00 TB");
- ck_assert_str_eq(getvalue(1125899906842624ULL, 0, 2), "1.00 PB");
- ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, 2), "1.00 EB");
+ ck_assert_str_eq(getvalue(100, 0, RT_Estimate), "100 B");
+ ck_assert_str_eq(getvalue(1024, 0, RT_Estimate), "1 KB");
+ ck_assert_str_eq(getvalue(1048576, 0, RT_Estimate), "1.00 MB");
+ ck_assert_str_eq(getvalue(1073741824, 0, RT_Estimate), "1.00 GB");
+ ck_assert_str_eq(getvalue(1099511627776ULL, 0, RT_Estimate), "1.00 TB");
+ ck_assert_str_eq(getvalue(1125899906842624ULL, 0, RT_Estimate), "1.00 PB");
+ ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, RT_Estimate), "1.00 EB");
cfg.unitmode = 2;
- ck_assert_str_eq(getvalue(100, 0, 2), "100 B");
- ck_assert_str_eq(getvalue(1000, 0, 2), "1 kB");
- ck_assert_str_eq(getvalue(1000000, 0, 2), "1.00 MB");
- ck_assert_str_eq(getvalue(1000000000, 0, 2), "1.00 GB");
- ck_assert_str_eq(getvalue(1000000000000ULL, 0, 2), "1.00 TB");
- ck_assert_str_eq(getvalue(1000000000000000ULL, 0, 2), "1.00 PB");
- ck_assert_str_eq(getvalue(1000000000000000000ULL, 0, 2), "1.00 EB");
+ ck_assert_str_eq(getvalue(100, 0, RT_Estimate), "100 B");
+ ck_assert_str_eq(getvalue(1000, 0, RT_Estimate), "1 kB");
+ ck_assert_str_eq(getvalue(1000000, 0, RT_Estimate), "1.00 MB");
+ ck_assert_str_eq(getvalue(1000000000, 0, RT_Estimate), "1.00 GB");
+ ck_assert_str_eq(getvalue(1000000000000ULL, 0, RT_Estimate), "1.00 TB");
+ ck_assert_str_eq(getvalue(1000000000000000ULL, 0, RT_Estimate), "1.00 PB");
+ ck_assert_str_eq(getvalue(1000000000000000000ULL, 0, RT_Estimate), "1.00 EB");
}
END_TEST
{
cfg.defaultdecimals = 2;
cfg.unitmode = 0;
- ck_assert_str_eq(getvalue(100, 0, 3), "100 B");
- ck_assert_str_eq(getvalue(1024, 0, 3), "1 KiB");
- ck_assert_str_eq(getvalue(1048576, 0, 3), "1 MiB");
- ck_assert_str_eq(getvalue(1073741824, 0, 3), "1 GiB");
- ck_assert_str_eq(getvalue(1099511627776ULL, 0,3), "1 TiB");
- ck_assert_str_eq(getvalue(1125899906842624ULL, 0, 3), "1 PiB");
- ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, 3), "1 EiB");
+ ck_assert_str_eq(getvalue(100, 0, RT_ImageScale), "100 B");
+ ck_assert_str_eq(getvalue(1024, 0, RT_ImageScale), "1 KiB");
+ ck_assert_str_eq(getvalue(1048576, 0, RT_ImageScale), "1 MiB");
+ ck_assert_str_eq(getvalue(1073741824, 0, RT_ImageScale), "1 GiB");
+ ck_assert_str_eq(getvalue(1099511627776ULL, 0, RT_ImageScale), "1 TiB");
+ ck_assert_str_eq(getvalue(1125899906842624ULL, 0, RT_ImageScale), "1 PiB");
+ ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, RT_ImageScale), "1 EiB");
cfg.unitmode = 1;
- ck_assert_str_eq(getvalue(100, 0, 3), "100 B");
- ck_assert_str_eq(getvalue(1024, 0, 3), "1 KB");
- ck_assert_str_eq(getvalue(1048576, 0, 3), "1 MB");
- ck_assert_str_eq(getvalue(1073741824, 0, 3), "1 GB");
- ck_assert_str_eq(getvalue(1099511627776ULL, 0, 3), "1 TB");
- ck_assert_str_eq(getvalue(1125899906842624ULL, 0, 3), "1 PB");
- ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, 3), "1 EB");
+ ck_assert_str_eq(getvalue(100, 0, RT_ImageScale), "100 B");
+ ck_assert_str_eq(getvalue(1024, 0, RT_ImageScale), "1 KB");
+ ck_assert_str_eq(getvalue(1048576, 0, RT_ImageScale), "1 MB");
+ ck_assert_str_eq(getvalue(1073741824, 0, RT_ImageScale), "1 GB");
+ ck_assert_str_eq(getvalue(1099511627776ULL, 0, RT_ImageScale), "1 TB");
+ ck_assert_str_eq(getvalue(1125899906842624ULL, 0, RT_ImageScale), "1 PB");
+ ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, RT_ImageScale), "1 EB");
cfg.unitmode = 2;
- ck_assert_str_eq(getvalue(100, 0, 3), "100 B");
- ck_assert_str_eq(getvalue(1000, 0, 3), "1 kB");
- ck_assert_str_eq(getvalue(1000000, 0, 3), "1 MB");
- ck_assert_str_eq(getvalue(1000000000, 0, 3), "1 GB");
- ck_assert_str_eq(getvalue(1000000000000ULL, 0, 3), "1 TB");
- ck_assert_str_eq(getvalue(1000000000000000ULL, 0, 3), "1 PB");
- ck_assert_str_eq(getvalue(1000000000000000000ULL, 0, 3), "1 EB");
+ ck_assert_str_eq(getvalue(100, 0, RT_ImageScale), "100 B");
+ ck_assert_str_eq(getvalue(1000, 0, RT_ImageScale), "1 kB");
+ ck_assert_str_eq(getvalue(1000000, 0, RT_ImageScale), "1 MB");
+ ck_assert_str_eq(getvalue(1000000000, 0, RT_ImageScale), "1 GB");
+ ck_assert_str_eq(getvalue(1000000000000ULL, 0, RT_ImageScale), "1 TB");
+ ck_assert_str_eq(getvalue(1000000000000000ULL, 0, RT_ImageScale), "1 PB");
+ ck_assert_str_eq(getvalue(1000000000000000000ULL, 0, RT_ImageScale), "1 EB");
}
END_TEST
{
cfg.defaultdecimals = 2;
cfg.unitmode = 0;
- ck_assert_str_eq(getvalue(1024, 10, 1), " 1.00 KiB");
+ ck_assert_str_eq(getvalue(1024, 10, RT_Normal), " 1.00 KiB");
cfg.unitmode = 1;
- ck_assert_str_eq(getvalue(1024, 10, 1), " 1.00 KB");
+ ck_assert_str_eq(getvalue(1024, 10, RT_Normal), " 1.00 KB");
cfg.unitmode = 2;
- ck_assert_str_eq(getvalue(1000, 10, 1), " 1.00 kB");
+ ck_assert_str_eq(getvalue(1000, 10, RT_Normal), " 1.00 kB");
}
END_TEST
START_TEST(getvalue_zero_values)
{
cfg.unitmode = 0;
- ck_assert_str_eq(getvalue(0, 0, 1), "0 B");
- ck_assert_str_eq(getvalue(0, 10, 2), " -- ");
- ck_assert_int_eq((int)strlen(getvalue(0, 10, 2)), 10);
- ck_assert_int_eq((int)strlen(getvalue(0, 20, 2)), 20);
- ck_assert_str_eq(getvalue(0, 0, 3), "0 B");
+ ck_assert_str_eq(getvalue(0, 0, RT_Normal), "0 B");
+ ck_assert_str_eq(getvalue(0, 10, RT_Estimate), " -- ");
+ ck_assert_int_eq((int)strlen(getvalue(0, 10, RT_Estimate)), 10);
+ ck_assert_int_eq((int)strlen(getvalue(0, 20, RT_Estimate)), 20);
+ ck_assert_str_eq(getvalue(0, 0, RT_ImageScale), "0 B");
cfg.unitmode = 1;
- ck_assert_str_eq(getvalue(0, 0, 1), "0 B");
- ck_assert_str_eq(getvalue(0, 10, 2), " -- ");
- ck_assert_int_eq((int)strlen(getvalue(0, 10, 2)), 10);
- ck_assert_int_eq((int)strlen(getvalue(0, 20, 2)), 20);
- ck_assert_str_eq(getvalue(0, 0, 3), "0 B");
+ ck_assert_str_eq(getvalue(0, 0, RT_Normal), "0 B");
+ ck_assert_str_eq(getvalue(0, 10, RT_Estimate), " -- ");
+ ck_assert_int_eq((int)strlen(getvalue(0, 10, RT_Estimate)), 10);
+ ck_assert_int_eq((int)strlen(getvalue(0, 20, RT_Estimate)), 20);
+ ck_assert_str_eq(getvalue(0, 0, RT_ImageScale), "0 B");
cfg.unitmode = 2;
- ck_assert_str_eq(getvalue(0, 0, 1), "0 B");
- ck_assert_str_eq(getvalue(0, 10, 2), " -- ");
- ck_assert_int_eq((int)strlen(getvalue(0, 10, 2)), 10);
- ck_assert_int_eq((int)strlen(getvalue(0, 20, 2)), 20);
- ck_assert_str_eq(getvalue(0, 0, 3), "0 B");
+ ck_assert_str_eq(getvalue(0, 0, RT_Normal), "0 B");
+ ck_assert_str_eq(getvalue(0, 10, RT_Estimate), " -- ");
+ ck_assert_int_eq((int)strlen(getvalue(0, 10, RT_Estimate)), 10);
+ ck_assert_int_eq((int)strlen(getvalue(0, 20, RT_Estimate)), 20);
+ ck_assert_str_eq(getvalue(0, 0, RT_ImageScale), "0 B");
}
END_TEST