Author: Ashok P. Nadkarni <apnmbx-public@yahoo.com>
Tcl-Version: 9.1
State: Final
Type: Project
Created: 2025-12-24
Tcl-Branch: tip-744
Vote: Done
Vote-Summary: Accepted 6/0/0
Votes-For: AN, HO, KW, JN, MC, SL
Votes-Against: none
Votes-Present: none
Abstract
This TIP proposes support for file system paths longer than MAX_PATH on the
Windows platform .
Background
Historically, the Win32 API functions were limited to file system path lengths
of MAX_PATH characters (260) though the file systems themselves could support
longer paths which could be accessed by prefixing the path with a \\?\
sequence which bypasses Win32 processing of paths. Tcl tried to support this to
some extent but with inconsistencies arising from multiple sources - differences
between Win32 and raw NT path syntax and semantics, only partial support in Tcl,
and partial support in Windows.
bc7925fc notes only some of
the issues.
Starting with Windows 10 1607, Microsoft added support for longer paths to the Win32 API (with a few notable exceptions). Enabling the use of these API's requires the system registry to be configured appropriately, and the executable manifest to have an entry indicating the applications supports long paths. Long paths may then be passed to and from Win32 API's without any special treatment.
Adding support for this enhancement requires removal of path length limitations from Tcl's Windows-specific implementation. The other platforms are not affected in any manner.
Specification
Long path support
On Windows 10 version 1607 (corresponding to 10.0.14393) and newer, Tcl will
support native file system paths longer than MAX_PATH so long as the system
had been configured to set the registry value
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled
to 1 and the application executable manifest includes the entry LongPathAware
as described in the Windows SDK. Both these conditions are Microsoft
requirements.
Tcl changes
The tclsh executable manifest will have the LongPathAware entry added and
will therefore support long paths on systems that are configured as above. On
systems which are not configured appropriately, the current path length
restrictions will remain.
There are no changes to the script level commands except that the errors that
were previously reported as ENAMETOOLONG may no longer do so.
At the C API level, extensions must no longer assume path lengths are limited
to MAX_PATH on Windows.
With the exception of temp files (where the Windows API does not support
long paths), the Tcl Windows native path implementation is modified to
allocate dynamically if necessary and not limit paths to MAX_PATH.
Tk changes
The wish executable manifest will have the LongPathAware entry added.
The only place where MAX_PATH is referenced is in the struct ICONRESOURCE
which does not seem to be used anywhere. To prevent future misuse of MAX_PATH
via the struct, this unused struct definition itself has been deletion.
Limitations
Even on long path configured systems, the Windows CreateProcessW API does not
support long paths. Therefore, neither does exec. Further, Tcl or extensions
may not be installed in locations with paths exceeding MAX_PATH. The
implementation has latent support however, so both should work (modulo bugs)
once (and if) Microsoft fixes this limitation. The same also applies to
temporary file related commands. However, in this case, there is no latent
support for longer paths.
While the total path length may exceed MAX_PATH, individual path components
may not. Microsoft documentation is not clear on this but that is what I have
gleaned from the net.
Implementation notes
Implementation is in the tip-744 branch.
Test cases have been added to winFCmd.test to verify all file related commands
when passed long paths.
Copyright
This document has been placed in the public domain.