Fix ln(1) behavior on empty paths and indentation.

This commit is contained in:
Jonas 'Sortie' Termansen 2020-04-12 21:08:57 +02:00
parent ff1a90c331
commit 90180a614f
1 changed files with 5 additions and 8 deletions

View File

@ -114,8 +114,6 @@ static bool lnat(const char* source,
// Retains the trailing slashes unlike basename(3) so ln foo/ bar/ fails. // Retains the trailing slashes unlike basename(3) so ln foo/ bar/ fails.
static const char* basename_with_slashes(const char* path) static const char* basename_with_slashes(const char* path)
{ {
if ( !path || !*path )
return ".";
size_t offset = strlen(path); size_t offset = strlen(path);
while ( offset && path[offset - 1] == '/' ) while ( offset && path[offset - 1] == '/' )
offset--; offset--;
@ -186,14 +184,13 @@ static bool ln_into_directory(const char* source,
err(1, "malloc"); err(1, "malloc");
const char* base_name = basename(source_copy); const char* base_name = basename(source_copy);
size_t source_length = strlen(source); size_t source_length = strlen(source);
bool has_slash = bool has_slash = source_length && source[source_length - 1] == '/';
source_length && source[source_length - 1] == '/';
char* new_target; char* new_target;
if ( asprintf(&new_target, if ( asprintf(&new_target,
"%s%s%s", "%s%s%s",
target, target,
has_slash ? "" : "/", has_slash ? "" : "/",
base_name) < 0 ) base_name) < 0 )
err(1, "malloc"); err(1, "malloc");
free(source_copy); free(source_copy);
bool ret = ln(source, new_target, force, symbolic, physical, no_dereference, bool ret = ln(source, new_target, force, symbolic, physical, no_dereference,