Yes
This commit is contained in:
parent
20f7eefb3e
commit
07742fcdb9
2
Makefile
2
Makefile
@ -2,7 +2,7 @@ C_SOURCES:=$(wildcard coreutils/*.c)
|
|||||||
C_TARGETS:=$(patsubst coreutils/%.c,bin/%,$(C_SOURCES))
|
C_TARGETS:=$(patsubst coreutils/%.c,bin/%,$(C_SOURCES))
|
||||||
TARGETS:=$(C_TARGETS)
|
TARGETS:=$(C_TARGETS)
|
||||||
|
|
||||||
CFLAGS:=-s -Os -pedantic -Wall -Wextra
|
CFLAGS:=-s -Os -flto -pedantic -Wall -Wextra
|
||||||
all: bin $(TARGETS)
|
all: bin $(TARGETS)
|
||||||
|
|
||||||
bin/%: coreutils/%.c
|
bin/%: coreutils/%.c
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
char *make_path(const char *src, const char *dst) {
|
char *make_path(const char *src, const char *dst) {
|
||||||
@ -22,6 +23,7 @@ char *make_path(const char *src, const char *dst) {
|
|||||||
|
|
||||||
|
|
||||||
int write_to_file(const char *src, const char *dst) {
|
int write_to_file(const char *src, const char *dst) {
|
||||||
|
int ret = 0;
|
||||||
int ifd = open(src, O_RDONLY);
|
int ifd = open(src, O_RDONLY);
|
||||||
if (ifd < 0)
|
if (ifd < 0)
|
||||||
return 1;
|
return 1;
|
||||||
@ -32,14 +34,27 @@ int write_to_file(const char *src, const char *dst) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char buf[4096];
|
off_t len = lseek(ifd, 0, SEEK_END);
|
||||||
ssize_t len = 0;
|
if (len <= 0)
|
||||||
while ((len = read(ifd, buf, sizeof(buf))))
|
goto EXIT;
|
||||||
write(ofd, buf, len);
|
|
||||||
|
|
||||||
|
void *buf = mmap(NULL, len, PROT_READ, MAP_PRIVATE, ifd, 0);
|
||||||
|
if (buf == MAP_FAILED) {
|
||||||
|
ret = 1;
|
||||||
|
goto EXIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
write(ofd, buf, len);
|
||||||
|
|
||||||
|
if (munmap(buf, len)) {
|
||||||
|
ret = 0;
|
||||||
|
goto EXIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXIT:
|
||||||
close(ifd);
|
close(ifd);
|
||||||
close(ofd);
|
close(ofd);
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int copyf(const char *src, const char *dst) {
|
int copyf(const char *src, const char *dst) {
|
||||||
|
Loading…
Reference in New Issue
Block a user