Thread overview | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
November 16, 2005 Phobos bug - std.path.getDirName() - Windows | ||||
---|---|---|---|---|
| ||||
Under Windows, getDirName() returns incorrect results if you have a directory that uses forward slashes. Here's the source of the function: char[] getDirName(char[] fullname) out (result) { assert(result.length <= fullname.length); } body { uint i; for (i = fullname.length; i > 0; i--) { version(Win32) { if (fullname[i - 1] == ':') break; if (fullname[i - 1] == '\\') { i--; break; } } version(linux) { if (fullname[i - 1] == '/') { i--; break; } } } return fullname[0 .. i]; } The line if (fullname[i - 1] == '\\') Should be if (fullname[i - 1] == '\\' || fullname[i - 1] == '/') Looking through std.path, it looks like the problem could also occur with std.path.join(). |
November 16, 2005 Re: Phobos bug - std.path.getDirName() - Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | In article <dle8k6$1e6$1@digitaldaemon.com>, Jarrett Billingsley says... > >Under Windows, getDirName() returns incorrect results if you have a directory that uses forward slashes. Here's the source of the function: > >char[] getDirName(char[] fullname) > out (result) > { > assert(result.length <= fullname.length); > } > body > { > uint i; > > for (i = fullname.length; i > 0; i--) > { > version(Win32) > { > if (fullname[i - 1] == ':') > break; > if (fullname[i - 1] == '\\') > { i--; > break; > } > } > version(linux) > { > if (fullname[i - 1] == '/') > { i--; > break; > } > } > } > return fullname[0 .. i]; > } > >The line > > if (fullname[i - 1] == '\\') > >Should be > > if (fullname[i - 1] == '\\' || fullname[i - 1] == '/') Why? Is forward slash Windows path separator? Maybe i'm missing your point, but it looks good to me. :D Tom |
November 16, 2005 Re: Phobos bug - std.path.getDirName() - Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomás Rossi | On Wed, 16 Nov 2005 13:14:02 +0000 (UTC), Tomás Rossi wrote: > In article <dle8k6$1e6$1@digitaldaemon.com>, Jarrett Billingsley says... >> >>Under Windows, getDirName() returns incorrect results if you have a directory that uses forward slashes. Here's the source of the function: >> >>char[] getDirName(char[] fullname) >> out (result) >> { >> assert(result.length <= fullname.length); >> } >> body >> { >> uint i; >> >> for (i = fullname.length; i > 0; i--) >> { >> version(Win32) >> { >> if (fullname[i - 1] == ':') >> break; >> if (fullname[i - 1] == '\\') >> { i--; >> break; >> } >> } >> version(linux) >> { >> if (fullname[i - 1] == '/') >> { i--; >> break; >> } >> } >> } >> return fullname[0 .. i]; >> } >> >>The line >> >> if (fullname[i - 1] == '\\') >> >>Should be >> >> if (fullname[i - 1] == '\\' || fullname[i - 1] == '/') > > Why? Is forward slash Windows path separator? > Maybe i'm missing your point, but it looks good to me. :D Yes it is. At least in the NT family. Try this ... dir c:\ dir c:/ dir "c:/" The first and third works, but the second fails. The rule seems to be, that when an unambiguous path is used, the path delimiter can be either '/' or '\'. However, the '\' is the preferred form. Some DOS and Windows programs don't seem to recognise this so its best not to output '/' in paths. -- Derek Parnell Melbourne, Australia 17/11/2005 12:30:24 AM |
November 16, 2005 Re: Phobos bug - std.path.getDirName() - Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | In article <4x0gom8gt8e7$.1jsl2jogqx0w$.dlg@40tude.net>, Derek Parnell says... > >On Wed, 16 Nov 2005 13:14:02 +0000 (UTC), Tomás Rossi wrote: > >> In article <dle8k6$1e6$1@digitaldaemon.com>, Jarrett Billingsley says... >>> >>>Under Windows, getDirName() returns incorrect results if you have a directory that uses forward slashes. Here's the source of the function: >>> >>>char[] getDirName(char[] fullname) >>> out (result) >>> { >>> assert(result.length <= fullname.length); >>> } >>> body >>> { >>> uint i; >>> >>> for (i = fullname.length; i > 0; i--) >>> { >>> version(Win32) >>> { >>> if (fullname[i - 1] == ':') >>> break; >>> if (fullname[i - 1] == '\\') >>> { i--; >>> break; >>> } >>> } >>> version(linux) >>> { >>> if (fullname[i - 1] == '/') >>> { i--; >>> break; >>> } >>> } >>> } >>> return fullname[0 .. i]; >>> } >>> >>>The line >>> >>> if (fullname[i - 1] == '\\') >>> >>>Should be >>> >>> if (fullname[i - 1] == '\\' || fullname[i - 1] == '/') >> >> Why? Is forward slash Windows path separator? >> Maybe i'm missing your point, but it looks good to me. :D > >Yes it is. At least in the NT family. > >Try this ... > > dir c:\ > > dir c:/ > > dir "c:/" > >The first and third works, but the second fails. > >The rule seems to be, that when an unambiguous path is used, the path delimiter can be either '/' or '\'. However, the '\' is the preferred form. Some DOS and Windows programs don't seem to recognise this so its best not to output '/' in paths. Perhaps you're right though I don't think it's a pretty Windows-Standard path separator. Don't work in many situations so I don't think it should be trated as an accepted one and I wouldn't recomend its use. Not sure if it can be called formally a bug, maybe just an D-unsupported Windows path separator. Despite this, it'd be harmless and also useful to support it in this functions, as Jarret suggests. Tom |
November 16, 2005 Re: Phobos bug - std.path.getDirName() - Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomás Rossi | Tomás Rossi wrote:
> Perhaps you're right though I don't think it's a pretty Windows-Standard path
> separator. Don't work in many situations so I don't think it should be trated as
> an accepted one and I wouldn't recomend its use. Not sure if it can be called
> formally a bug, maybe just an D-unsupported Windows path separator. Despite
> this, it'd be harmless and also useful to support it in this functions, as
> Jarret suggests.
>
> Tom
It would definitely make it easier to create more portable programs. No need to every time search'n'replace those. AFAIK most GNU-programs support both separators in Windows/DOS. I think even Java supports both syntaxes. Originally it was a stupid idea to make people use ; instead of : in path-variables and \ instead of /. I assume the only reason was to create a vendor lock-in?
|
November 16, 2005 Re: Phobos bug - std.path.getDirName() - Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomás Rossi | "Tomás Rossi" <Tomás_member@pathlink.com> wrote in message news:dlffgl$17j9$1@digitaldaemon.com... > In article <4x0gom8gt8e7$.1jsl2jogqx0w$.dlg@40tude.net>, Derek Parnell says... >> >>On Wed, 16 Nov 2005 13:14:02 +0000 (UTC), Tomás Rossi wrote: >> >>> In article <dle8k6$1e6$1@digitaldaemon.com>, Jarrett Billingsley says... >>>> >>>>Under Windows, getDirName() returns incorrect results if you have a directory that uses forward slashes. Here's the source of the function: >>>> >>>>char[] getDirName(char[] fullname) >>>> out (result) >>>> { >>>> assert(result.length <= fullname.length); >>>> } >>>> body >>>> { >>>> uint i; >>>> >>>> for (i = fullname.length; i > 0; i--) >>>> { >>>> version(Win32) >>>> { >>>> if (fullname[i - 1] == ':') >>>> break; >>>> if (fullname[i - 1] == '\\') >>>> { i--; >>>> break; >>>> } >>>> } >>>> version(linux) >>>> { >>>> if (fullname[i - 1] == '/') >>>> { i--; >>>> break; >>>> } >>>> } >>>> } >>>> return fullname[0 .. i]; >>>> } >>>> >>>>The line >>>> >>>> if (fullname[i - 1] == '\\') >>>> >>>>Should be >>>> >>>> if (fullname[i - 1] == '\\' || fullname[i - 1] == '/') >>> >>> Why? Is forward slash Windows path separator? >>> Maybe i'm missing your point, but it looks good to me. :D >> >>Yes it is. At least in the NT family. >> >>Try this ... >> >> dir c:\ >> >> dir c:/ >> >> dir "c:/" >> >>The first and third works, but the second fails. >> >>The rule seems to be, that when an unambiguous path is used, the path >>delimiter can be either '/' or '\'. However, the '\' is the preferred >>form. >>Some DOS and Windows programs don't seem to recognise this so its best not >>to output '/' in paths. > > Perhaps you're right though I don't think it's a pretty Windows-Standard > path > separator. Don't work in many situations so I don't think it should be > trated as > an accepted one and I wouldn't recomend its use. Not sure if it can be > called > formally a bug, maybe just an D-unsupported Windows path separator. > Despite > this, it'd be harmless and also useful to support it in this functions, as > Jarret suggests. I read somewhere that "/" has been standard in Windows since version 1.0. Therefore I'd say its omission in Phobos is a bug. > > Tom |
November 16, 2005 Re: Phobos bug - std.path.getDirName() - Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to John C | "John C" <johnch_atms@hotmail.com> wrote in message news:dlfp25$1on7$1@digitaldaemon.com... > I read somewhere that "/" has been standard in Windows since version 1.0. Therefore I'd say its omission in Phobos is a bug. Using '/' as a path separator in windows works sometimes, and does not work sometimes. It should be avoided. |
November 16, 2005 Re: Phobos bug - std.path.getDirName() - Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
>
> Using '/' as a path separator in windows works sometimes, and does not work
> sometimes. It should be avoided.
Does anyone know why DOS used a '\' as a path separator to begin with? UNIX and C had been around for ages already--using the C escape signifier for a path separator instead of the established UNIX '/' convention just seems kind of silly.
Sean
|
November 16, 2005 Re: Phobos bug - std.path.getDirName() - Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to John C | On Wed, 16 Nov 2005 17:08:19 -0000, John C wrote: > "Tomás Rossi" <Tomás_member@pathlink.com> wrote in message news:dlffgl$17j9$1@digitaldaemon.com... >> In article <4x0gom8gt8e7$.1jsl2jogqx0w$.dlg@40tude.net>, Derek Parnell says... >>> >>>On Wed, 16 Nov 2005 13:14:02 +0000 (UTC), Tomás Rossi wrote: >>> >>>> In article <dle8k6$1e6$1@digitaldaemon.com>, Jarrett Billingsley says... >>>>> >>>>>Under Windows, getDirName() returns incorrect results if you have a directory that uses forward slashes. Here's the source of the function: >>>>> >>>>>char[] getDirName(char[] fullname) >>>>> out (result) >>>>> { >>>>> assert(result.length <= fullname.length); >>>>> } >>>>> body >>>>> { >>>>> uint i; >>>>> >>>>> for (i = fullname.length; i > 0; i--) >>>>> { >>>>> version(Win32) >>>>> { >>>>> if (fullname[i - 1] == ':') >>>>> break; >>>>> if (fullname[i - 1] == '\\') >>>>> { i--; >>>>> break; >>>>> } >>>>> } >>>>> version(linux) >>>>> { >>>>> if (fullname[i - 1] == '/') >>>>> { i--; >>>>> break; >>>>> } >>>>> } >>>>> } >>>>> return fullname[0 .. i]; >>>>> } >>>>> >>>>>The line >>>>> >>>>> if (fullname[i - 1] == '\\') >>>>> >>>>>Should be >>>>> >>>>> if (fullname[i - 1] == '\\' || fullname[i - 1] == '/') >>>> >>>> Why? Is forward slash Windows path separator? >>>> Maybe i'm missing your point, but it looks good to me. :D >>> >>>Yes it is. At least in the NT family. >>> >>>Try this ... >>> >>> dir c:\ >>> >>> dir c:/ >>> >>> dir "c:/" >>> >>>The first and third works, but the second fails. >>> >>>The rule seems to be, that when an unambiguous path is used, the path >>>delimiter can be either '/' or '\'. However, the '\' is the preferred >>>form. >>>Some DOS and Windows programs don't seem to recognise this so its best not >>>to output '/' in paths. >> >> Perhaps you're right though I don't think it's a pretty Windows-Standard >> path >> separator. Don't work in many situations so I don't think it should be >> trated as >> an accepted one and I wouldn't recomend its use. Not sure if it can be >> called >> formally a bug, maybe just an D-unsupported Windows path separator. >> Despite >> this, it'd be harmless and also useful to support it in this functions, as >> Jarret suggests. > > I read somewhere that "/" has been standard in Windows since version 1.0. Therefore I'd say its omission in Phobos is a bug. Not quite. There was a low level API (BIOS) call to set the Switch delimiter from "/" to something else and that influenced the path separator determination. -- Derek Parnell Melbourne, Australia 17/11/2005 8:26:44 AM |
November 16, 2005 Re: Phobos bug - std.path.getDirName() - Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | On Wed, 16 Nov 2005 11:48:40 -0800, Sean Kelly wrote: > Walter Bright wrote: >> >> Using '/' as a path separator in windows works sometimes, and does not work sometimes. It should be avoided. > > Does anyone know why DOS used a '\' as a path separator to begin with? UNIX and C had been around for ages already--using the C escape signifier for a path separator instead of the established UNIX '/' convention just seems kind of silly. > DOS was based on an earlier operating system (CP/M) and that made the decision for Gates. As to why *that* used a "/" is an exercise for the reader. -- Derek Parnell Melbourne, Australia 17/11/2005 8:28:14 AM |
Copyright © 1999-2021 by the D Language Foundation