[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bugs in dirname module
From: |
Paul Eggert |
Subject: |
Re: bugs in dirname module |
Date: |
Wed, 16 Nov 2005 12:50:19 -0800 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
Eric Blake <address@hidden> writes:
> OK, how about this approach: continue with the current rule that base_name
> always returns a pointer into the original string without modification.
> On systems where drive prefixes exist, have base_name("a:") return "" (it
> is a root), but base_name("foo/a:b") return "a:b". Then provide a second
> function, abase_name, which malloc()s the memory for storing the last
> component. Normally it will just strdup() the base_name of the original
> string, but it does the right thing where base_name is empty (a root, so
> abase_name("a:") gives "a:" instead of "") or where base_name results in a
> drive letter (a multi-component path, so abase_name("foo/a:b") results in
> "./a:b").
I'm trying to map this to the bigger picture, and coming up empty.
Among other things, I don't like having "" be a special case.
How about the following idea instead? Let's omit abase_name and just
have base_name. Then we use this rule:
If you have a valid file name F, then accessing F is the same as
chdir(dir_name(F)) followed by accessing base_name(F). Furthermore
if you successfully { chdir(dir_name(F)); rename(base_name(F),"foo"); },
you have renamed F to a file named "foo" in the same directory that F was in.
If we go this route, then base_name(F) cannot in general yield a
suffix of F even on Unix systems, since we would want dir_name("a/b/")
== "a/b" and base_name("a/b/") == ".". Hence base_name will need to
allocate memory in general, even on Unix. On Cygwin it will need it
to compute "./a:b".
Also, src/dirname.c and src/basename.c will have to be modified to
strip redundant trailing slashes before invoking dir_name and
base_name.
- Re: bugs in dirname module, (continued)
Re: bugs in dirname module, Eric Blake, 2005/11/08
- Re: bugs in dirname module, Bruno Haible, 2005/11/09
- Re: bugs in dirname module, Paul Eggert, 2005/11/09
- Re: bugs in dirname module, Eric Blake, 2005/11/09
- Re: bugs in dirname module, Paul Eggert, 2005/11/10
- Re: bugs in dirname module, Eric Blake, 2005/11/10
- Re: bugs in dirname module, Paul Eggert, 2005/11/11
- Re: bugs in dirname module, Eric Blake, 2005/11/11
- Re: bugs in dirname module,
Paul Eggert <=
- Re: bugs in dirname module, Eric Blake, 2005/11/17
- Re: bugs in dirname module, Paul Eggert, 2005/11/17
Re: bugs in dirname module, Jim Meyering, 2005/11/17
Re: bugs in dirname module, Eric Blake, 2005/11/17
Re: bugs in dirname module, Eric Blake, 2005/11/17