Skip to content

Commit

Permalink
Merge SVN 4384
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeclerck committed Jun 17, 2024
1 parent bd4b5ea commit e974a32
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 36 deletions.
5 changes: 5 additions & 0 deletions libcob/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,11 @@
having only its POINTER be "external" and use cob_file_malloc to allocate
and set the attributes

2021-09-28 Simon Sobisch <[email protected]>

* common.c (cob_gettmpdir): do the lookup and validation only once,
also ensure for TMPDIR that it has no trailing slash

2021-09-27 Simon Sobisch <[email protected]>

* common.c (call_exit_handlers_and_terminate): extracted from
Expand Down
72 changes: 42 additions & 30 deletions libcob/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -5642,45 +5642,57 @@ check_valid_env_tmpdir (const char *envname)
static const char *
cob_gettmpdir (void)
{
const char *tmpdir;
static const char *tmpdir = NULL;
char *tmp;

if ((tmpdir = check_valid_env_tmpdir ("TMPDIR")) == NULL) {
tmp = NULL;
if (tmpdir != NULL) {
return tmpdir;
}

tmp = NULL;
/* target directory, also used by most called external tools*/
if ((tmpdir = check_valid_env_tmpdir ("TMPDIR")) == NULL
/* OS specific temporary paths */
#ifdef _WIN32
if ((tmpdir = check_valid_env_tmpdir ("TEMP")) == NULL
&& (tmpdir = check_valid_env_tmpdir ("TMP")) == NULL
&& (tmpdir = check_valid_env_tmpdir ("USERPROFILE")) == NULL) {
&& (tmpdir = check_valid_env_tmpdir ("TEMP")) == NULL
&& (tmpdir = check_valid_env_tmpdir ("TMP")) == NULL
&& (tmpdir = check_valid_env_tmpdir ("USERPROFILE")) == NULL) {
#else
if ((tmpdir = check_valid_env_tmpdir ("TMP")) == NULL
&& (tmpdir = check_valid_env_tmpdir ("TEMP")) == NULL) {
if (!check_valid_dir ("/tmp")) {
tmp = cob_fast_malloc (5U);
strcpy (tmp, "/tmp");
tmpdir = tmp;
}
&& (tmpdir = check_valid_env_tmpdir ("TMP")) == NULL
&& (tmpdir = check_valid_env_tmpdir ("TEMP")) == NULL) {
if (!check_valid_dir ("/tmp")) {
tmp = cob_fast_malloc (5U);
strcpy (tmp, "/tmp");
tmpdir = tmp;
}
if (!tmpdir) {
#endif
tmp = cob_fast_malloc (2U);
tmp[0] = '.';
tmp[1] = 0;
}
/* fallback if still not valid: current directory */
if (!tmpdir) {
tmp = cob_fast_malloc (2U);
tmp[0] = '.';
tmp[1] = 0;
tmpdir = tmp;
} else {
/* if we have a valid path: ensure there's no trailing slash */
size_t size = strlen (tmpdir) - 1;
if (tmpdir[size] == SLASH_CHAR) {
tmp = (char*)cob_fast_malloc (size + 1);
memcpy (tmp, tmpdir, size);
tmp[size] = 0;
tmpdir = tmp;
} else {
size_t size = strlen (tmpdir) - 1;
if (tmpdir[size] == SLASH_CHAR) {
tmp = (char*)cob_fast_malloc (size + 1);
memcpy (tmp, tmpdir, size);
tmp[size] = 0;
tmpdir = tmp;
}
}
(void)cob_setenv ("TMPDIR", tmpdir, 1);
if (tmp) {
cob_free ((void *)tmp);
tmpdir = getenv ("TMPDIR");
}
}
/* ensure TMPDIR is set for called tools (which partially break hard otherwise) */
(void)cob_setenv ("TMPDIR", tmpdir, 1);

if (tmp) {
cob_free ((void *)tmp);
}

/* get the pointer to the environment copy - as this may point to a different place -
store it for subsequent calls and finally return it to the caller */
tmpdir = getenv ("TMPDIR");
return tmpdir;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
* testsuite.src/listings.at: ignore all stderr in listing tests
as those are checked via the listing output there

2021-09-28 Simon Sobisch <[email protected]>

* atlocal.in: workaround for MSYS issues

2021-09-25 Ron Norman <[email protected]>

* atlocal.in,atlocal_win,atlocal_valgrind: Add -std=default to COBC
Expand Down
6 changes: 6 additions & 0 deletions tests/atlocal.in
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ _return_path () {
# Fix for testcases where cobc translates path to win32 equivalents
if test "x$MSYSTEM" != "x"; then
PATHSEP=";"
# finding the cobc executable is done from MSYS, but if this calls cobcrun
# it just uses the PATH variable which not necessarily has the correct
# order - especially if the current system has cobcrun installed - so
# let that cobc call COBCRUN with a full path (converted by MSYS into
# the Win32 variant when starting the cobc process)
COBCRUN=${ABS_COBCRUN}
else
PATHSEP='@PATH_SEPARATOR@';
fi
Expand Down
20 changes: 14 additions & 6 deletions tests/testsuite.src/run_file.at
Original file line number Diff line number Diff line change
Expand Up @@ -6080,9 +6080,13 @@ AT_CHECK([$COBCRUN_DIRECT ./prog ./prog.cob], [0],
AT_CHECK([DD_dot="." dd_dot="A" dot="B" $COBCRUN_DIRECT ./prog 'dot/prog.cob'], [0],
[RUN WITH dot/prog.cob
], [])
AT_CHECK([DD_dot="" dd_dot="." dot="A" $COBCRUN_DIRECT ./prog 'dot/prog.cob'], [0],
[RUN WITH dot/prog.cob
# MinGW and other Win32 builds would fail this - because "getenv is not case sensitive"
# note: does not apply to cygwin; "AAA" wins over "aaa"
if test "$PATHSEP" != ";"; then
AT_CHECK([DD_dot="" dd_dot="." dot="A" $COBCRUN_DIRECT ./prog 'dot/prog.cob'], [0],
[RUN WITH dot/prog.cob
], [])
fi
# MF would say (ignore for now as this conflicts with ACUCOBOL) don't resolve by $
# as it does not start with $:
#AT_CHECK([DD_dot="" dd_dot="" dot="." $COBCRUN_DIRECT ./prog 'dot/prog.cob'], [0],
Expand All @@ -6100,9 +6104,13 @@ error opening file ...
AT_CHECK([DD_dot="." dd_dot="" dot="" $COBCRUN_DIRECT ./prog '$dot/prog.cob'], [0],
[RUN WITH $dot/prog.cob
], [])
AT_CHECK([DD_dot="" dd_dot="." dot="" $COBCRUN_DIRECT ./prog '$dot/prog.cob'], [0],
[RUN WITH $dot/prog.cob
# MinGW and other Win32 builds would fail this - because "getenv is not case sensitive"
# note: does not apply to cygwin; "AAA" wins over "aaa"
if test "$PATHSEP" != ";"; then
AT_CHECK([DD_dot="" dd_dot="." dot="" $COBCRUN_DIRECT ./prog '$dot/prog.cob'], [0],
[RUN WITH $dot/prog.cob
], [])
fi
AT_CHECK([DD_dot="" dd_dot="" dot="." $COBCRUN_DIRECT ./prog '$dot/prog.cob'], [0],
[RUN WITH $dot/prog.cob
], [])
Expand All @@ -6111,7 +6119,7 @@ AT_CHECK([DD_dot="" dd_dot="" dot="." $COBCRUN_DIRECT ./prog '$dot/prog.cob'],
AT_CHECK([DD_dot="" dd_dot="" dot="" $COBCRUN_DIRECT ./prog '$dot/prog.cob'], [0],
[RUN WITH $dot/prog.cob
], [])
# would _possibly_ fail with MF (docs are wrong here in any case...)
# would _possibly_ fail with MF (their docs do not match their behaviour in any case...)
# but this is by GnuCOBOL design here:
AT_CHECK([DD_dot="" dd_dot="" dot="" $COBCRUN_DIRECT ./prog '$dot/$dotter/prog.cob'], [0],
[RUN WITH $dot/$dotter/prog.cob
Expand Down Expand Up @@ -11994,7 +12002,7 @@ AT_DATA([prog.cob], [
MOVE READ-RANDOM-LOCK TO COBOL-OP.
SET FCD-RECORD-ADDRESS TO ADDRESS OF RECORD-AREA.
PERFORM A-200-CALL-EXTFH.
MOVE FCD-RELATIVE-KEY TO I.
MOVE FCD-RELATIVE-KEY TO I.
A-400-REWRITE-RECORD.
MOVE COBOL-TYPE TO ACTION-TYPE.
MOVE REWRITE-RECORD TO COBOL-OP.
Expand Down

0 comments on commit e974a32

Please sign in to comment.