diff options
author | Jim Meyering <jim@meyering.net> | 2006-03-26 11:59:58 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2006-03-26 11:59:58 +0000 |
commit | a9e9c226dae2afb2d4c0bbbcc68918d00a915aff (patch) | |
tree | 88f6e014a75552338d15d1a89a0b372ab312f885 /src | |
parent | ba3419a626a00de701682d4144ce876e97fbaf8f (diff) | |
download | coreutils-a9e9c226dae2afb2d4c0bbbcc68918d00a915aff.tar.xz |
(main): Don't strip suffix from file system roots.
Diffstat (limited to 'src')
-rw-r--r-- | src/basename.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/basename.c b/src/basename.c index 4450abe39..05fbb66db 100644 --- a/src/basename.c +++ b/src/basename.c @@ -1,5 +1,5 @@ /* basename -- strip directory and suffix from file names - Copyright (C) 1990-1997, 1999-2005 Free Software Foundation, Inc. + Copyright (C) 1990-1997, 1999-2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -126,12 +126,20 @@ main (int argc, char **argv) } name = base_name (argv[optind]); - name[base_len (name)] = '\0'; - - if (argc == optind + 2) + strip_trailing_slashes (name); + + /* Per POSIX, `basename // /' must return `//' on platforms with + distinct //. On platforms with drive letters, this generalizes + to making `basename c: :' return `c:'. This rule is captured by + skipping suffix stripping if base_name returned an absolute path + or a drive letter (only possible if name is a file-system + root). */ + if (argc == optind + 2 && IS_RELATIVE_FILE_NAME (name) + && ! FILE_SYSTEM_PREFIX_LEN (name)) remove_suffix (name, argv[optind + 1]); puts (name); + free (name); exit (EXIT_SUCCESS); } |