2014/10/15 Wed 19:57:03 UTC+9 Bram Moolenaar wrote:
> Ken Takata wrote:
>
> > open() and fopen() are implemented with CreateFileA(), and CreateFileA() can
> > handle maximum MAX_PATH characters (*1).
> > However, some other CRT functions are limited to MAX_PATH bytes (e.g. stat()).
> > This inconsistency causes the problem.
> >
> > (*1) http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx
> > "In the ANSI version of this function, the name is limited to MAX_PATH
> > characters."
> >
> > To avoid this problem, maximum length should be limited to MAX_PATH bytes.
> > (If someone want to handle a file name which is longer than MAX_PATH bytes and
> > shorter than MAX_PATH characters, he should set 'enc' to utf-8.)
> >
> > I wrote a patch to fix this problem.
> > Please check the attached patch.
>
> Can't we fix the places that are restricted to MAX_PATH bytes? If this
> is 256 bytes that's quite short. Perhaps we can change a few places to
> use MAX_PATH * 2, since this appears to be a problem with double-byte
> encodings only.
>
> We could check somewhere that MAX_PATH is 256, and then define another
> variable to 512. Perhaps MAX_PATH_BYTES.
At first, MAX_PATH (or _MAX_PATH) is 260, not 256.
I think there are two problems, if 'enc' is not utf-8:
1. Vim cannot handle a very long filename which is longer than MAX_PATH bytes
and shorter than MAX_PATH characters properly.
2. Vim breaks an existing file if the filename is longer than MAX_PATH bytes
and shorter than MAX_PATH characters. This is a special case of 1 and
a critical problem.
My patch only fixes the problem 2.
I don't think the problem 1 needs to be fixed, because using enc=utf-8 doesn't
have the problem 1. When 'enc' is utf-8, Vim can handle a very long filename
properly.
Using MAX_PATH * 2 bytes doesn't solve the problem 1, because stat(),
FindFirstFileA() or some other API/CRT functions cannot handle longer than
MAX_PATH bytes. E.g. FindFirstFileA() uses WIN32_FIND_DATAA structure (*1)
and its cFileName member is only MAX_PATH bytes.
(*1) http://msdn.microsoft.com/en-us/library/windows/desktop/aa365740.aspx
If we want to use a very long filename even if 'enc' is not utf-8, we should
always use wide APIs on WinNT and later. We need to modify many part and it
has very high risk, I think.
Regards,
Ken Takata