From 9486a5004ef24a008d2aa2f12c9d5eaecad0c431 Mon Sep 17 00:00:00 2001 From: call-cc Date: Tue, 2 Jun 2020 16:53:42 -0400 Subject: [PATCH] Add -f flag to ln --- src/ln.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ln.c b/src/ln.c index 1ce49f0..96da684 100644 --- a/src/ln.c +++ b/src/ln.c @@ -10,13 +10,16 @@ main(int argc, char *argv[]) printf("Usage: ln oldfile newfile\n"); return 1; } - int opts; - int fd; - while((opts = getopt(argc, argv, "s:")) != -1) + int opts, fd, fflag; + while((opts = getopt(argc, argv, "sf")) != -1) { switch(opts) { - case 's': + case 'f': + fflag=1; + case 's': + if(fflag && (access(argv[3], F_OK) != 1)) + unlink(argv[3]); symlink(argv[2],argv[3]); break; case '?':