Skip to content

Commit

Permalink
transfer: explicity typecast to float in size report
Browse files Browse the repository at this point in the history
* Fixes the file size being reported as 0.00M when size was less than 1M

* Thanks for the reports, On the scale of 0 to 10, I rate myself as retard.

* Kill trailing white spaces while we are at it.

Signed-off-by: dev-harsh1998 <[email protected]>
  • Loading branch information
dev-harsh1998 committed Mar 29, 2019
1 parent dbabf1e commit 45eca71
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions transfer.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Copyright (C) 2018, Harshit Jain
* Copyright (C) 2019, Harshit Jain
*/

#include <stdbool.h>
Expand Down Expand Up @@ -75,16 +75,16 @@ int main(int argc, char *argv[]) {
const char curl[5] = "curl";
static bool x;

#ifdef UPLOAD_MULTIPLE
#ifdef UPLOAD_MULTIPLE
int holder = argc;
int q;
#endif
#endif

x = can_run_command(curl);
/* Only run the uploader when curl binary is found & is executable */
if (x) {

#ifdef UPLOAD_MULTIPLE
#ifdef UPLOAD_MULTIPLE
/* Argument check */
if (argc <= 1) {
printf("ERROR: This binary expects atleast one command "
Expand All @@ -97,7 +97,7 @@ int main(int argc, char *argv[]) {
}
printf("\n");
/* Display names of file (Ignore the first argument as its transfer itself) */
for (q = 1; q < holder; q++) {
for (q = 1; q < holder; q++) {
printf("File no. %d is %s\n", q, argv[q]);
}
printf("\n");
Expand All @@ -116,17 +116,17 @@ int main(int argc, char *argv[]) {
if (getenv("TRANSFER_DISABLE_FILESIZE") == NULL) {
static struct stat st;
#ifdef UPLOAD_MULTIPLE
for (q = 1; q < holder; q++) {
for (q = 1; q < holder; q++) {
stat(argv[q], &st);
const float mb = st.st_size / 1048576;
const float mb = (float)st.st_size / 1048576;
printf("The size of the %d file going to be uploaded is near to %.2f "
"megabytes\n", q, mb);
}
}
#else
stat(argv[1], &st);
// convert bytes to mb (devide by 1024*1024)
const float mb = st.st_size / 1048576;
const float mb = (float)st.st_size / 1048576;
printf("The size of the file going to be uploaded is near to %.2f "
"megabytes\n",
mb);
Expand All @@ -150,7 +150,7 @@ int main(int argc, char *argv[]) {
#endif
#else
#ifdef UPLOAD_MULTIPLE
for (q = 1; q < holder; q++) {
for (q = 1; q < holder; q++) {
sprintf(cmdbuf, "curl -T %s %s", argv[q], "https://transfer.sh");
ret = uploader(cmdbuf);
printf("\n");
Expand Down

0 comments on commit 45eca71

Please sign in to comment.