Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 645225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:28:43+00:00 2026-05-13T21:28:43+00:00

I have a 2884765579 bytes file. This is double checked with this function, that

  • 0

I have a 2884765579 bytes file. This is double checked with this function, that returns that number:

size_t GetSize() {
       const size_t current_position = mFile.tellg();
       mFile.seekg(0, std::ios::end);
       const size_t ret = mFile.tellg();
       mFile.seekg(current_position);
       return ret;
    }

I then do:

mFile.seekg(pos, std::ios::beg);
// pos = 2883426827, which is < than the file size, 2884765579

This sets the failbit. errno is not changed. What steps can I take to troubleshoot this?


I am absolutely sure that:

  • The file size is really 2884765579
  • pos is really 2884765579
  • The failbit is not set before .seekg()
  • The failbit is set right after .seekg() and no other calls are made in between
  • The file is opened with the binary flag

EDIT: in case someone runs into the same problem.. Use this code I wrote (works on windows only) and many less headaches for you:

class BinaryIFile
{
public:
    BinaryIFile(const string& path) : mPath(path), mFileSize(0) {
        mFile = open(path.c_str(), O_RDONLY | O_BINARY);

        if (mFile == -1)
            FATAL(format("Cannot open %s: %s") % path.c_str() % strerror(errno));
    }
    ~BinaryIFile() {
        if (mFile != -1)
            close(mFile);
    }

    string GetPath() const { return mPath; }
    int64 GetSize() {
        if (mFileSize)
            return mFileSize;

        const int64 current_position = _telli64(mFile);
        _lseeki64(mFile, 0, SEEK_END);
        mFileSize = _telli64(mFile);
        _lseeki64(mFile, current_position, SEEK_SET);

        return mFileSize;
    }

    int64 Read64() { return _Read<int64>(); }
    int32 Read32() { return _Read<int32>(); }
    int16 Read16() { return _Read<int16>(); }
    int8 Read8() { return _Read<int8>(); }
    float ReadFloat() { return _Read<float>(); }
    double ReadDouble() { return _Read<double>(); }

    void Skip(int64 bytes) { _lseeki64(mFile, bytes, SEEK_CUR); }
    void Seek(int64 pos) { _lseeki64(mFile, pos, SEEK_SET); }
    int64 Tell() { return _telli64(mFile); }

    template <class T>
    T Read() { return _Read<T>(); }

    void Read(char *to, size_t size) {
        const int ret = read(mFile, (void *)to, size);
        if ((int)size != ret)
            FATAL(format("Read error: attempted to read %d bytes, read() returned %d, errno: %s [we are at offset %d, file size is %d]") % size % ret % strerror(errno) % Tell() % GetSize());
    }

    template <class T>
    BinaryIFile& operator>>(T& val) { val = _Read<T>(); return *this; }

private:
    const string mPath;
    int mFile;
    int64 mFileSize;

    template <class T>
    T _Read() { T ret; if (sizeof(ret) != read(mFile, (void *)&ret, sizeof(ret))) FATAL("Read error"); return ret; }
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:28:44+00:00Added an answer on May 13, 2026 at 9:28 pm

    You can seekg before a given position, so pos is signed. Try it with files of size 0x7fffffff and 0x80ffffff and see if the latter triggers the problem, that’s my guess.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 414k
  • Answers 415k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Have a look at EmbPerl. It's a Perl based templating… May 15, 2026 at 8:51 am
  • Editorial Team
    Editorial Team added an answer My solution for this was to setup a zip file… May 15, 2026 at 8:51 am
  • Editorial Team
    Editorial Team added an answer The standard library solves this problem using an allocator object… May 15, 2026 at 8:51 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.