From 33ff3f21bd551fd1521dd5c3be90ef69f216174a Mon Sep 17 00:00:00 2001 From: Black-Speedy Date: Thu, 21 Dec 2023 01:03:24 +0100 Subject: [PATCH] Revert some things --- WebShare-Connect/server.c | 42 ++++++++++++++------------------------- WebShare-Connect/server.h | 1 - 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/WebShare-Connect/server.c b/WebShare-Connect/server.c index 3e73a83..de37d78 100644 --- a/WebShare-Connect/server.c +++ b/WebShare-Connect/server.c @@ -25,34 +25,22 @@ zsock_t* server(void* context, const char *port, int threads) return serv_sock; } -// Function to get file size using stat -long long getFileSize(const char* file_path) { - struct stat st; - if (stat(file_path, &st) == 0) { - return st.st_size; - } else { - perror("stat"); - return -1; // Return -1 if file size retrieval fails - } -} +void server_send(zsock_t* serv_sock, const char* file_path) +{ + // Open file + FILE *fp = fopen(file_path, "rb"); + if (fp == NULL) + { + printf("File open error\n"); + return; + } + + // Determine file size + fseek(fp, 0L, SEEK_END); + int file_size = ftell(fp); + rewind(fp); -void server_send(zsock_t* serv_sock, const char* file_path) { - // Open file - FILE *fp = fopen(file_path, "rb"); - if (fp == NULL) { - printf("File open error\n"); - return; - } - - // Determine file size - long long file_size = getFileSize(file_path); - if (file_size < 0) { - printf("Failed to determine file size\n"); - fclose(fp); - return; - } - - printf("File size: %lld bytes\n", file_size); + printf("File size: %d bytes\n", file_size); int chunk_size; diff --git a/WebShare-Connect/server.h b/WebShare-Connect/server.h index 203f97f..b815f33 100644 --- a/WebShare-Connect/server.h +++ b/WebShare-Connect/server.h @@ -15,6 +15,5 @@ #define FILE_SIZE_50GB 50 * 1000 * 1000 * 1000LL // 50 GiB zsock_t* server(void* context, const char* port, int threads); -off_t getFileSize(const char* file_path); void server_send(zsock_t* serv_sock, const char* output_file_path); int server_main(int argc, char const* argv[]); \ No newline at end of file