From 0b110821f6b03f83261a04e32b6287db44814c2c Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Wed, 26 Nov 2014 16:42:56 +0000 Subject: [PATCH] Equipped all non-system-dependent open(2) calls with O_BINARY --- cdrskin/cdrskin_timestamp.h | 2 +- libburn/ddlpa.c | 11 +++++++---- libburn/drive.c | 12 +++++++++--- libburn/file.c | 13 +++++++++---- libburn/libdax_audioxtr.c | 6 +++++- libburn/mmc.c | 8 +++++++- libburn/read.c | 10 ++++++++-- libburn/sector.c | 9 +++++++-- libburn/sg-dummy.c | 9 +++++++-- libburn/sg-libcdio.c | 15 ++++++++++----- libburn/structure.c | 9 +++++++-- libburn/write.c | 10 ++++++++-- 12 files changed, 85 insertions(+), 29 deletions(-) diff --git a/cdrskin/cdrskin_timestamp.h b/cdrskin/cdrskin_timestamp.h index b762037..6ff56ff 100644 --- a/cdrskin/cdrskin_timestamp.h +++ b/cdrskin/cdrskin_timestamp.h @@ -1 +1 @@ -#define Cdrskin_timestamP "2014.11.23.190942" +#define Cdrskin_timestamP "2014.11.26.164119" diff --git a/libburn/ddlpa.c b/libburn/ddlpa.c index a5d2002..3f473ba 100644 --- a/libburn/ddlpa.c +++ b/libburn/ddlpa.c @@ -50,7 +50,9 @@ static int ddlpa_debug_mode = 1; #ifndef O_LARGEFILE #define O_LARGEFILE 0 #endif - +#ifndef O_BINARY +#define O_BINARY 0 +#endif /* ----------------------- private -------------------- */ @@ -173,7 +175,7 @@ static int ddlpa_occupy(struct ddlpa_lock *o, char *path, int *fd, int ret, o_flags, o_rw, l_type; char *o_rwtext; - o_flags = o->o_flags | O_NDELAY; + o_flags = o->o_flags | O_NDELAY | O_BINARY; if(!no_o_excl) o_flags |= O_EXCL; o_rw = (o_flags) & (O_RDONLY | O_WRONLY | O_RDWR); @@ -216,7 +218,7 @@ static int ddlpa_occupy(struct ddlpa_lock *o, char *path, int *fd, static int ddlpa_obtain_scsi_adr(struct ddlpa_lock *o, char *path, int *bus, int *host, int *channel, int *id, int *lun) { - int fd, ret, open_mode = O_RDONLY | O_NDELAY; + int fd, ret, open_mode = O_RDONLY | O_NDELAY | O_BINARY; struct my_scsi_idlun { int x; int host_unique_id; @@ -550,7 +552,8 @@ usage:; } else { /* This substitutes for: - fd = open(my_path, O_RDWR | O_EXCL | O_LARGEFILE); + fd = open(my_path, + O_RDWR | O_EXCL | O_LARGEFILE | O_BINARY); */ diff --git a/libburn/drive.c b/libburn/drive.c index 8fe73a5..132252a 100644 --- a/libburn/drive.c +++ b/libburn/drive.c @@ -26,6 +26,12 @@ #include #include #include + +/* ts B41126 : O_BINARY is needed for Cygwin but undefined elsewhere */ +#ifndef O_BINARY +#define O_BINARY 0 +#endif + #include "libburn.h" #include "init.h" #include "drive.h" @@ -1638,17 +1644,17 @@ static int burn_role_by_access(char *fname, int flag) #endif int fd; - fd = open(fname, O_RDWR | O_LARGEFILE); + fd = open(fname, O_RDWR | O_LARGEFILE | O_BINARY); if (fd != -1) { close(fd); return 2; } - fd = open(fname, O_RDONLY | O_LARGEFILE); + fd = open(fname, O_RDONLY | O_LARGEFILE | O_BINARY); if (fd != -1) { close(fd); return 4; } - fd = open(fname, O_WRONLY | O_LARGEFILE); + fd = open(fname, O_WRONLY | O_LARGEFILE | O_BINARY); if (fd != -1) { close(fd); return 5; diff --git a/libburn/file.c b/libburn/file.c index d0e9ddb..fcc8973 100644 --- a/libburn/file.c +++ b/libburn/file.c @@ -1,7 +1,7 @@ /* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */ /* Copyright (c) 2004 - 2006 Derek Foreman, Ben Jansens - Copyright (c) 2006 - 2010 Thomas Schmitt + Copyright (c) 2006 - 2014 Thomas Schmitt Provided under GPL version 2 or later. */ @@ -22,6 +22,11 @@ #include #include +/* ts B41126 : O_BINARY is needed for Cygwin but undefined elsewhere */ +#ifndef O_BINARY +#define O_BINARY 0 +#endif + #include "source.h" #include "libburn.h" #include "file.h" @@ -121,11 +126,11 @@ struct burn_source *burn_file_source_new(const char *path, const char *subpath) if (!path) return NULL; - fd1 = open(path, O_RDONLY); + fd1 = open(path, O_RDONLY | O_BINARY); if (fd1 == -1) return NULL; if (subpath != NULL) { - fd2 = open(subpath, O_RDONLY); + fd2 = open(subpath, O_RDONLY | O_BINARY); if (fd2 == -1) { close(fd1); return NULL; @@ -945,7 +950,7 @@ int burn_drive_extract_audio(struct burn_drive *drive, BURN_ALLOC_MEM(msg, char, 4096); BURN_ALLOC_MEM(buf, char, 24 * 2352); - fd = open(target_path, O_WRONLY | O_CREAT, + fd = open(target_path, O_WRONLY | O_CREAT | O_BINARY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (fd == -1) { sprintf(msg, "Cannot open disk file for writing: %.4000s", diff --git a/libburn/libdax_audioxtr.c b/libburn/libdax_audioxtr.c index 0eb8960..ea5f322 100644 --- a/libburn/libdax_audioxtr.c +++ b/libburn/libdax_audioxtr.c @@ -17,6 +17,10 @@ #include #include +/* ts B41126 : O_BINARY is needed for Cygwin but undefined elsewhere */ +#ifndef O_BINARY +#define O_BINARY 0 +#endif #include "libdax_msgs.h" extern struct libdax_msgs *libdax_messenger; @@ -90,7 +94,7 @@ static int libdax_audioxtr_open(struct libdax_audioxtr *o, int flag) if(strcmp(o->path,"-")==0) o->fd= 0; else - o->fd= open(o->path, O_RDONLY); + o->fd= open(o->path, O_RDONLY | O_BINARY); if(o->fd<0) { sprintf(msg,"Cannot open audio source file : %s",o->path); libdax_msgs_submit(libdax_messenger,-1,0x00020200, diff --git a/libburn/mmc.c b/libburn/mmc.c index 06d407e..ff6aa01 100644 --- a/libburn/mmc.c +++ b/libburn/mmc.c @@ -21,6 +21,11 @@ #include #include +/* ts B41126 : O_BINARY is needed for Cygwin but undefined elsewhere */ +#ifndef O_BINARY +#define O_BINARY 0 +#endif + #include "error.h" #include "sector.h" #include "libburn.h" @@ -942,7 +947,8 @@ fprintf(stderr, "libburn_DEBUG: buffer sectors= %d bytes= %d\n", static int tee_fd= -1; if(tee_fd==-1) tee_fd= open("/tmp/libburn_sg_written", - O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR); + O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, + S_IRUSR | S_IWUSR); #endif /* Libburn_log_in_and_out_streaM */ mmc_start_if_needed(d, 0); diff --git a/libburn/read.c b/libburn/read.c index 2284ccf..b3ef220 100644 --- a/libburn/read.c +++ b/libburn/read.c @@ -1,7 +1,7 @@ /* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */ /* Copyright (c) 2004 - 2006 Derek Foreman, Ben Jansens - Copyright (c) 2006 - 2012 Thomas Schmitt + Copyright (c) 2006 - 2014 Thomas Schmitt Provided under GPL version 2 or later. */ @@ -22,6 +22,11 @@ #include #include +/* ts B41126 : O_BINARY is needed for Cygwin but undefined elsewhere */ +#ifndef O_BINARY +#define O_BINARY 0 +#endif + #include "sector.h" #include "libburn.h" #include "drive.h" @@ -521,7 +526,8 @@ int burn_read_data(struct burn_drive *d, off_t byte_address, fd = d->stdio_fd; if (fd < 0) d->stdio_fd = fd = - open(d->devname, O_RDONLY | O_LARGEFILE); + open(d->devname, + O_RDONLY | O_LARGEFILE | O_BINARY); if (fd == -1) { if (errno == EACCES && (flag & 2)) { if (!(flag & 8)) diff --git a/libburn/sector.c b/libburn/sector.c index c214097..e4d24cd 100644 --- a/libburn/sector.c +++ b/libburn/sector.c @@ -1,7 +1,7 @@ /* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */ /* Copyright (c) 2004 - 2006 Derek Foreman, Ben Jansens - Copyright (c) 2006 - 2011 Thomas Schmitt + Copyright (c) 2006 - 2014 Thomas Schmitt Provided under GPL version 2 or later. */ @@ -40,6 +40,10 @@ extern struct libdax_msgs *libdax_messenger; #include #endif /* Libburn_log_in_and_out_streaM */ +/* ts B41126 : O_BINARY is needed for Cygwin but undefined elsewhere */ +#ifndef O_BINARY +#define O_BINARY 0 +#endif /*static unsigned char isrc[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";*/ @@ -109,7 +113,8 @@ static void get_bytes(struct burn_track *track, int count, unsigned char *data) static int tee_fd= -1; if(tee_fd==-1) tee_fd= open("/tmp/libburn_sg_readin", - O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR); + O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, + S_IRUSR | S_IWUSR); #endif /* Libburn_log_in_and_out_streaM */ diff --git a/libburn/sg-dummy.c b/libburn/sg-dummy.c index f9b6e40..fefcaeb 100644 --- a/libburn/sg-dummy.c +++ b/libburn/sg-dummy.c @@ -35,6 +35,11 @@ Present implementation: default dummy which enables libburn only to work #include #endif /* Libburn_os_has_stavtfS */ +/* ts B41126 : O_BINARY is needed for Cygwin but undefined elsewhere */ +#ifndef O_BINARY +#define O_BINARY 0 +#endif + #include "transport.h" #include "drive.h" #include "sg.h" @@ -277,7 +282,7 @@ int burn_os_stdio_capacity(char *path, off_t write_start, off_t *bytes) long blocks; blocks = *bytes / 512; - fd = open(path, open_mode); + fd = open(path, open_mode | O_BINARY); if (fd == -1) {ret = -2; goto ex;} ret = ioctl(fd, BLKGETSIZE, &blocks); @@ -330,7 +335,7 @@ int burn_os_open_track_src(char *path, int open_flags, int flag) { int fd; - fd = open(path, open_flags); + fd = open(path, open_flags | O_BINARY); return fd; } diff --git a/libburn/sg-libcdio.c b/libburn/sg-libcdio.c index b2a63e2..eb852f4 100644 --- a/libburn/sg-libcdio.c +++ b/libburn/sg-libcdio.c @@ -1,7 +1,7 @@ /* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */ /* - Copyright (c) 2009 - 2013 Thomas Schmitt + Copyright (c) 2009 - 2014 Thomas Schmitt Provided under GPL version 2 or later. */ @@ -149,6 +149,11 @@ Send feedback to libburn-hackers@pykix.org . #include #include +/* ts B41126 : O_BINARY is needed for Cygwin but undefined elsewhere */ +#ifndef O_BINARY +#define O_BINARY 0 +#endif + /* The waiting time before eventually retrying a failed SCSI command. Before each retry wait Libburn_sg_linux_retry_incR longer than with @@ -895,7 +900,7 @@ int burn_os_stdio_capacity(char *path, off_t write_start, off_t *bytes) /* GNU/Linux specific determination of block device size */ } else if(S_ISBLK(stbuf.st_mode)) { - int open_mode = O_RDONLY, fd; + int open_mode = O_RDONLY | O_BINARY, fd; long blocks; blocks = *bytes / 512; @@ -915,7 +920,7 @@ int burn_os_stdio_capacity(char *path, off_t write_start, off_t *bytes) } else if(S_ISCHR(stbuf.st_mode)) { int fd; - fd = open(path, O_RDONLY); + fd = open(path, O_RDONLY | O_BINARY); if (fd == -1) {ret = -2; goto ex;} ret = ioctl(fd, DIOCGMEDIASIZE, &add_size); @@ -929,7 +934,7 @@ int burn_os_stdio_capacity(char *path, off_t write_start, off_t *bytes) #ifdef Libburn_is_on_solariS } else if(S_ISBLK(stbuf.st_mode)) { - int open_mode = O_RDONLY, fd; + int open_mode = O_RDONLY | O_BINARY, fd; fd = open(path, open_mode); if (fd == -1) @@ -985,7 +990,7 @@ int burn_os_open_track_src(char *path, int open_flags, int flag) { int fd; - fd = open(path, open_flags); + fd = open(path, open_flags | O_BINARY); return fd; } diff --git a/libburn/structure.c b/libburn/structure.c index 859485f..69d5292 100644 --- a/libburn/structure.c +++ b/libburn/structure.c @@ -1,6 +1,6 @@ /* Copyright (c) 2004 - 2006 Derek Foreman, Ben Jansens - Copyright (c) 2006 - 2012 Thomas Schmitt + Copyright (c) 2006 - 2014 Thomas Schmitt Provided under GPL version 2 or later. */ @@ -21,6 +21,11 @@ #include #include +/* ts B41126 : O_BINARY is needed for Cygwin but undefined elsewhere */ +#ifndef O_BINARY +#define O_BINARY 0 +#endif + #include "libburn.h" #include "structure.h" #include "write.h" @@ -1483,7 +1488,7 @@ static int cue_create_file_source(char *path, struct burn_cue_file_cursor *crs, if (ret <= 0) goto ex; } else { - fd = open(path, O_RDONLY); + fd = open(path, O_RDONLY | O_BINARY); if (fd == -1) { sprintf(msg, "In cue sheet: Cannot open FILE '%.4000s'", diff --git a/libburn/write.c b/libburn/write.c index 9729832..282d1fb 100644 --- a/libburn/write.c +++ b/libburn/write.c @@ -38,6 +38,11 @@ #include #include +/* ts B41126 : O_BINARY is needed for Cygwin but undefined elsewhere */ +#ifndef O_BINARY +#define O_BINARY 0 +#endif + #include "error.h" #include "sector.h" #include "libburn.h" @@ -1795,7 +1800,8 @@ static int transact_dvd_chunk(struct burn_write_opts *opts, static int tee_fd= -1; if(tee_fd==-1) tee_fd= open("/tmp/libburn_sg_readin", - O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR); + O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, + S_IRUSR | S_IWUSR); #endif /* Libburn_log_in_and_out_streaM */ @@ -2524,7 +2530,7 @@ int burn_stdio_open_write(struct burn_drive *d, off_t start_byte, if (fd >= 0) fd = dup(fd); /* check validity and make closeable */ else - fd = open(d->devname, mode, + fd = open(d->devname, mode | O_BINARY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (fd == -1) { libdax_msgs_submit(libdax_messenger, d->global_index,