commit bdbe212df78bb9d2bf40b87861b50d7dfafba2b0
parent 3843efd08f765ff51539e65b1c6cca84c05c2b93
Author: call-cc <callcc@vxempire.xyz>
Date: Tue, 2 Jun 2020 16:19:26 -0400
Add to TODO and clean up ln
Diffstat:
M | TODO | | | 2 | ++ |
M | src/ln.c | | | 34 | ++++++++++++++++++++-------------- |
2 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/TODO b/TODO
@@ -1,3 +1,4 @@
* The rest of programs.
* Manuals
* flags for the programs
+* fix yes (constantly returns y when no argument is passed)
+\ No newline at end of file
diff --git a/src/ln.c b/src/ln.c
@@ -12,20 +12,26 @@ main(int argc, char *argv[])
printf("Usage: ln oldfile newfile\n");
return 1;
}
-
- int c = getopt(argc, argv, "s");
- if(c == 's')
- {
- symlink(argv[2],argv[3]);
- return 0;
- }
-
-
- int fd = link(argv[1],argv[2]);
- if(fd == -1)
+ int opts;
+ int fd;
+ while((opts = getopt(argc, argv, "s:")) != -1)
{
- fprintf(stderr,"Error creating link\n");
- return 1;
+ switch(opts)
+ {
+ case 's':
+ symlink(argv[2],argv[3]);
+ break;
+ case '?':
+ printf("-%c: Argument not found", optopt);
+ break;
+ default:
+ fd = link(argv[1],argv[2]);
+ if(fd == -1)
+ {
+ fprintf(stderr,"Error creating link\n");
+ return 1;
+ }
+ return 0;
+ }
}
- return 0;
}