Skip to content

Commit

Permalink
#refs modelica#4301 Fix feature check macros for POSIX realpath
Browse files Browse the repository at this point in the history
  • Loading branch information
beutlich committed Mar 14, 2024
1 parent 677bec0 commit da90ab2
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Modelica/Resources/C-Sources/ModelicaInternal.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,13 @@ int ModelicaInternal_getNumberOfFiles(_In_z_ const char* directory) {

_Ret_z_ const char* ModelicaInternal_fullPathName(_In_z_ const char* name) {
/* Get full path name of file or directory */
#undef MODELICA_INTERNAL_HAVE_POSIX_REALPATH
#if defined(_BSD_SOURCE) || \
(defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 500) || \
(defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
_POSIX_VERSION >= 200112L
#define MODELICA_INTERNAL_HAVE_POSIX_REALPATH
#endif

#if defined(_WIN32)
char* fullName;
Expand All @@ -684,7 +691,7 @@ _Ret_z_ const char* ModelicaInternal_fullPathName(_In_z_ const char* name) {
fullName = ModelicaDuplicateString(tempName);
ModelicaConvertToUnixDirectorySeparator(fullName);
return fullName;
#elif (_BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED || _POSIX_VERSION >= 200112L)
#elif defined(MODELICA_INTERNAL_HAVE_POSIX_REALPATH)
char* fullName;
char localbuf[BUFFER_LENGTH];
size_t len;
Expand All @@ -710,10 +717,10 @@ _Ret_z_ const char* ModelicaInternal_fullPathName(_In_z_ const char* name) {
return fullName;
#endif

#if (_BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED || _POSIX_VERSION >= 200112L)
#if defined(MODELICA_INTERNAL_HAVE_POSIX_REALPATH)
FALLBACK_getcwd:
#endif
#if (_BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED || _POSIX_VERSION >= 200112L || _POSIX_)
#if defined(MODELICA_INTERNAL_HAVE_POSIX_REALPATH) || defined(_POSIX_)
{
/* No such system call in _POSIX_ available (except realpath for existing paths) */
char* cwd = getcwd(localbuf, sizeof(localbuf));
Expand All @@ -734,6 +741,7 @@ _Ret_z_ const char* ModelicaInternal_fullPathName(_In_z_ const char* name) {
}
return fullName;
#endif
#undef MODELICA_INTERNAL_HAVE_POSIX_REALPATH
}

_Ret_z_ const char* ModelicaInternal_temporaryFileName(void) {
Expand Down

0 comments on commit da90ab2

Please sign in to comment.