From 90180a614f79481a9fbaf1bdb5278908d5724fea Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 12 Apr 2020 21:08:57 +0200 Subject: [PATCH] Fix ln(1) behavior on empty paths and indentation. --- utils/ln.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/utils/ln.c b/utils/ln.c index 3b5d6157..7382dfd9 100644 --- a/utils/ln.c +++ b/utils/ln.c @@ -114,8 +114,6 @@ static bool lnat(const char* source, // Retains the trailing slashes unlike basename(3) so ln foo/ bar/ fails. static const char* basename_with_slashes(const char* path) { - if ( !path || !*path ) - return "."; size_t offset = strlen(path); while ( offset && path[offset - 1] == '/' ) offset--; @@ -186,14 +184,13 @@ static bool ln_into_directory(const char* source, err(1, "malloc"); const char* base_name = basename(source_copy); size_t source_length = strlen(source); - bool has_slash = - source_length && source[source_length - 1] == '/'; + bool has_slash = source_length && source[source_length - 1] == '/'; char* new_target; if ( asprintf(&new_target, - "%s%s%s", - target, - has_slash ? "" : "/", - base_name) < 0 ) + "%s%s%s", + target, + has_slash ? "" : "/", + base_name) < 0 ) err(1, "malloc"); free(source_copy); bool ret = ln(source, new_target, force, symbolic, physical, no_dereference,