summaryrefslogtreecommitdiff
path: root/lib-src/emacsclient.c
diff options
context:
space:
mode:
authorYuuki Harano <masm+github@masm11.me>2020-12-27 03:13:00 +0900
committerYuuki Harano <masm+github@masm11.me>2020-12-27 03:13:00 +0900
commitb64089c37b4305a511e5ddbf02746862c7c7575e (patch)
treec6978d471e4b0b061b7cc9c46147968379aec94f /lib-src/emacsclient.c
parent565d8f57d349c19d9bbb5d5d5fdacf3c70b85d42 (diff)
parent4b2ca6bfc079c66cfcf39f2f36dc139012787535 (diff)
downloademacs-b64089c37b4305a511e5ddbf02746862c7c7575e.tar.gz
Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs into feature/pgtk
Diffstat (limited to 'lib-src/emacsclient.c')
-rw-r--r--lib-src/emacsclient.c39
1 files changed, 12 insertions, 27 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index a55e4bc705c..908298533d9 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