--- /dev/null
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+
+int main(int argc, char *argv[]) {
+
+ int cur, flag_append, flag_force;
+ int fd_from, fd_to, mode;
+ char buf[1];
+
+ flag_append = 0;
+ flag_force = 0;
+
+ while((cur = getopt(argc, argv, "af")) != -1) {
+ switch(cur) {
+
+ case 'a':
+ flag_append = 1;
+ break;
+
+ case 'f':
+ flag_force = 1;
+ break;
+
+ default:
+ printf("invalid argument\n");
+ return 1;
+ }
+ }
+
+ if(argc - optind != 2) {
+
+ printf("invalid number of args\n");
+ return 1;
+
+ } else if(flag_append && flag_force) {
+
+ printf("cannot simultaneously specify overwrite and append\n");
+ return 1;
+ }
+
+ if(access(argv[optind + 1], F_OK) != -1 && !flag_append && !flag_force) {
+
+ printf("destination file already exists, pass -f to overwrite\n");
+ return 1;
+ }
+
+ if(flag_force) mode = O_TRUNC;
+ else if(flag_append) mode = O_APPEND;
+ else mode = O_CREAT;
+
+ fd_from = open(argv[optind], O_RDONLY);
+ fd_to = open(argv[optind + 1], mode | O_WRONLY, S_IRWXU);
+
+ if(fd_from == -1) {
+
+ printf("could not open source file\n");
+ return 1;
+
+ } else if(fd_to == -1 && !flag_force && !flag_append) {
+
+ printf("could not create new destination file\n");
+ return 1;
+
+ } else if(fd_to == -1) {
+
+ }
+
+ while(read(fd_from, buf, 1) == 1)
+ write(fd_to, buf, 1);
+
+ close(fd_from);
+ close(fd_to);
+
+ return 0;
+}