Please do not use MAXPATHLEN, it is a arbitrary limit, and is not
defined on GNU. Currently this makes libjava (gcc 4.0.0) unbuildable on GNU
since [gcc]/libjava/gnu/java/nio/channels/natFileChannelImpl.cc assumes that
MAXPATHLEN is defined. Please do not use these kind of limits in GNU programs.
Not having MAXPATHLEN is perfectly compliant with POSIX, same goes for
MAXHOSTNAMELEN, PATH_MAX etc.
[gcc]/libjava/java/io/natFilePosix.cc is also broken due to the usage of MAXPATHLEN.
Its easy to fix this for natFileChannelImpl.cc.
For natFilePosix.cc it is not so simple - is there a portable alternative to
realpath() that does not require the use of MAXPATHLEN / PATH_MAX ?
Subject: Bug 21821
Module name: gcc
Changes by: firstname.lastname@example.org 2005-05-30 16:02:40
libjava : ChangeLog
2005-05-30 Bryce McKinlay <email@example.com>
* gnu/java/nio/channels/natFileChannelPosix.cc (open): Don't use
MAXPATHLEN. Format exception message using a StringBuffer instead.
(In reply to comment #2)
> Its easy to fix this for natFileChannelImpl.cc.
Thank you for fixing it!
> For natFilePosix.cc it is not so simple - is there a portable alternative to
> realpath() that does not require the use of MAXPATHLEN / PATH_MAX ?
One can call realpath() with NULL for the second parameter on systems that do
not have MAXPATHLEN/PATH_MAX. You could also use canonicalize_file_name(), but
this is a GNU C library specific function.
-- Function: char * realpath (const char *restrict NAME, char
On systems which define `PATH_MAX'
this means the buffer must be large enough for a pathname of this
size. For systems without limitations on the pathname length the
requirement cannot be met and programs should not call `realpath'
with anything but `NULL' for the second parameter.
-- Function: char * canonicalize_file_name (const char *NAME)
The `canonicalize_file_name' function returns the absolute name of
the file named by NAME which contains no `.', `..' components nor
any repeated path separators (`/') or symlinks. The result is
passed back as the return value of the function in a block of
memory allocated with `malloc'. If the result is not used anymore
the memory should be freed with a call to `free'.
Created attachment 9856 [details]
Remove arbitrary limit in getCanonicalPath().
Here is a portable way of doing realpath().
2005-09-16 Alfred M. Szmidt <firstname.lastname@example.org>
* java/io/natFilePosix.cc (getCanonicalPath): Don't assume that
MAXPATHLEN is defined. Only declare BUF2 if HAVE_REALPATH is
Created attachment 9859 [details]
Remove arbitrary limit in File.Java:createTempFile
This removes the last (to my knowledge) MAXPATHLEN issue in Java.
2005-10-01 Alfred M. Szmidt <email@example.com>
* java/io/natFilePosix.cc (init_native) [!MAXPATHLEN]: Define to 0.
* java/io/File.java (createTempFile): Don't truncate if the system
doesn't have a limit on the length of a file name.
*** Bug 28234 has been marked as a duplicate of this bug. ***
*** Bug 32846 has been marked as a duplicate of this bug. ***
Sorry I missed this for so long.
Please submit these patches to the java-patches mailing list.
It got fixed in CVS.
Fixed so closing.