[fpc-pascal] Possible RTFM question: is there something like an IsRootPath() function?

Tomas Hajny XHajT03 at hajny.biz
Mon Aug 20 17:42:27 CEST 2012


On Mon, August 20, 2012 16:28, Mattias Gaertner wrote:
> On Mon, 20 Aug 2012 14:38:05 +0200
> Sven Barth <pascaldragon at googlemail.com> wrote:
>
>> Am 20.08.2012 14:05, schrieb JĂźrgen Hestermann:
>> > Am 2012-08-20 00:17, schrieb Bart:
>> >  > Does fpc have a function that determines if a given paths is the
>> root
>> >  > (e.g. '/' in Linux, 'F:\' in Windows)?
>> >
>> > The question is: For what reason is this function needed? If you use
>> > "subst" on Windows you can make every path to a root path if you want.
>>
>> Maybe because he wants to determine whether a path is absolute or not?
>
> No, for this there is FilenameIsAbsolute in LazUtils.
>
> It is about scanning the directory. Juha needs a simple
> heuristic if the converter should search the parent directory for
> related files.
> Apparently it is a bad idea to scan a root directory.
>
> See
> http://bugs.freepascal.org/view.php?id=22630

If that is the original problem, you could use the following check:

if ExpandFileName (APath+'..'+DirectorySeparator) <> ExpandFileName
(APath) then ...

This is because MS Windows API happily accepts paths containing references
to supposed parent directory of a root directory and silently ignores that
part of the path specification. We do the same in ExpandFileName in order
to remain Delphi compatible (because Delphi apparently relies on a Win32
API call for ExpandFileName whereas FPC has its own cross-platform
implementation). DirectoryExists for 'c:\..\' returns true under Win32 for
the same reason.

Tomas





More information about the fpc-pascal mailing list