summaryrefslogtreecommitdiff
path: root/libguile
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-06-04 21:20:15 +0200
committerLudovic Courtès <ludo@gnu.org>2019-06-04 21:24:02 +0200
commit36ad1d24b3d2c174a64c445502a36f19605dbd65 (patch)
treeab03139bea21a023610042fa6875b3836943706d /libguile
parent65d98d8fd290f985e49994f784b02b8e5ce01dd6 (diff)
'basename' correctly handles "/" and "//".
* libguile/filesys.c (scm_basename): Special-case "/" and "//". * test-suite/tests/filesys.test ("basename"): New test prefix.
Diffstat (limited to 'libguile')
-rw-r--r--libguile/filesys.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/libguile/filesys.c b/libguile/filesys.c
index 1a8dfa044..3cf474c05 100644
--- a/libguile/filesys.c
+++ b/libguile/filesys.c
@@ -1602,11 +1602,20 @@ SCM_DEFINE (scm_basename, "basename", 1, 1, 0,
c_filename = scm_to_utf8_string (filename);
scm_dynwind_free (c_filename);
- c_last_component = last_component (c_filename);
- if (!c_last_component)
- res = filename;
+ if (strcmp (c_filename, "/") == 0
+ || strcmp (c_filename, "//") == 0)
+ /* As per
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/basename.html>,
+ "/" and "//" are treated specially. */
+ res = scm_from_utf8_string ("/");
else
- res = scm_from_utf8_string (c_last_component);
+ {
+ c_last_component = last_component (c_filename);
+ if (!c_last_component)
+ res = filename;
+ else
+ res = scm_from_utf8_string (c_last_component);
+ }
scm_dynwind_end ();
if (!SCM_UNBNDP (suffix) &&