Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.
This repository was archived by the owner on May 31, 2025. It is now read-only.

Copy & Paste error in ChunkedFile::open? #1001

@racko

Description

@racko

if mode == "r+b" and file_ != NULL, we open the file with "w+b" on Windows and with "r+b" on Linux (or everywhere else, to be exact). Is this the intended behavior? Even if it is, I guess there should be a comment.

void ChunkedFile::open(string const& filename, string const& mode) {
    // Check if file is already open
    if (file_)
        throw BagIOException((format("File already open: %1%") % filename_.c_str()).str());

    // Open the file
    if (mode == "r+b") {
        // Read + write requires file to exists.  Create a new file if it doesn't exist.
        #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
            fopen_s( &file_, filename.c_str(), "r" );
        #else
            file_ = fopen(filename.c_str(), "r");
        #endif
        if (file_ == NULL)
            #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
                fopen_s( &file_, filename.c_str(), "w+b" );
            #else
                file_ = fopen(filename.c_str(), "w+b");
            #endif
        else {
            fclose(file_);
            #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
                fopen_s( &file_, filename.c_str(), "w+b" );
            #else
                file_ = fopen(filename.c_str(), "r+b");
            #endif
        }   
    }   
    else
        #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
            fopen_s( &file_, filename.c_str(), mode.c_str() );
        #else
            file_ = fopen(filename.c_str(), mode.c_str());
        #endif

    if (!file_)
        throw BagIOException((format("Error opening file: %1%") % filename.c_str()).str());

    read_stream_  = boost::make_shared<UncompressedStream>(this);
    write_stream_ = boost::make_shared<UncompressedStream>(this);
    filename_     = filename;
    offset_       = ftello(file_);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions