Prof A Olowofoyeku (The African Chief) wrote:
But I have come across a little snag. MSYS is a minimalist POSIX environment for Windows. So, it uses front slashes and all that. My little problem arose with FileExists(). Assume a filename 'foo.cfg'. Expand it into a fully qualified pathname with GPC and it becomes '/d/bar/foo.cfg' (where "/d" is the drive d:).
Does realpath (C function) return that, or did we anything special about it (I don't remember all this)?
It seems that FileExists cannot cope with this expanded filename, or with the alternative after it has been converted by the Slash2OSDir... stuff (i.e., '\d\bar\foo.cfg'). The file is said not to exist. I wrote a little hack to see how I could solve this:
function MSYSPath2DosPath (Const s : String): String; Var i : Cardinal; begin Result := s; {$ifdef __MSYS__} if (Result [1] in ['/', '']) and (Upcase (Result[2]) in ['A'..'Z']) and (Pos (':', Result) = 0) then begin delete (Result, 1, 1); insert (':', Result, 2); end; {$endif} end;
At the return of this routine, '\d\bar\foo.cfg' or '/d/bar/foo.cfg' becomes 'd:\bar\foo.cfg' or 'd:/bar/foo.cfg'. MSYS and FileExists seem to both be happy with either of these results. I am sure that this problem will exist elsewhere in the RTS and not just with FileExists. The question is how we can solve it in the RTS (perhaps in the Slash2OSDir stuff).
Yes, I think so. Is this `/d/foo/...' form supposed to "exist" at all?
And if so, can this be assumed to always mean `d:/foo'? -- At least under old Dos, it could also mean directory `/d/foo' on the current drive. Or are such directories just not supposed to exist, and bad luck otherwise (or they should write `f:/d/foo' then, including the drive)?
If that's not the case, we might have to check for the existence of such a `/d' directory which would be extra programming effort, and might be expensive at runtime to do for every Slash2OSDirSeparator call (which is expected to be a cheap operation, WRT I/O).
If the `/d/foo' form is not supposed to occur in the first place, then I think we should rather fix realpath (and possibly other routines that produce such a form).
Frank