From 590ca4dbdf5e6629c908091896d113473559cda0 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Wed, 9 Aug 2023 18:52:16 +0000 Subject: [PATCH] Merge pull request #1484 from ailin-nemui/realposix change realpath to use syntax based on _POSIX_VERSION (cherry picked from commit f9c9485d155c1b0545fb30b0d2d6d884079b2f76) --- src/lib-config/write.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib-config/write.c b/src/lib-config/write.c index 5dbbd1ed..b7c6edb5 100644 --- a/src/lib-config/write.c +++ b/src/lib-config/write.c @@ -305,6 +305,9 @@ int config_write(CONFIG_REC *rec, const char *fname, int create_mode) const char *base_name; char *tmp_name = NULL; char *dest_name = NULL; +#if !defined(_POSIX_VERSION) || _POSIX_VERSION < 200809L + char resolved_path[PATH_MAX] = { 0 }; +#endif g_return_val_if_fail(rec != NULL, -1); g_return_val_if_fail(fname != NULL || rec->fname != NULL, -1); @@ -313,16 +316,15 @@ int config_write(CONFIG_REC *rec, const char *fname, int create_mode) base_name = fname != NULL ? fname : rec->fname; /* expand all symlinks; else we may replace a symlink with a regular file */ - dest_name = realpath(base_name, NULL); - - if (errno == EINVAL) { - /* variable path length not supported by glibc < 2.3, Solaris < 11 */ - char resolved_path[PATH_MAX] = { 0 }; - errno = 0; - if ((dest_name = realpath(base_name, resolved_path)) != NULL) { - dest_name = g_strdup(dest_name); - } +#if !defined(_POSIX_VERSION) || _POSIX_VERSION < 200809L + /* variable path length not supported by glibc < 2.3, Solaris < 11 */ + errno = 0; + if ((dest_name = realpath(base_name, resolved_path)) != NULL) { + dest_name = g_strdup(dest_name); } +#else + dest_name = realpath(base_name, NULL); +#endif if (dest_name == NULL) { if (errno == ENOENT) {