cobol: use ldirname in cdf-copy.cc

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.

gcc/cobol/ChangeLog

	* cdf-copy.cc (copybook_elem_t::open_file): Use ldirname rather
	than dirname.
This commit is contained in:
Jose E. Marchesi 2025-03-17 16:51:31 +01:00
parent 31dd621796
commit 260e0a389a

View file

@ -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 ) {