diff options
author | Ulf Hermann <[email protected]> | 2017-05-04 12:07:54 +0200 |
---|---|---|
committer | Ulf Hermann <[email protected]> | 2017-05-08 09:36:02 +0000 |
commit | 0cfab8d6e47c165ee02d027c11b9a11c726516fa (patch) | |
tree | 07868d226de62c4f9fd80ddb7882fe19151445b0 /src/ar.c | |
parent | 8ac52d75d47da355c4ace3224161de097db3e8d9 (diff) |
Open files in O_BINARY
If O_BINARY is not defined, define it to 0, so that the change has no
effect then. Some systems have separate binary and text modes for files,
and we don't want the text mode to be used.
Change-Id: If7efb5bd448c2a1c7d1eb5dab276849b1b15a3ce
Reviewed-by: Christian Kandeler <[email protected]>
Diffstat (limited to 'src/ar.c')
-rw-r--r-- | src/ar.c | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -393,14 +393,14 @@ open_archive (const char *arfname, int flags, int mode, Elf **elf, if (elf != NULL) { - Elf_Cmd cmd = flags == O_RDONLY ? ELF_C_READ_MMAP : ELF_C_RDWR_MMAP; + Elf_Cmd cmd = flags == (O_RDONLY | O_BINARY) ? ELF_C_READ_MMAP : ELF_C_RDWR_MMAP; *elf = elf_begin (fd, cmd, NULL); if (*elf == NULL) error (EXIT_FAILURE, 0, gettext ("cannot open archive '%s': %s"), arfname, elf_errmsg (-1)); - if (flags == O_RDONLY && elf_kind (*elf) != ELF_K_AR) + if (flags == (O_RDONLY | O_BINARY) && elf_kind (*elf) != ELF_K_AR) error (EXIT_FAILURE, 0, gettext ("%s: not an archive file"), arfname); } @@ -467,7 +467,7 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc, int status = 0; Elf *elf; - int fd = open_archive (arfname, O_RDONLY, 0, &elf, NULL, false); + int fd = open_archive (arfname, O_RDONLY | O_BINARY, 0, &elf, NULL, false); if (hcreate (2 * argc) == 0) error (EXIT_FAILURE, errno, gettext ("cannot create hash table")); @@ -600,7 +600,7 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc, { /* We cannot create a temporary file. Try to overwrite the file or create it if it does not exist. */ - int flags = O_WRONLY | O_CREAT; + int flags = O_WRONLY | O_BINARY | O_CREAT; if (dont_replace_existing) flags |= O_EXCL; else @@ -919,7 +919,7 @@ do_oper_delete (const char *arfname, char **argv, int argc, int status = 0; Elf *elf; struct stat st; - int fd = open_archive (arfname, O_RDONLY, 0, &elf, &st, false); + int fd = open_archive (arfname, O_RDONLY | O_BINARY, 0, &elf, &st, false); if (hcreate (2 * argc) == 0) error (EXIT_FAILURE, errno, gettext ("cannot create hash table")); @@ -1099,7 +1099,7 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc, int status = 0; Elf *elf; struct stat st; - int fd = open_archive (arfname, O_RDONLY, 0, &elf, &st, oper != oper_move); + int fd = open_archive (arfname, O_RDONLY | O_BINARY, 0, &elf, &st, oper != oper_move); /* List of the files we keep. */ struct armem *all = NULL; @@ -1255,7 +1255,7 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc, struct stat newst; Elf *newelf; - int newfd = open (argv[cnt], O_RDONLY); + int newfd = open (argv[cnt], O_RDONLY | O_BINARY); if (newfd == -1) { error (0, errno, gettext ("cannot open %s"), argv[cnt]); @@ -1399,7 +1399,7 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc, newfd = mkstemp (tmpfname); else { - newfd = open (arfname, O_RDWR | O_CREAT | O_EXCL, DEFFILEMODE); + newfd = open (arfname, O_RDWR | O_BINARY | O_CREAT | O_EXCL, DEFFILEMODE); if (newfd == -1 && errno == EEXIST) /* Bah, first the file did not exist, now it does. Restart. */ return do_oper_insert (oper, arfname, argv, argc, member); |