[Lazarus] FileExistsUTF8 and long paths

Jürgen Hestermann juergen.hestermann at gmx.de
Tue Jan 19 18:46:10 CET 2016


Am 2016-01-17 um 18:12 schrieb Bart:
 > On 1/17/16, Jürgen Hestermann <juergen.hestermann at gmx.de> wrote:
 >> 2. without forward slashes and
 > But then the function would not act on \\?\C:\maxpathchars\foo/bar if
 > you omitted the \\?\, which seems to be the intention of your
 > proposal?

I don't understand.
If the file path is already prepended by \\?\ then
forward slashes would not be resolved by the Win API anyway.
>From https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx

"Note:  File I/O functions in the Windows API convert "/" to "\" as part of converting the
name to an NT-style name, except when using the "\\?\" prefix as detailed in the following sections."

Nevertheless, we can also simply replace all / by \ before handing it over
to the Win API function.


 > If I understood you correctly you would want to have
 > function FileXXXUtf8(Fn) do:
 > begin
 > if (Length(Fn) > MaxPath) and (not StartsWith('\\?\',Fn) then
 >   FileXXXUtf8('\\?\' + Fn)
 > else
 >   OriginalImplementationOfFileXXXUtf8()
 > end;
 > (With the exception of ExpandFilenameUtf8)

Yes, more or less.
Slashes should be converted to backslashes too.

Also, expanding (relative or incomplete) paths can be done
by Lazarus internally so that this would even work with long paths.

 > To me, the better solution would be that a program that must be able
 > to handle this should prepend the prefix itself (and taking care of
 > all relevant issues like expanding, allowing/replacing '/' with '\'
 > etc. beforehand) and then call the FileXXXUtf8 functions on the
 > resulting string.

IMO this is just the wrong approach.
If Lazarus offers functions like FileExists then they should be rock solid.
Otherwise (if I have to find out the glory details anyway) I would
write my own FileExist (which I did now).
I have abandanded already many of these LCL functions because in
the end they did not help me avoiding any work.
There were always side effects that I had to overcome
with self written functions anyway.
So of what use are they?
Not only am I forced to know about all the OS specific details
I also need to find out what and how it has been implemented
in the Lazarus functions.
If I already know everything I can write my own
function that fits my needs much better.





More information about the Lazarus mailing list