Switch to unified view

a/src/readfile.cpp b/src/readfile.cpp
...
...
63
63
64
bool file_to_string(const string& fn, string& data, string *reason)
64
bool file_to_string(const string& fn, string& data, string *reason)
65
{
65
{
66
    return file_to_string(fn, data, 0, size_t(-1), reason);
66
    return file_to_string(fn, data, 0, size_t(-1), reason);
67
}
67
}
68
bool file_to_string(const string& fn, string& data, off_t offs, size_t cnt,
68
bool file_to_string(const string& fn, string& data, int64_t offs, size_t cnt,
69
                    string *reason)
69
                    string *reason)
70
{
70
{
71
    FileToString accum(data);
71
    FileToString accum(data);
72
    return file_scan(fn, &accum, offs, cnt, reason);
72
    return file_scan(fn, &accum, offs, cnt, reason);
73
}
73
}
...
...
80
const int RDBUFSZ = 8192;
80
const int RDBUFSZ = 8192;
81
// Note: the fstat() + reserve() (in init()) calls divide cpu usage almost by 2
81
// Note: the fstat() + reserve() (in init()) calls divide cpu usage almost by 2
82
// on both linux i586 and macosx (compared to just append())
82
// on both linux i586 and macosx (compared to just append())
83
// Also tried a version with mmap, but it's actually slower on the mac and not
83
// Also tried a version with mmap, but it's actually slower on the mac and not
84
// faster on linux.
84
// faster on linux.
85
bool file_scan(const string& fn, FileScanDo* doer, off_t startoffs,
85
bool file_scan(const string& fn, FileScanDo* doer, int64_t startoffs,
86
               size_t cnttoread, string *reason)
86
               size_t cnttoread, string *reason)
87
{
87
{
88
    if (startoffs < 0) {
88
    if (startoffs < 0) {
89
        *reason += " file_scan: negative startoffs not allowed";
89
        *reason += " file_scan: negative startoffs not allowed";
90
        return false;
90
        return false;
...
...
119
        doer->init(size_t(st.st_size + 1), reason);
119
        doer->init(size_t(st.st_size + 1), reason);
120
    } else {
120
    } else {
121
        doer->init(0, reason);
121
        doer->init(0, reason);
122
    }
122
    }
123
123
124
    off_t curoffs = 0;
124
    int64_t curoffs = 0;
125
    if (startoffs > 0 && !fn.empty()) {
125
    if (startoffs > 0 && !fn.empty()) {
126
        if (lseek(fd, startoffs, SEEK_SET) != startoffs) {
126
        if (lseek(fd, startoffs, SEEK_SET) != startoffs) {
127
            catstrerror(reason, "lseek", errno);
127
            catstrerror(reason, "lseek", errno);
128
            return false;
128
            return false;
129
        }
129
        }
...
...
231
    exit(1);
231
    exit(1);
232
}
232
}
233
233
234
int main(int argc, const char **argv)
234
int main(int argc, const char **argv)
235
{
235
{
236
    off_t offs = 0;
236
    int64_t offs = 0;
237
    size_t cnt = size_t(-1);
237
    size_t cnt = size_t(-1);
238
    thisprog = argv[0];
238
    thisprog = argv[0];
239
    argc--;
239
    argc--;
240
    argv++;
240
    argv++;
241
241