mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-06 06:20:55 -08:00
Adjust to recent Gnulib changes
The latest Gnulib merge brought in free-posix, which causes 'free' to preserve errno. This lets us simplify some Emacs code that calls 'free'. * admin/merge-gnulib (GNULIB_MODULES): Add free-posix. This module is pulled in by canonicalize-lgpl anyway, so we might as well rely on it. * lib-src/emacsclient.c (get_current_dir_name): Sync better with src/sysdep.c. * lib-src/etags.c (process_file_name, etags_mktmp): * lib-src/update-game-score.c (unlock_file): * src/fileio.c (file_accessible_directory_p): * src/sysdep.c (get_current_dir_name_or_unreachable): Simplify by assuming that 'free' preserves errno. * src/alloc.c (malloc_unblock_input): Preserve errno, so that xfree preserves errno. * src/sysdep.c (get_current_dir_name_or_unreachable): Simplify by using strdup instead of malloc+memcpy. No need for realloc (and the old code leaked memory anyway on failure); just use free+malloc.
This commit is contained in:
parent
b8b17038e1
commit
ec8a17e938
7 changed files with 31 additions and 67 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue