Max_path_length limitation

I’m using: SWI-Prolog version 8.4.2

There is a real show stopper in our application with v8.4.2.
Specifically, it is this artificial limitation of the path length of around 259:

?- absolute_file_name('1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',A).
ERROR: Cannot represent due to `max_path_length'
ERROR: In:
ERROR:   [11] '$absolute_file_name'('1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',_4810)
ERROR:    [9] toplevel_call(user:user: ...) at c:/programs/swi-prolog_8.4.2/boot/toplevel.pl:1158
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.

According to Microsoft the PATH_MAX limit is 260 :frowning: As I understand it, this may be disabled in Windows 10 through the registry. Is it disabled by default in Windows 11? When disabled the max seems to be 32K with an additional max for each component (how high?).

There are probably fairly easy quick work-arounds, i.e., by overruling PATH_MAX while a more principled fix will require some real work. If this is commercial work, please contact me using a personal message.

I get same result using Windows 11 with SWI-Prolog 8.5.5.


I can’t remember the exact details but one should be able to use a Windows symbolic link (guide) for the part of the path that does not change then hopefully the reminder of the path is less than the 260 character limit.

The C header files define PATH_MAX as 260. This doesn’t seem to (always) apply to Windows itself. SWI-Prolog however uses PATH_MAX. If we redefine that we may hit limits further down the pipeline. For some of this, these are the MSVC somewhat POSIX compliant runtime functions. Other parts of the file system API call the Windows native Win32 API.

Raising it a bit should be harmless. Raising the limit to 32K requires some care at several places as some of the functions processing paths allocate several PATH_MAX arrays of wide characters on the C stack while the Windows stacks are by default rather small.

Good old SWI-Prolog v5.9.7 does not have the problem (on the same machine):

1 ?- absolute_file_name('1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',A).
A = 'c:/programs/swi-prolog/bin/1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'.

That is really good old :slight_smile: Most likely it failed to pick up PATH_MAX from the headers and arbitrarily defined it (1024?). @mgondan1 fixed some of that :slight_smile:

Most probably we can restore the old behavior. That is not a proper fix, but might be good enough for 99% of the users.

Yes please restore the old behavior.

Might work with the latest binaries in the daily download section. Not tested.