On Wed, 2 Dec 2020 15:16:10 -0800, Charles Mills wrote:
>I have some code that compiles both under Windows Visual Studio and z/OS
>XLC.
>
>In Windows the maximum length of a file path is defined by _MAX_PATH and
>__MAX_PATH (I guess MS thinks two macros are better than one).
>
>What is the equivalent macro for XLC? Failing that, what *is* the maximum
>path length so I can define my own macro?
>
>Posix defines PATH_MAX and I see references to it in the z/OS doc but it
>does not seem to be defined for my compile. How do I pick that up? And yes,
>I have
>
>#define _XOPEN_SOURCE_EXTENDED 1
>#include <stdlib.h>
>
PATH_MAX is deprecated (I thought even by POSIX). IBM says this
it is because the value differs among filesystems. Here is some
code where I used the recommended alternative in a call to realpath().
(realpath() is dreadful: an invitation to buffer overflows.)
/* ***************************************** */
/* Doc: Print the resolved pathname of each argument
*/
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <unistd.h>
#undef PATH_MAX
int main( int argc, char ** argv ) {
char **file_name;
int status=0;
for ( file_name = argv; *++file_name; ) {
long PATH_MAX;
if ( ( PATH_MAX = pathconf( *file_name, _PC_PATH_MAX ) )>0 ) {
char *resolved_name;
if ( resolved_name = malloc( PATH_MAX + 1 ) ); {
if ( realpath( *file_name, resolved_name ) ) {
printf( "%s\n", resolved_name );
free( resolved_name );
continue; }
free( resolved_name ); } }
perror( *file_name );
status = 1; }
exit( status ); }
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN