d-type diffseq double-slash-root dtoastr dtotimespec dup2
environ execinfo explicit_bzero faccessat
fchmodat fcntl fcntl-h fdopendir
- filemode filename filevercmp flexmember fpieee fstatat fsusage fsync futimens
+ filemode filename filevercmp flexmember fpieee
+ free-posix fstatat fsusage fsync futimens
getloadavg getopt-gnu getrandom gettime gettimeofday gitlog-to-changelog
ieee754-h ignore-value intprops largefile libgmp lstat
manywarnings memmem-simple mempcpy memrchr minmax mkostemp mktime nstrftime
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
&& 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
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)
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)
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;
}
malloc_unblock_input (void)
{
if (block_input_in_memory_allocators)
- unblock_input ();
+ {
+ int err = errno;
+ unblock_input ();
+ errno = err;
+ }
}
# define MALLOC_BLOCK_INPUT malloc_block_input ()
# define MALLOC_UNBLOCK_INPUT malloc_unblock_input ()
ptrdiff_t len = SBYTES (file);
char const *dir;
bool ok;
- int saved_errno;
USE_SAFE_ALLOCA;
/* Normally a file "FOO" is an accessible directory if "FOO/." exists.
}
ok = file_access_p (dir, F_OK);
- saved_errno = errno;
SAFE_FREE ();
- errno = saved_errno;
return ok;
#endif /* !DOS_NT */
}
&& emacs_fstatat (AT_FDCWD, ".", &dotstat, 0) == 0
&& dotstat.st_ino == pwdstat.st_ino
&& dotstat.st_dev == pwdstat.st_dev)
- {
- char *buf = malloc (pwdlen + 1);
- if (!buf)
- return NULL;
- return memcpy (buf, pwd, pwdlen + 1);
- }
+ return strdup (pwd);
else
{
ptrdiff_t buf_size = min (bufsize_max, 1024);
- char *buf = malloc (buf_size);
- if (!buf)
- return NULL;
for (;;)
{
+ char *buf = malloc (buf_size);
+ if (!buf)
+ return NULL;
if (getcwd (buf, buf_size) == buf)
return buf;
- int getcwd_errno = errno;
- if (getcwd_errno != ERANGE || buf_size == bufsize_max)
- {
- free (buf);
- errno = getcwd_errno;
- return NULL;
- }
+ free (buf);
+ if (errno != ERANGE || buf_size == bufsize_max)
+ return NULL;
buf_size = buf_size <= bufsize_max / 2 ? 2 * buf_size : bufsize_max;
- buf = realloc (buf, buf_size);
- if (!buf)
- return NULL;
}
}
}