aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJose E. Marchesi <jose.marchesi@oracle.com>2025-03-17 16:51:31 +0100
committerJose E. Marchesi <jose.marchesi@oracle.com>2025-03-18 11:19:48 +0100
commit260e0a389a70994d2728b389e6865528557e3933 (patch)
tree42ddc65210f7601585218625af01ea4073f0e115 /gcc
parent31dd621796f9ff30b3df129a0e47c8d2348fa8c3 (diff)
downloadgcc-260e0a389a70994d2728b389e6865528557e3933.zip
gcc-260e0a389a70994d2728b389e6865528557e3933.tar.gz
gcc-260e0a389a70994d2728b389e6865528557e3933.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cobol/cdf-copy.cc24
1 files changed, 16 insertions, 8 deletions
diff --git a/gcc/cobol/cdf-copy.cc b/gcc/cobol/cdf-copy.cc
index dfa3f57..179dbac 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 ) {