aboutsummaryrefslogtreecommitdiff
path: root/src/xz/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xz/io.c')
-rw-r--r--src/xz/io.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/xz/io.c b/src/xz/io.c
index b8b8d8d7..5ee84a95 100644
--- a/src/xz/io.c
+++ b/src/xz/io.c
@@ -21,6 +21,10 @@
#include <fcntl.h>
+#ifdef DOSLIKE
+# include <io.h>
+#endif
+
#if defined(HAVE_FUTIMES) || defined(HAVE_FUTIMESAT) || defined(HAVE_UTIMES)
# include <sys/time.h>
#elif defined(HAVE_UTIME)
@@ -35,7 +39,7 @@
# define O_NOCTTY 0
#endif
-#ifndef _WIN32
+#ifndef DOSLIKE
# include "open_stdxxx.h"
static bool warn_fchown;
#endif
@@ -44,7 +48,7 @@ static bool warn_fchown;
extern void
io_init(void)
{
-#ifndef _WIN32
+#ifndef DOSLIKE
// Make sure that stdin, stdout, and and stderr are connected to
// a valid file descriptor. Exit immediatelly with exit code ERROR
// if we cannot make the file descriptors valid. Maybe we should
@@ -56,6 +60,13 @@ io_init(void)
warn_fchown = geteuid() == 0;
#endif
+#ifdef __DJGPP__
+ // Avoid doing useless things when statting files.
+ // This isn't important but doesn't hurt.
+ _djstat_flags = _STAT_INODE | _STAT_EXEC_EXT
+ | _STAT_EXEC_MAGIC | _STAT_DIRSIZE;
+#endif
+
return;
}
@@ -70,7 +81,7 @@ static void
io_unlink(const char *name, const struct stat *known_st)
{
// On Windows, st_ino is meaningless, so don't bother testing it.
-#ifndef _WIN32
+#ifndef DOSLIKE
struct stat new_st;
if (lstat(name, &new_st)
@@ -98,7 +109,7 @@ static void
io_copy_attrs(const file_pair *pair)
{
// Skip chown and chmod on Windows.
-#ifndef _WIN32
+#ifndef DOSLIKE
// This function is more tricky than you may think at first.
// Blindly copying permissions may permit users to access the
// destination file who didn't have permission to access the
@@ -233,7 +244,7 @@ io_open_src(file_pair *pair)
// There's nothing to open when reading from stdin.
if (pair->src_name == stdin_filename) {
pair->src_fd = STDIN_FILENO;
-#ifdef _WIN32
+#ifdef DOSLIKE
setmode(STDIN_FILENO, O_BINARY);
#endif
return false;
@@ -246,7 +257,7 @@ io_open_src(file_pair *pair)
// Flags for open()
int flags = O_RDONLY | O_BINARY | O_NOCTTY;
-#ifndef _WIN32
+#ifndef DOSLIKE
// If we accept only regular files, we need to be careful to avoid
// problems with special files like devices and FIFOs. O_NONBLOCK
// prevents blocking when opening such files. When we want to accept
@@ -259,7 +270,7 @@ io_open_src(file_pair *pair)
#if defined(O_NOFOLLOW)
if (reg_files_only)
flags |= O_NOFOLLOW;
-#elif !defined(_WIN32)
+#elif !defined(DOSLIKE)
// Some POSIX-like systems lack O_NOFOLLOW (it's not required
// by POSIX). Check for symlinks with a separate lstat() on
// these systems.
@@ -363,7 +374,7 @@ io_open_src(file_pair *pair)
return true;
}
-#ifndef _WIN32
+#ifndef DOSLIKE
// Drop O_NONBLOCK, which is used only when we are accepting only
// regular files. After the open() call, we want things to block
// instead of giving EAGAIN.
@@ -398,7 +409,7 @@ io_open_src(file_pair *pair)
}
// These are meaningless on Windows.
-#ifndef _WIN32
+#ifndef DOSLIKE
if (pair->src_st.st_mode & (S_ISUID | S_ISGID)) {
// gzip rejects setuid and setgid files even
// when --force was used. bzip2 doesn't check
@@ -450,7 +461,7 @@ static void
io_close_src(file_pair *pair, bool success)
{
if (pair->src_fd != STDIN_FILENO && pair->src_fd != -1) {
-#ifdef _WIN32
+#ifdef DOSLIKE
(void)close(pair->src_fd);
#endif
@@ -459,12 +470,12 @@ io_close_src(file_pair *pair, bool success)
// happens to get same inode number, which would make us
// unlink() wrong file.
//
- // NOTE: Windows is an exception to this, because it doesn't
- // allow unlinking files that are open. *sigh*
+ // NOTE: DOS-like systems are an exception to this, because
+ // they don't allow unlinking files that are open. *sigh*
if (success && !opt_keep_original)
io_unlink(pair->src_name, &pair->src_st);
-#ifndef _WIN32
+#ifndef DOSLIKE
(void)close(pair->src_fd);
#endif
}
@@ -480,7 +491,7 @@ io_open_dest(file_pair *pair)
// We don't modify or free() this.
pair->dest_name = (char *)"(stdout)";
pair->dest_fd = STDOUT_FILENO;
-#ifdef _WIN32
+#ifdef DOSLIKE
setmode(STDOUT_FILENO, O_BINARY);
#endif
return false;