From 44d68c5746b436bd0984e52d4c111310d7701e7e Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Mon, 17 Oct 2005 15:31:10 +0000 Subject: [PATCH] Support for O_BINARY --- src/apprentice.c | 6 +++--- src/file.c | 3 +-- src/file.h | 7 ++++++- src/magic.c | 7 +++---- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/apprentice.c b/src/apprentice.c index f93ed361..977821f2 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -45,7 +45,7 @@ #endif #ifndef lint -FILE_RCSID("@(#)$Id: apprentice.c,v 1.84 2005/03/25 18:03:18 christos Exp $") +FILE_RCSID("@(#)$Id: apprentice.c,v 1.85 2005/10/17 15:31:10 christos Exp $") #endif /* lint */ #define EATAB {while (isascii((unsigned char) *l) && \ @@ -1059,7 +1059,7 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp, if (dbname == NULL) return -1; - if ((fd = open(dbname, O_RDONLY)) == -1) + if ((fd = open(dbname, O_RDONLY|O_BINARY)) == -1) return -1; if (fstat(fd, &st) == -1) { @@ -1149,7 +1149,7 @@ apprentice_compile(struct magic_set *ms, struct magic **magicp, if (dbname == NULL) return -1; - if ((fd = open(dbname, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) { + if ((fd = open(dbname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644)) == -1) { file_error(ms, errno, "cannot open `%s'", dbname); return -1; } diff --git a/src/file.c b/src/file.c index dd9bde7a..3a181762 100644 --- a/src/file.c +++ b/src/file.c @@ -39,7 +39,6 @@ #include #include /* for MAXPATHLEN */ #include -#include /* for open() */ #ifdef RESTORE_TIME # if (__COHERENT__ >= 0x420) # include @@ -72,7 +71,7 @@ #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$Id: file.c,v 1.97 2005/08/12 14:19:33 christos Exp $") +FILE_RCSID("@(#)$Id: file.c,v 1.98 2005/10/17 15:31:10 christos Exp $") #endif /* lint */ diff --git a/src/file.h b/src/file.h index 8e78a98f..bfc56499 100644 --- a/src/file.h +++ b/src/file.h @@ -27,7 +27,7 @@ */ /* * file.h - definitions for file(1) program - * @(#)$Id: file.h,v 1.70 2005/07/29 17:57:20 christos Exp $ + * @(#)$Id: file.h,v 1.71 2005/10/17 15:31:10 christos Exp $ */ #ifndef __file_h__ @@ -39,6 +39,7 @@ #include /* Include that here, to make sure __P gets defined */ #include +#include /* For open and flags #ifdef HAVE_STDINT_H #include #endif @@ -291,6 +292,10 @@ int snprintf(char *, size_t, const char *, ...); #define QUICK #endif +#ifndef O_BINARY +#define O_BINARY 0 +#endif + #define FILE_RCSID(id) \ static const char *rcsid(const char *p) { \ return rcsid(p = id); \ diff --git a/src/magic.c b/src/magic.c index 66a6302b..03d02915 100644 --- a/src/magic.c +++ b/src/magic.c @@ -35,7 +35,6 @@ #include #include /* for MAXPATHLEN */ #include -#include /* for open() */ #ifdef QUICK #include #endif @@ -63,7 +62,7 @@ #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$Id: magic.c,v 1.31 2005/10/17 15:14:44 christos Exp $") +FILE_RCSID("@(#)$Id: magic.c,v 1.32 2005/10/17 15:31:10 christos Exp $") #endif /* lint */ #ifdef __EMX__ @@ -246,11 +245,11 @@ magic_file(struct magic_set *ms, const char *inname) if (inname == NULL) fd = STDIN_FILENO; - else if ((fd = open(inname, O_RDONLY)) < 0) { + else if ((fd = open(inname, O_RDONLY|O_BINARY)) < 0) { #ifdef __CYGWIN__ char *tmp = alloca(strlen(inname) + 5); (void)strcat(strcpy(tmp, inname), ".exe"); - if ((fd = open(tmp, O_RDONLY)) < 0) { + if ((fd = open(tmp, O_RDONLY|O_BINARY)) < 0) { #endif /* We cannot open it, but we were able to stat it. */ if (sb.st_mode & 0222) -- 2.40.0