1
0
Fork 0

change realpath to use syntax based on _POSIX_VERSION

This commit is contained in:
Ailin Nemui 2023-08-08 07:59:31 +02:00
parent da49ec62e6
commit 1131a881cf
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) {