diff options
Diffstat (limited to 'lib-src')
-rw-r--r-- | lib-src/emacsclient.c | 39 | ||||
-rw-r--r-- | lib-src/etags.c | 17 | ||||
-rw-r--r-- | lib-src/update-game-score.c | 4 |
3 files changed, 17 insertions, 43 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 871fa7a8d3c..8d184e28177 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -251,7 +251,6 @@ get_current_dir_name (void) bufsize_max = min (bufsize_max, PATH_MAX); #endif - char *buf; struct stat dotstat, pwdstat; size_t pwdlen; /* If PWD is accurate, use it instead of calling getcwd. PWD is @@ -265,37 +264,23 @@ get_current_dir_name (void) && stat (".", &dotstat) == 0 && dotstat.st_ino == pwdstat.st_ino && dotstat.st_dev == pwdstat.st_dev) - { - buf = xmalloc (strlen (pwd) + 1); - strcpy (buf, pwd); - } + return strdup (pwd); else { - size_t buf_size = 1024; + ptrdiff_t buf_size = min (bufsize_max, 1024); for (;;) - { - int tmp_errno; - buf = malloc (buf_size); - if (! buf) - break; - if (getcwd (buf, buf_size) == buf) - break; - tmp_errno = errno; + { + char *buf = malloc (buf_size); + if (!buf) + return NULL; + if (getcwd (buf, buf_size) == buf) + return buf; free (buf); - if (tmp_errno != ERANGE) - { - errno = tmp_errno; - return NULL; - } - buf_size *= 2; - if (! buf_size) - { - errno = ENOMEM; - return NULL; - } - } + if (errno != ERANGE || buf_size == bufsize_max) + return NULL; + buf_size = buf_size <= bufsize_max / 2 ? 2 * buf_size : bufsize_max; + } } - return buf; } #endif diff --git a/lib-src/etags.c b/lib-src/etags.c index a1c6837e880..071892ee317 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -1643,19 +1643,10 @@ process_file_name (char *file, language *lang) char *cmd = concat (cmd1, "' > ", tmp_name); #endif free (cmd1); - int tmp_errno; - if (system (cmd) == -1) - { - inf = NULL; - tmp_errno = EINVAL; - } - else - { - inf = fopen (tmp_name, "r" FOPEN_BINARY); - tmp_errno = errno; - } + inf = (system (cmd) == -1 + ? NULL + : fopen (tmp_name, "r" FOPEN_BINARY)); free (cmd); - errno = tmp_errno; } if (!inf) @@ -7068,9 +7059,7 @@ etags_mktmp (void) int fd = mkostemp (templt, O_CLOEXEC); if (fd < 0 || close (fd) != 0) { - int temp_errno = errno; free (templt); - errno = temp_errno; templt = NULL; } #if defined (DOS_NT) diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c index 93aa0393d94..fc6e72838ea 100644 --- a/lib-src/update-game-score.c +++ b/lib-src/update-game-score.c @@ -499,9 +499,9 @@ unlock_file (const char *filename, void *state) char *lockpath = (char *) state; int saved_errno = errno; int ret = unlink (lockpath); - int unlink_errno = errno; + if (0 <= ret) + errno = saved_errno; free (lockpath); - errno = ret < 0 ? unlink_errno : saved_errno; return ret; } |