k9core

Unnamed repository
Log | Files | Refs | LICENSE

commit 66dbedad8237c918cb81b0006a1dd8b5a6ac5f6b
parent 36adf5463c5a22abbc190e208bd54900c9ce272f
Author: qorg11 <qorg@vxempire.xyz>
Date:   Tue,  2 Jun 2020 22:25:29 +0200

I hate git.

Diffstat:
MTODO | 2++
Msrc/ln.c | 37+++++++++++++++++++++----------------
2 files changed, 23 insertions(+), 16 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 @@ -1,8 +1,6 @@ #include <stdio.h> #include <unistd.h> -/* TODO -s flag */ - int main(int argc, char *argv[]) { @@ -12,20 +10,27 @@ main(int argc, char *argv[]) printf("Usage: ln oldfile newfile\n"); return 1; } - - int c = getopt(argc, argv, "s"); - if(c == 's') + int opts; + int fd; + /* I am aware that this doesn't conform to style, but it's the only option that actually works */ + while((opts = getopt(argc, argv, "s:")) != -1) { - symlink(argv[2],argv[3]); - return 0; - } - - - int fd = link(argv[1],argv[2]); - if(fd == -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; }