Skip to content

Commit

Permalink
Revert some things
Browse files Browse the repository at this point in the history
  • Loading branch information
Black-Speedy committed Dec 21, 2023
1 parent b8cdec6 commit 33ff3f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 28 deletions.
42 changes: 15 additions & 27 deletions WebShare-Connect/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion WebShare-Connect/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[]);

0 comments on commit 33ff3f2

Please sign in to comment.