aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2020-12-25 01:38:31 -0800
committerPaul Eggert2020-12-25 01:40:39 -0800
commitec8a17e938c3ef213709ea6b6b3e565333a9c508 (patch)
tree1558c79f3c269d9ae1b068bb7c66fce04707b32c /src
parentb8b17038e140fe215a76f2e899c00b9b95614886 (diff)
downloademacs-ec8a17e938c3ef213709ea6b6b3e565333a9c508.tar.gz
emacs-ec8a17e938c3ef213709ea6b6b3e565333a9c508.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/alloc.c6
-rw-r--r--src/fileio.c3
-rw-r--r--src/sysdep.c26
3 files changed, 12 insertions, 23 deletions
diff --git a/src/alloc.c b/src/alloc.c
index adbfa1883c5..0b387dd8c1b 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -732,7 +732,11 @@ static void
732malloc_unblock_input (void) 732malloc_unblock_input (void)
733{ 733{
734 if (block_input_in_memory_allocators) 734 if (block_input_in_memory_allocators)
735 unblock_input (); 735 {
736 int err = errno;
737 unblock_input ();
738 errno = err;
739 }
736} 740}
737# define MALLOC_BLOCK_INPUT malloc_block_input () 741# define MALLOC_BLOCK_INPUT malloc_block_input ()
738# define MALLOC_UNBLOCK_INPUT malloc_unblock_input () 742# define MALLOC_UNBLOCK_INPUT malloc_unblock_input ()
diff --git a/src/fileio.c b/src/fileio.c
index 651e765fca4..23b4523c944 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -3050,7 +3050,6 @@ file_accessible_directory_p (Lisp_Object file)
3050 ptrdiff_t len = SBYTES (file); 3050 ptrdiff_t len = SBYTES (file);
3051 char const *dir; 3051 char const *dir;
3052 bool ok; 3052 bool ok;
3053 int saved_errno;
3054 USE_SAFE_ALLOCA; 3053 USE_SAFE_ALLOCA;
3055 3054
3056 /* Normally a file "FOO" is an accessible directory if "FOO/." exists. 3055 /* Normally a file "FOO" is an accessible directory if "FOO/." exists.
@@ -3075,9 +3074,7 @@ file_accessible_directory_p (Lisp_Object file)
3075 } 3074 }
3076 3075
3077 ok = file_access_p (dir, F_OK); 3076 ok = file_access_p (dir, F_OK);
3078 saved_errno = errno;
3079 SAFE_FREE (); 3077 SAFE_FREE ();
3080 errno = saved_errno;
3081 return ok; 3078 return ok;
3082#endif /* !DOS_NT */ 3079#endif /* !DOS_NT */
3083} 3080}
diff --git a/src/sysdep.c b/src/sysdep.c
index 29c88f5308e..eeb9d184940 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -314,33 +314,21 @@ get_current_dir_name_or_unreachable (void)
314 && emacs_fstatat (AT_FDCWD, ".", &dotstat, 0) == 0 314 && emacs_fstatat (AT_FDCWD, ".", &dotstat, 0) == 0
315 && dotstat.st_ino == pwdstat.st_ino 315 && dotstat.st_ino == pwdstat.st_ino
316 && dotstat.st_dev == pwdstat.st_dev) 316 && dotstat.st_dev == pwdstat.st_dev)
317 { 317 return strdup (pwd);
318 char *buf = malloc (pwdlen + 1);
319 if (!buf)
320 return NULL;
321 return memcpy (buf, pwd, pwdlen + 1);
322 }
323 else 318 else
324 { 319 {
325 ptrdiff_t buf_size = min (bufsize_max, 1024); 320 ptrdiff_t buf_size = min (bufsize_max, 1024);
326 char *buf = malloc (buf_size);
327 if (!buf)
328 return NULL;
329 for (;;) 321 for (;;)
330 { 322 {
323 char *buf = malloc (buf_size);
324 if (!buf)
325 return NULL;
331 if (getcwd (buf, buf_size) == buf) 326 if (getcwd (buf, buf_size) == buf)
332 return buf; 327 return buf;
333 int getcwd_errno = errno; 328 free (buf);
334 if (getcwd_errno != ERANGE || buf_size == bufsize_max) 329 if (errno != ERANGE || buf_size == bufsize_max)
335 { 330 return NULL;
336 free (buf);
337 errno = getcwd_errno;
338 return NULL;
339 }
340 buf_size = buf_size <= bufsize_max / 2 ? 2 * buf_size : bufsize_max; 331 buf_size = buf_size <= bufsize_max / 2 ? 2 * buf_size : bufsize_max;
341 buf = realloc (buf, buf_size);
342 if (!buf)
343 return NULL;
344 } 332 }
345 } 333 }
346} 334}