1
0
Fork 0

Merge pull request #1484 from ailin-nemui/realposix

change realpath to use syntax based on _POSIX_VERSION

(cherry picked from commit f9c9485d15)
This commit is contained in:
ailin-nemui 2023-08-09 18:52:16 +00:00 committed by Ailin Nemui
parent edfbc1f2f6
commit 590ca4dbdf
1 changed files with 11 additions and 9 deletions

View File

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