}
#endif /* F_DUPFD_CLOEXEC */
new_fd = dup(fd);
- if (new_fd != -1) {
- __archive_ensure_cloexec_flag(new_fd);
- return (new_fd);
- }
- return (-1);
+ __archive_ensure_cloexec_flag(new_fd);
+ return (new_fd);
}
/*
* so try again for execute. The consequences of not opening this are
* unhelpful and unnecessary errors later.
*/
- if (t->initial_dir_fd < 0) {
+ if (t->initial_dir_fd < 0)
t->initial_dir_fd = open(".", o_flag | O_CLOEXEC);
- if (t->initial_dir_fd < 0)
- return NULL;
- }
#endif
__archive_ensure_cloexec_flag(t->initial_dir_fd);
t->working_dir_fd = tree_dup(t->initial_dir_fd);
- if (t->working_dir_fd < 0)
- return NULL;
return (t);
}
tree_dir_next_posix(struct tree *t)
{
int r;
+#if defined(HAVE_FDOPENDIR)
+ int fd;
+#endif
const char *name;
size_t namelen;
if (t->d == NULL) {
#if defined(HAVE_FDOPENDIR)
- int fd = tree_dup(t->working_dir_fd);
- if (fd != -1)
- t->d = fdopendir(fd);
+ if (t->working_dir_fd >= 0) {
+ fd = tree_dup(t->working_dir_fd);
+ if (fd != -1)
+ t->d = fdopendir(fd);
+ }
#else /* HAVE_FDOPENDIR */
if (tree_enter_working_dir(t) == 0) {
t->d = opendir(".");
archive_entry_filetype(entry) == AE_IFDIR) {
mtree->fd = open(path, O_RDONLY | O_BINARY | O_CLOEXEC);
__archive_ensure_cloexec_flag(mtree->fd);
- if (mtree->fd < 0 && (
+ if (mtree->fd == -1 && (
#if defined(_WIN32) && !defined(__CYGWIN__)
/*
* On Windows, attempting to open a file with an
* for directories. For other file types
* we need to verify via fstat() or lstat()
*/
- if (fd < 0 || p->filetype != AE_IFDIR) {
+ if (fd == -1 || p->filetype != AE_IFDIR) {
#if HAVE_FSTAT
- if (fd >= 0 && (
+ if (fd > 0 && (
fstat(fd, &st) != 0 ||
la_verify_filetype(st.st_mode,
p->filetype) == 0)) {
*/
fd = open(pathname, O_RDONLY | O_BINARY | O_CLOEXEC);
__archive_ensure_cloexec_flag(fd);
- if (fd < 0) {
+ if (fd == -1) {
archive_set_error(&a->archive, errno,
"Failed to open a restoring file");
ret = ARCHIVE_WARN;