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) | |||
| 251 | bufsize_max = min (bufsize_max, PATH_MAX); | 251 | bufsize_max = min (bufsize_max, PATH_MAX); |
| 252 | #endif | 252 | #endif |
| 253 | 253 | ||
| 254 | char *buf; | ||
| 255 | struct stat dotstat, pwdstat; | 254 | struct stat dotstat, pwdstat; |
| 256 | size_t pwdlen; | 255 | size_t pwdlen; |
| 257 | /* If PWD is accurate, use it instead of calling getcwd. PWD is | 256 | /* If PWD is accurate, use it instead of calling getcwd. PWD is |
| @@ -265,37 +264,23 @@ get_current_dir_name (void) | |||
| 265 | && stat (".", &dotstat) == 0 | 264 | && stat (".", &dotstat) == 0 |
| 266 | && dotstat.st_ino == pwdstat.st_ino | 265 | && dotstat.st_ino == pwdstat.st_ino |
| 267 | && dotstat.st_dev == pwdstat.st_dev) | 266 | && dotstat.st_dev == pwdstat.st_dev) |
| 268 | { | 267 | return strdup (pwd); |
| 269 | buf = xmalloc (strlen (pwd) + 1); | ||
| 270 | strcpy (buf, pwd); | ||
| 271 | } | ||
| 272 | else | 268 | else |
| 273 | { | 269 | { |
| 274 | size_t buf_size = 1024; | 270 | ptrdiff_t buf_size = min (bufsize_max, 1024); |
| 275 | for (;;) | 271 | for (;;) |
| 276 | { | 272 | { |
| 277 | int tmp_errno; | 273 | char *buf = malloc (buf_size); |
| 278 | buf = malloc (buf_size); | 274 | if (!buf) |
| 279 | if (! buf) | 275 | return NULL; |
| 280 | break; | 276 | if (getcwd (buf, buf_size) == buf) |
| 281 | if (getcwd (buf, buf_size) == buf) | 277 | return buf; |
| 282 | break; | ||
| 283 | tmp_errno = errno; | ||
| 284 | free (buf); | 278 | free (buf); |
| 285 | if (tmp_errno != ERANGE) | 279 | if (errno != ERANGE || buf_size == bufsize_max) |
| 286 | { | 280 | return NULL; |
| 287 | errno = tmp_errno; | 281 | buf_size = buf_size <= bufsize_max / 2 ? 2 * buf_size : bufsize_max; |
| 288 | return NULL; | 282 | } |
| 289 | } | ||
| 290 | buf_size *= 2; | ||
| 291 | if (! buf_size) | ||
| 292 | { | ||
| 293 | errno = ENOMEM; | ||
| 294 | return NULL; | ||
| 295 | } | ||
| 296 | } | ||
| 297 | } | 283 | } |
| 298 | return buf; | ||
| 299 | } | 284 | } |
| 300 | #endif | 285 | #endif |
| 301 | 286 | ||
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) | |||
| 1643 | char *cmd = concat (cmd1, "' > ", tmp_name); | 1643 | char *cmd = concat (cmd1, "' > ", tmp_name); |
| 1644 | #endif | 1644 | #endif |
| 1645 | free (cmd1); | 1645 | free (cmd1); |
| 1646 | int tmp_errno; | 1646 | inf = (system (cmd) == -1 |
| 1647 | if (system (cmd) == -1) | 1647 | ? NULL |
| 1648 | { | 1648 | : fopen (tmp_name, "r" FOPEN_BINARY)); |
| 1649 | inf = NULL; | ||
| 1650 | tmp_errno = EINVAL; | ||
| 1651 | } | ||
| 1652 | else | ||
| 1653 | { | ||
| 1654 | inf = fopen (tmp_name, "r" FOPEN_BINARY); | ||
| 1655 | tmp_errno = errno; | ||
| 1656 | } | ||
| 1657 | free (cmd); | 1649 | free (cmd); |
| 1658 | errno = tmp_errno; | ||
| 1659 | } | 1650 | } |
| 1660 | 1651 | ||
| 1661 | if (!inf) | 1652 | if (!inf) |
| @@ -7068,9 +7059,7 @@ etags_mktmp (void) | |||
| 7068 | int fd = mkostemp (templt, O_CLOEXEC); | 7059 | int fd = mkostemp (templt, O_CLOEXEC); |
| 7069 | if (fd < 0 || close (fd) != 0) | 7060 | if (fd < 0 || close (fd) != 0) |
| 7070 | { | 7061 | { |
| 7071 | int temp_errno = errno; | ||
| 7072 | free (templt); | 7062 | free (templt); |
| 7073 | errno = temp_errno; | ||
| 7074 | templt = NULL; | 7063 | templt = NULL; |
| 7075 | } | 7064 | } |
| 7076 | #if defined (DOS_NT) | 7065 | #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) | |||
| 499 | char *lockpath = (char *) state; | 499 | char *lockpath = (char *) state; |
| 500 | int saved_errno = errno; | 500 | int saved_errno = errno; |
| 501 | int ret = unlink (lockpath); | 501 | int ret = unlink (lockpath); |
| 502 | int unlink_errno = errno; | 502 | if (0 <= ret) |
| 503 | errno = saved_errno; | ||
| 503 | free (lockpath); | 504 | free (lockpath); |
| 504 | errno = ret < 0 ? unlink_errno : saved_errno; | ||
| 505 | return ret; | 505 | return ret; |
| 506 | } | 506 | } |
| 507 | 507 | ||