]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Issue 70: Consistently use O_BINARY when opening files.
authorTim Kientzle <kientzle@gmail.com>
Sat, 6 Mar 2010 18:49:21 +0000 (13:49 -0500)
committerTim Kientzle <kientzle@gmail.com>
Sat, 6 Mar 2010 18:49:21 +0000 (13:49 -0500)
SVN-Revision: 2015

tar/write.c

index 01e110923e399100140a96cf767befe2c168b70f..93f20353296bfb44ebc7d9fcad744b4dcd932f62 100644 (file)
@@ -104,6 +104,10 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/write.c,v 1.79 2008/11/27 05:49:52 kientzle
 /* Fixed size of uname/gname caches. */
 #define        name_cache_size 101
 
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 static const char * const NO_NAME = "(noname)";
 
 struct archive_dir_entry {
@@ -267,9 +271,9 @@ tar_mode_r(struct bsdtar *bsdtar)
        format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED;
 
 #if defined(__BORLANDC__)
-       bsdtar->fd = open(bsdtar->filename, O_RDWR | O_CREAT);
+       bsdtar->fd = open(bsdtar->filename, O_RDWR | O_CREAT | O_BINARY);
 #else
-       bsdtar->fd = open(bsdtar->filename, O_RDWR | O_CREAT, 0666);
+       bsdtar->fd = open(bsdtar->filename, O_RDWR | O_CREAT | O_BINARY, 0666);
 #endif
        if (bsdtar->fd < 0)
                lafe_errc(1, errno,
@@ -363,7 +367,7 @@ tar_mode_u(struct bsdtar *bsdtar)
        /* Sanity-test some arguments and the file. */
        test_for_append(bsdtar);
 
-       bsdtar->fd = open(bsdtar->filename, O_RDWR);
+       bsdtar->fd = open(bsdtar->filename, O_RDWR | O_BINARY);
        if (bsdtar->fd < 0)
                lafe_errc(1, errno,
                    "Cannot open %s", bsdtar->filename);
@@ -852,7 +856,7 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
 #if defined(EXT2_IOC_GETFLAGS) && defined(EXT2_NODUMP_FL)
                /* Linux uses ioctl to read flags. */
                if (bsdtar->option_honor_nodump) {
-                       int fd = open(name, O_RDONLY | O_NONBLOCK);
+                       int fd = open(name, O_RDONLY | O_NONBLOCK | O_BINARY);
                        if (fd >= 0) {
                                unsigned long fflags;
                                int r = ioctl(fd, EXT2_IOC_GETFLAGS, &fflags);
@@ -1020,7 +1024,7 @@ write_entry(struct bsdtar *bsdtar, struct archive *a,
 
        if (archive_entry_size(entry) > 0) {
                const char *pathname = archive_entry_sourcepath(entry);
-               fd = open(pathname, O_RDONLY);
+               fd = open(pathname, O_RDONLY | O_BINARY);
                if (fd == -1) {
                        if (!bsdtar->verbose)
                                lafe_warnc(errno,