This code has been changed since I last compiled it on Z but I don't think I 
changed that reference. It appears that PATH_MAX went away somewhere between 
V2R2 and V2R4. I see some comments in limits.h that are consistent with that.

I picked up _POSIX_PATH_MAX from limits.h. I am running POSIX(ON). It that a 
valid maximum path length or am I likely to get whacked with a buffer overflow?

Re-stating the question, what is the maximum path length on z/OS UNIX? Can it 
really be true that there is no hard maximum? I really have to ask pathconf() 
every time? No maximum of possible maximums? The maximum is really whatever 
z/OS wants it to be today?

What is FILENAME_MAX, referenced in 
https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.4.0/com.ibm.zos.v2r4.bpxbd00/fldata.htm
 ?

Charles


-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf 
Of Paul Gilmartin
Sent: Wednesday, December 2, 2020 3:25 PM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: C macro for maximum path length?

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 lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to