[hackers] [sbase] Fix a completely broken ln(1) || sin

From: <git_AT_suckless.org>
Date: Fri, 17 Oct 2014 17:08:20 +0200

commit 353ac69a93322a8c97db2dad3dee47447de77032
Author: sin <sin_AT_2f30.org>
Date: Fri Oct 17 16:03:41 2014 +0100

    Fix a completely broken ln(1)

diff --git a/ln.c b/ln.c
index 8869823..494a4a5 100644
--- a/ln.c
+++ b/ln.c
_AT_@ -1,10 +1,11 @@
 /* See LICENSE file for copyright and license details. */
 #include <errno.h>
+#include <libgen.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <string.h>
+#include <unistd.h>
 #include "util.h"
 
 static void
_AT_@ -32,7 +33,10 @@ main(int argc, char *argv[])
                 usage();
         } ARGEND;
 
- if(sflag) {
+ if (argc == 0 || argc > 2)
+ usage();
+
+ if (sflag) {
                 flink = symlink;
                 fname = "symlink";
         } else {
_AT_@ -40,17 +44,12 @@ main(int argc, char *argv[])
                 fname = "link";
         }
 
- if(argc < 2) {
- if((to = strrchr(argv[0], '/')))
- to++;
- } else {
- to = argv[1];
- }
+ to = argc < 2 ? basename(argv[0]) : argv[1];
 
         if (fflag == true)
- remove(argv[1]);
+ remove(to);
         if (flink(argv[0], to) < 0)
- eprintf("%s:", fname);
+ eprintf("%s %s <- %s:", fname, argv[0], to);
 
         return 0;
 }
Received on Fri Oct 17 2014 - 17:08:20 CEST

This archive was generated by hypermail 2.3.0 : Fri Oct 17 2014 - 17:12:08 CEST