Added signatures for the backing system.

This commit is contained in:
2024-02-16 23:26:29 +01:00
parent 332f5ccfd0
commit 66caca4a7f
4 changed files with 53 additions and 53 deletions

View File

@@ -276,53 +276,3 @@ char* read_file(int fd) {
return data;
}
bool copy_file(const char* src, const char* dst, mode_t mode) {
// Open the source file
int src_fd = open(src, O_RDONLY);
if (src_fd == -1) {
log_message(LOG_ERROR, "Failed to open the source file %s (%s).", src, strerror(errno));
return false;
}
// Open the destination file
int dst_fd = open(dst, O_WRONLY | O_CREAT | O_TRUNC, mode);
if (dst_fd == -1) {
log_message(LOG_ERROR, "Failed to open the destination file %s (%s).", dst, strerror(errno));
close(src_fd);
return false;
}
// Copy the file
char buffer[4096];
ssize_t n;
while ((n = read(src_fd, buffer, sizeof(buffer))) > 0) {
if (write(dst_fd, buffer, n) != n) {
log_message(LOG_ERROR, "Failed to write to the destination file %s (%s).", dst, strerror(errno));
close(src_fd);
close(dst_fd);
return false;
}
}
// Check for read errors
if (n < 0) {
log_message(LOG_ERROR, "Failed to read the source file %s (%s).", src, strerror(errno));
close(src_fd);
close(dst_fd);
return false;
}
// Close the files
close(src_fd);
close(dst_fd);
return true;
}