blob: c811e669ee86568a5b83782b884e9acfe8ddc5b6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include "log.h"
int copyFile(char * source, char * dest) {
int infd = -1, outfd = -1;
char buf[4096];
int i;
outfd = open(dest, O_CREAT | O_RDWR, 0666);
infd = open(source, O_RDONLY);
if (infd < 0) {
logMessage("failed to open %s: %s", source, strerror(errno));
}
while ((i = read(infd, buf, sizeof(buf))) > 0) {
if (write(outfd, buf, i) != i) break;
}
close(infd);
close(outfd);
return 0;
}
|