linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* extra slash in current path
@ 2011-06-23 13:14 yuyichao-mit
  2011-06-23 13:17 ` Alessandro Suardi
       [not found] ` <20110623153116.404f2a63.taeuber@bbaw.de>
  0 siblings, 2 replies; 9+ messages in thread
From: yuyichao-mit @ 2011-06-23 13:14 UTC (permalink / raw)
  To: linux-kernel, linux-c-programming

The problem is like this:

$ cd /
$ pwd
/

$ cd /
$ pwd
//

$ cd ///
$ pwd
/

Why can there be a extra slash (and exactly one) in current path? Is
this designed on purpose?
This is not really a big deal but I think it can confuse some program.

Thanks.

Yichao

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: extra slash in current path
  2011-06-23 13:14 extra slash in current path yuyichao-mit
@ 2011-06-23 13:17 ` Alessandro Suardi
       [not found]   ` <BANLkTik3iMqZJiEY1+DYS2T9=+q2x2=5pQ@mail.gmail.com>
       [not found] ` <20110623153116.404f2a63.taeuber@bbaw.de>
  1 sibling, 1 reply; 9+ messages in thread
From: Alessandro Suardi @ 2011-06-23 13:17 UTC (permalink / raw)
  To: yuyichao-mit; +Cc: linux-kernel, linux-c-programming

On Thu, Jun 23, 2011 at 3:14 PM, yuyichao-mit <yuyichao@mit.edu> wrote:
> The problem is like this:
>
> $ cd /
> $ pwd
> /
>
> $ cd /
> $ pwd
> //
>
> $ cd ///
> $ pwd
> /
>
> Why can there be a extra slash (and exactly one) in current path? Is
> this designed on purpose?
> This is not really a big deal but I think it can confuse some program.

Multiple consecutive slashes should not confuse any program.

http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_266

--alessandro

 "There's always a siren singing you to shipwreck"

   (Radiohead, "There There")

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: extra slash in current path
       [not found]   ` <BANLkTik3iMqZJiEY1+DYS2T9=+q2x2=5pQ@mail.gmail.com>
@ 2011-06-23 13:26     ` yuyichao-mit
  0 siblings, 0 replies; 9+ messages in thread
From: yuyichao-mit @ 2011-06-23 13:26 UTC (permalink / raw)
  To: linux-c-programming, linux-kernel

Well, actually, I mean why is // so special if more than two slash at
the beginning of absolute path become only one slash?

Yichao Yu

On Thu, Jun 23, 2011 at 9:17 AM, Alessandro Suardi
<alessandro.suardi@gmail.com> wrote:
> On Thu, Jun 23, 2011 at 3:14 PM, yuyichao-mit <yuyichao@mit.edu> wrote:
>> The problem is like this:
>>
>> $ cd /
>> $ pwd
>> /
>>
>> $ cd /
>> $ pwd
>> //
>>
>> $ cd ///
>> $ pwd
>> /
>>
>> Why can there be a extra slash (and exactly one) in current path? Is
>> this designed on purpose?
>> This is not really a big deal but I think it can confuse some program.
>
> Multiple consecutive slashes should not confuse any program.
>
> http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_266
>
> --alessandro
>
>  "There's always a siren singing you to shipwreck"
>
>    (Radiohead, "There There")
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: extra slash in current path
       [not found]     ` <BANLkTimXH8K91cZ69oPRu=wbYt9JgBadfA@mail.gmail.com>
@ 2011-06-23 14:11       ` yuyichao-mit
  2011-06-23 14:25         ` richard -rw- weinberger
                           ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: yuyichao-mit @ 2011-06-23 14:11 UTC (permalink / raw)
  To: richard -rw- weinberger
  Cc: Lars Täuber, linux-kernel, linux-c-programming

On Thu, Jun 23, 2011 at 9:54 AM, richard -rw- weinberger
<richard.weinberger@gmail.com> wrote:
> On Thu, Jun 23, 2011 at 3:32 PM, yuyichao-mit <yuyichao@mit.edu> wrote:
>> On Thu, Jun 23, 2011 at 9:31 AM, Lars Täuber <taeuber@bbaw.de> wrote:
>>> Hi,
>>>
>>> Am Thu, 23 Jun 2011 09:14:18 -0400
>>> yuyichao-mit <yuyichao@mit.edu> schrieb:
>>>> The problem is like this:
>>>>
>>>> $ cd /
>>>> $ pwd
>>>> /
>>>>
>>>> $ cd /
>>>> $ pwd
>>>> //
>>>
>>> didn't you mean?:
>>> $ cd //
>>> $ pwd
>>> //
>>
>> yes, exactly.
>>
>> Sorry for the typo (copy-paste~~~)
>>
>
> Is this really a kernel issue?
> rw@raccoon:~> cd //
> rw@raccoon://> pwd
> //
> rw@raccoon://> ls -l /proc/self/cwd
> lrwxrwxrwx 1 rw users 0 23. Jun 15:53 /proc/self/cwd -> /

well, that's true, but this is indeed the retrun value of get_current_dir_name.

#include <unistd.h>
#include <stdio.h>

int main()
{
        char *cwd = get_current_dir_name();
        printf("%s\n", cwd);
        return 0;
}

$ cd //
$ pwd
//
$ main
//

so is this a glibc stuff??
(that's y I also send to linux-c-programming.)

>
> --
> Thanks,
> //richard
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: extra slash in current path
  2011-06-23 14:11       ` yuyichao-mit
@ 2011-06-23 14:25         ` richard -rw- weinberger
  2011-06-23 14:27         ` Nick Bowler
  2011-06-23 14:31         ` Michael Tokarev
  2 siblings, 0 replies; 9+ messages in thread
From: richard -rw- weinberger @ 2011-06-23 14:25 UTC (permalink / raw)
  To: yuyichao-mit; +Cc: Lars Täuber, linux-kernel, linux-c-programming

On Thu, Jun 23, 2011 at 4:11 PM, yuyichao-mit <yuyichao@mit.edu> wrote:
> On Thu, Jun 23, 2011 at 9:54 AM, richard -rw- weinberger
> <richard.weinberger@gmail.com> wrote:
>> On Thu, Jun 23, 2011 at 3:32 PM, yuyichao-mit <yuyichao@mit.edu> wrote:
>>> On Thu, Jun 23, 2011 at 9:31 AM, Lars Täuber <taeuber@bbaw.de> wrote:
>>>> Hi,
>>>>
>>>> Am Thu, 23 Jun 2011 09:14:18 -0400
>>>> yuyichao-mit <yuyichao@mit.edu> schrieb:
>>>>> The problem is like this:
>>>>>
>>>>> $ cd /
>>>>> $ pwd
>>>>> /
>>>>>
>>>>> $ cd /
>>>>> $ pwd
>>>>> //
>>>>
>>>> didn't you mean?:
>>>> $ cd //
>>>> $ pwd
>>>> //
>>>
>>> yes, exactly.
>>>
>>> Sorry for the typo (copy-paste~~~)
>>>
>>
>> Is this really a kernel issue?
>> rw@raccoon:~> cd //
>> rw@raccoon://> pwd
>> //
>> rw@raccoon://> ls -l /proc/self/cwd
>> lrwxrwxrwx 1 rw users 0 23. Jun 15:53 /proc/self/cwd -> /
>
> well, that's true, but this is indeed the retrun value of get_current_dir_name.
>
> #include <unistd.h>
> #include <stdio.h>
>
> int main()
> {
>        char *cwd = get_current_dir_name();
>        printf("%s\n", cwd);
>        return 0;
> }
>
> $ cd //
> $ pwd
> //
> $ main
> //
>
> so is this a glibc stuff??

I guess glibc does some caching.

> (that's y I also send to linux-c-programming.)

Ah, ok.

-- 
Thanks,
//richard

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: extra slash in current path
  2011-06-23 14:11       ` yuyichao-mit
  2011-06-23 14:25         ` richard -rw- weinberger
@ 2011-06-23 14:27         ` Nick Bowler
  2011-06-23 14:31         ` Michael Tokarev
  2 siblings, 0 replies; 9+ messages in thread
From: Nick Bowler @ 2011-06-23 14:27 UTC (permalink / raw)
  To: yuyichao-mit
  Cc: richard -rw- weinberger, Lars Täuber, linux-kernel,
	linux-c-programming

On 2011-06-23 10:11 -0400, yuyichao-mit wrote:
> On Thu, Jun 23, 2011 at 9:54 AM, richard -rw- weinberger
> > Is this really a kernel issue?
> > rw@raccoon:~> cd //
> > rw@raccoon://> pwd
> > //
> > rw@raccoon://> ls -l /proc/self/cwd
> > lrwxrwxrwx 1 rw users 0 23. Jun 15:53 /proc/self/cwd -> /
> 
> well, that's true, but this is indeed the retrun value of get_current_dir_name.

glibc's get_current_dir_name will honour the PWD environment variable in some
cases, which is where the // actually comes from (i.e., it does not come
from the kernel).

This funny behaviour of cd is actually specified by POSIX (man 1p cd):

        8. The curpath value shall then be converted to canonical form
           as follows, considering each component from beginning to
           end, in sequence:
[...]
            c. An implementation may further simplify curpath by
               removing any trailing slash characters that are not also
               leading slashes, replacing multiple non-leading
               consecutive slashes with a single slash, and replacing
               three or more leading slashes with a single slash.  If,
               as a result of this canonicalization, the curpath
               variable is null, no further steps shall be taken.

        9. [...] The PWD environment variable shall be set to curpath.

Cheers,
-- 
Nick Bowler, Elliptic Technologies (http://www.elliptictech.com/)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: extra slash in current path
  2011-06-23 14:11       ` yuyichao-mit
  2011-06-23 14:25         ` richard -rw- weinberger
  2011-06-23 14:27         ` Nick Bowler
@ 2011-06-23 14:31         ` Michael Tokarev
  2011-06-23 14:53           ` yuyichao-mit
       [not found]           ` <20110623165206.d88dcbb3.taeuber@bbaw.de>
  2 siblings, 2 replies; 9+ messages in thread
From: Michael Tokarev @ 2011-06-23 14:31 UTC (permalink / raw)
  To: yuyichao-mit
  Cc: richard -rw- weinberger, Lars Täuber, linux-kernel,
	linux-c-programming

23.06.2011 18:11, yuyichao-mit wrote:

>>>> $ cd //
>>>> $ pwd
>>>> //

The current directory is cached in $PWD environment
variable by shell (bash at least).  This variable is
checked in glibc (getcwd() et al) - if it is set and
stat($PWD) is the same as stat("."), that value is used.

It has nothing to do with kernel, probably the issue
is in bash which somehow allows double slash for root
dir (but not triple).

/mjt

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: extra slash in current path
  2011-06-23 14:31         ` Michael Tokarev
@ 2011-06-23 14:53           ` yuyichao-mit
       [not found]           ` <20110623165206.d88dcbb3.taeuber@bbaw.de>
  1 sibling, 0 replies; 9+ messages in thread
From: yuyichao-mit @ 2011-06-23 14:53 UTC (permalink / raw)
  To: Michael Tokarev
  Cc: richard -rw- weinberger, Lars Täuber, linux-kernel,
	linux-c-programming

On Thu, Jun 23, 2011 at 10:31 AM, Michael Tokarev <mjt@tls.msk.ru> wrote:
> 23.06.2011 18:11, yuyichao-mit wrote:
>
>>>>> $ cd //
>>>>> $ pwd
>>>>> //
>
> The current directory is cached in $PWD environment
> variable by shell (bash at least).  This variable is
> checked in glibc (getcwd() et al) - if it is set and
> stat($PWD) is the same as stat("."), that value is used.
>
> It has nothing to do with kernel, probably the issue
> is in bash which somehow allows double slash for root
> dir (but not triple).

u r right. chdir in c and cd in csh doesn't have this problem.

it is bash stuff.

>
> /mjt
>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: extra slash in current path
       [not found]             ` <BANLkTimdzyT6w2LoKtTjhHTKF5d6zWXFGw@mail.gmail.com>
@ 2011-06-23 15:02               ` 俞颐超
  0 siblings, 0 replies; 9+ messages in thread
From: 俞颐超 @ 2011-06-23 15:02 UTC (permalink / raw)
  To: linux-kernel, linux-c-programming

On Thu, Jun 23, 2011 at 10:52 AM, Lars Täuber <taeuber@bbaw.de> wrote:
> Am Thu, 23 Jun 2011 18:31:06 +0400
> Michael Tokarev <mjt@tls.msk.ru> schrieb:
>> 23.06.2011 18:11, yuyichao-mit wrote:
>>
>> >>>> $ cd //
>> >>>> $ pwd
>> >>>> //
>>
>> The current directory is cached in $PWD environment
>> variable by shell (bash at least).  This variable is
>> checked in glibc (getcwd() et al) - if it is set and
>> stat($PWD) is the same as stat("."), that value is used.
>
> It also is somehow cached inside bash/dash for it's built in commands.
> $ cd //
> $ export PWD=5

this PWD=5 is not necessary.

> $ pwd
> //
> $ /bin/pwd
> /

$ export PWD=////
$ /bin/pwd
/
$ pwd
//
$ echo $PWD
////
$ a.out (simply output get_current_dir_name())
////
so getcwd indeed use $PWD (for symlink?) but pwd and /bin/pwd both
simplify the output although bash simplify it in a strange way~~~

~~interesting

>
>
> Regards
> Lars
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-06-23 15:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-23 13:14 extra slash in current path yuyichao-mit
2011-06-23 13:17 ` Alessandro Suardi
     [not found]   ` <BANLkTik3iMqZJiEY1+DYS2T9=+q2x2=5pQ@mail.gmail.com>
2011-06-23 13:26     ` yuyichao-mit
     [not found] ` <20110623153116.404f2a63.taeuber@bbaw.de>
     [not found]   ` <BANLkTinOb-4Xm_W2fmzivk6jBJwjeHYKVA@mail.gmail.com>
     [not found]     ` <BANLkTimXH8K91cZ69oPRu=wbYt9JgBadfA@mail.gmail.com>
2011-06-23 14:11       ` yuyichao-mit
2011-06-23 14:25         ` richard -rw- weinberger
2011-06-23 14:27         ` Nick Bowler
2011-06-23 14:31         ` Michael Tokarev
2011-06-23 14:53           ` yuyichao-mit
     [not found]           ` <20110623165206.d88dcbb3.taeuber@bbaw.de>
     [not found]             ` <BANLkTimdzyT6w2LoKtTjhHTKF5d6zWXFGw@mail.gmail.com>
2011-06-23 15:02               ` 俞颐超

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).