On Mon, Mar 17, 2025 at 7:45 PM Jose E. Marchesi <jose.march...@oracle.com> wrote: > > This patch changes gcc/cobol/cdf-copy.cc to use the new ldirname from > libibertay rather than the host's dirname. This removes an include > for libgen.h. > > Regtested in x86_64-linux-gnu by running make check-cobol.
OK to both patches of the series. Thanks, Richard. > gcc/cobol/ChangeLog > > * cdf-copy.cc (copybook_elem_t::open_file): Use ldirname rather > than dirname. > --- > gcc/cobol/cdf-copy.cc | 24 ++++++++++++++++-------- > 1 file changed, 16 insertions(+), 8 deletions(-) > > diff --git a/gcc/cobol/cdf-copy.cc b/gcc/cobol/cdf-copy.cc > index dfa3f57315d..179dbacea93 100644 > --- a/gcc/cobol/cdf-copy.cc > +++ b/gcc/cobol/cdf-copy.cc > @@ -40,7 +40,6 @@ > #include "copybook.h" > > #include <glob.h> > -#include <libgen.h> > > #define COUNT_OF(X) (sizeof(X) / sizeof(X[0])) > > @@ -268,24 +267,33 @@ int > copybook_elem_t::open_file( const char directory[], bool literally ) { > int erc; > char *pattern, *copier = xstrdup(cobol_filename()); > - if( ! directory ) { > - directory = dirname(copier); > - if( 0 == strcmp(".", directory) ) directory = NULL; > + char *dname = NULL; > + > + if ( directory ) { > + dname = xstrdup(directory); > + } else { > + dname = ldirname(copier); > + gcc_assert (dname != NULL); /* out of memory */ > + if( '\0' == dname[0] ) { > + free (dname); > + dname = NULL; > + } > } > > char *path = NULL; > > - if( directory || library.name ) { > - if( directory && library.name ) { > - path = xasprintf( "%s/%s/%s", directory, library.name, source.name ); > + if( dname || library.name ) { > + if( dname && library.name ) { > + path = xasprintf( "%s/%s/%s", dname, library.name, source.name ); > } else { > - const char *dir = directory? directory : library.name; > + const char *dir = dname? dname : library.name; > path = xasprintf( "%s/%s", dir, source.name ); > } > } else { > path = xasprintf( "%s", source.name ); > } > > + free(dname); > gcc_assert(path); > > if( literally ) { > -- > 2.30.2 >