Add -f flag to ln

This commit is contained in:
call-cc 2020-06-02 16:53:42 -04:00
parent f458b93c2b
commit 9486a5004e
1 changed files with 7 additions and 4 deletions

View File

@ -10,13 +10,16 @@ main(int argc, char *argv[])
printf("Usage: ln oldfile newfile\n"); printf("Usage: ln oldfile newfile\n");
return 1; return 1;
} }
int opts; int opts, fd, fflag;
int fd; while((opts = getopt(argc, argv, "sf")) != -1)
while((opts = getopt(argc, argv, "s:")) != -1)
{ {
switch(opts) switch(opts)
{ {
case 'f':
fflag=1;
case 's': case 's':
if(fflag && (access(argv[3], F_OK) != 1))
unlink(argv[3]);
symlink(argv[2],argv[3]); symlink(argv[2],argv[3]);
break; break;
case '?': case '?':