Skip to content

Instantly share code, notes, and snippets.

@gitryder
Created March 25, 2021 10:36
Show Gist options
  • Save gitryder/4a110032e0d9d9becbc4be1791941a02 to your computer and use it in GitHub Desktop.
Save gitryder/4a110032e0d9d9becbc4be1791941a02 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <dirent.h>
int main(int argc, char *argv[]) {
int i, fd1, fd2;
char *file1, *file2, buf[2];
file1 = argv[1];
file2 = argv[2];
printf("file1=%s file2=%s", file1, file2);
fd1 = open(file1, O_RDONLY, 0777);
fd2 = creat(file2, 0777);
while (i = read(fd1, buf, 1) > 0) {
write(fd2, buf, 1);
remove(file1);
close(fd1);
close(fd2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment