From aea2ee257728846a31535ba367da7e7d14a2fa7c Mon Sep 17 00:00:00 2001 From: Derek Date: Mon, 19 Jul 2010 19:05:51 -0400 Subject: [PATCH] Added cross-platform LFS for tell/seek. Removed fopen64/freopen64 - hopefully unecessary with -D_FILE_OFFSET_BITS=64 compiler flag --- BGZF.cpp | 17 ++++++++++------- BGZF.h | 14 +++++++++++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/BGZF.cpp b/BGZF.cpp index 1d185ba..a9f2f56 100644 --- a/BGZF.cpp +++ b/BGZF.cpp @@ -3,7 +3,7 @@ // Marth Lab, Department of Biology, Boston College // All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 9 July 2010 (DB) +// Last modified: 19 July 2010 (DB) // --------------------------------------------------------------------------- // BGZF routines were adapted from the bgzf.c code developed at the Broad // Institute. @@ -232,15 +232,18 @@ bool BgzfData::Open(const string& filename, const char* mode) { // stdin/stdout option contributed by Aaron Quinlan (2010-Jan-03) if ( (filename != "stdin") && (filename != "stdout") ) { // read/write BGZF data to/from a file - Stream = fopen64(filename.c_str(), mode); +// Stream = fopen64(filename.c_str(), mode); + Stream = fopen(filename.c_str(), mode); } else if ( (filename == "stdin") && (strcmp(mode, "rb") == 0 ) ) { // read BGZF data from stdin - Stream = freopen64(NULL, mode, stdin); +// Stream = freopen64(NULL, mode, stdin); + Stream = freopen(NULL, mode, stdin); } else if ( (filename == "stdout") && (strcmp(mode, "wb") == 0) ) { // write BGZF data to stdout - Stream = freopen64(NULL, mode, stdout); +// Stream = freopen64(NULL, mode, stdout); + Stream = freopen(NULL, mode, stdout); } if(!Stream) { @@ -279,7 +282,7 @@ int BgzfData::Read(char* data, const unsigned int dataLength) { } if ( BlockOffset == BlockLength ) { - BlockAddress = ftello(Stream); + BlockAddress = ftell64(Stream); BlockOffset = 0; BlockLength = 0; } @@ -291,7 +294,7 @@ int BgzfData::Read(char* data, const unsigned int dataLength) { bool BgzfData::ReadBlock(void) { char header[BLOCK_HEADER_LENGTH]; - int64_t blockAddress = ftello(Stream); + int64_t blockAddress = ftell64(Stream); int count = fread(header, 1, sizeof(header), Stream); if (count == 0) { @@ -340,7 +343,7 @@ bool BgzfData::Seek(int64_t position) { int blockOffset = (position & 0xFFFF); int64_t blockAddress = (position >> 16) & 0xFFFFFFFFFFFFLL; - if (fseeko(Stream, blockAddress, SEEK_SET) != 0) { + if (fseek64(Stream, blockAddress, SEEK_SET) != 0) { printf("BGZF ERROR: unable to seek in file\n"); return false; } diff --git a/BGZF.h b/BGZF.h index 5904fe5..303684e 100644 --- a/BGZF.h +++ b/BGZF.h @@ -3,7 +3,7 @@ // Marth Lab, Department of Biology, Boston College // All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 9 July 2010 (DB) +// Last modified: 19 July 2010 (DB) // --------------------------------------------------------------------------- // BGZF routines were adapted from the bgzf.c code developed at the Broad // Institute. @@ -25,6 +25,18 @@ // zlib includes #include "zlib.h" +// Platform-specific large-file support +#ifndef BAMTOOLS_LFS +#define BAMTOOLS_LFS + #ifdef WIN32 + #define ftell64(a) _ftelli64(a) + #define fseek64(a,b,c) _fseeki64(a,b,c) + #else + #define ftell64(a) ftello(a) + #define fseek64(a,b,c) fseeko(a,b,c) + #endif +#endif // BAMTOOLS_LFS + // Platform-specific type definitions #ifndef BAMTOOLS_TYPES #define BAMTOOLS_TYPES -- 2.39.5