aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-06-17 15:31:58 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2025-06-17 15:31:58 +0530
commit3a33da381d8d42e0bbc70d5f0e79e4d086c759f2 (patch)
tree61134eb82dcf7150de896afb4dd73f5976a8f59d
parent257908233e8fd3a4deec3d0971f4cbcd90c626fd (diff)
(copy_recursively): use sendfile syscall to copy file
-rw-r--r--compromyse.xyz/assets/abc2
-rw-r--r--msg.c15
2 files changed, 12 insertions, 5 deletions
diff --git a/compromyse.xyz/assets/abc b/compromyse.xyz/assets/abc
index 2d05e13..e5177b2 100644
--- a/compromyse.xyz/assets/abc
+++ b/compromyse.xyz/assets/abc
@@ -1 +1 @@
-AHHH
+AHHH1
diff --git a/msg.c b/msg.c
index 0244c73..0360444 100644
--- a/msg.c
+++ b/msg.c
@@ -1,6 +1,7 @@
#define _GNU_SOURCE
#include <ctype.h>
+#include <fcntl.h>
#include <ftw.h>
#include <libgen.h>
#include <mkdio.h>
@@ -8,7 +9,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/sendfile.h>
#include <sys/stat.h>
+#include <unistd.h>
#include "config.h"
@@ -260,12 +263,16 @@ copy_recursively(const char *fpath,
return FTW_CONTINUE;
FILE *in = fopen(fpath, "r");
- FILE *out = fopen(output_path, "w");
-
size_t size = fsize(in);
- char *content = fcontent(in, size);
+ fclose(in);
+
+ int in_fd = open(fpath, O_RDONLY);
+ int out_fd = open(output_path, O_WRONLY | O_CREAT, 0700);
+
+ sendfile(out_fd, in_fd, 0, size);
- fprintf(out, "%s", content);
+ close(in_fd);
+ close(out_fd);
return FTW_CONTINUE;
}