Switch to unified view

a/src/utils/readfile.cpp b/src/utils/readfile.cpp
...
...
20
#include <unistd.h>
20
#include <unistd.h>
21
#include <fcntl.h>
21
#include <fcntl.h>
22
#include <sys/types.h>
22
#include <sys/types.h>
23
#include <sys/stat.h>
23
#include <sys/stat.h>
24
24
25
#ifndef O_STREAMING
26
#define O_STREAMING 0
27
#endif
28
#include <errno.h>
25
#include <errno.h>
29
#include <cstdio>
26
#include <cstdio>
30
#include <cstring>
27
#include <cstring>
31
28
32
#include <string>
29
#include <string>
33
30
34
#ifndef NO_NAMESPACES
35
using std::string;
31
using std::string;
36
#endif /* NO_NAMESPACES */
37
32
38
#include "readfile.h"
33
#include "readfile.h"
39
#include "smallut.h"
34
#include "smallut.h"
40
35
41
#ifndef MIN
36
#ifndef MIN
...
...
76
bool file_scan(const string &fn, FileScanDo* doer, string *reason)
71
bool file_scan(const string &fn, FileScanDo* doer, string *reason)
77
{
72
{
78
    return file_scan(fn, doer, 0, size_t(-1), reason);
73
    return file_scan(fn, doer, 0, size_t(-1), reason);
79
}
74
}
80
75
81
const int RDBUFSZ = 4096;
76
const int RDBUFSZ = 8192;
82
// Note: the fstat() + reserve() (in init()) calls divide cpu usage almost by 2
77
// Note: the fstat() + reserve() (in init()) calls divide cpu usage almost by 2
83
// on both linux i586 and macosx (compared to just append())
78
// on both linux i586 and macosx (compared to just append())
84
// Also tried a version with mmap, but it's actually slower on the mac and not
79
// Also tried a version with mmap, but it's actually slower on the mac and not
85
// faster on linux.
80
// faster on linux.
86
bool file_scan(const string &fn, FileScanDo* doer, off_t startoffs, 
81
bool file_scan(const string &fn, FileScanDo* doer, off_t startoffs, 
...
...
93
    // Initialize st_size: if fn.empty() , the fstat() call won't happen. 
88
    // Initialize st_size: if fn.empty() , the fstat() call won't happen. 
94
    st.st_size = 0;
89
    st.st_size = 0;
95
90
96
    // If we have a file name, open it, else use stdin.
91
    // If we have a file name, open it, else use stdin.
97
    if (!fn.empty()) {
92
    if (!fn.empty()) {
98
    fd = open(fn.c_str(), O_RDONLY|O_STREAMING);
93
    fd = open(fn.c_str(), O_RDONLY);
99
    if (fd < 0 || fstat(fd, &st) < 0) {
94
    if (fd < 0 || fstat(fd, &st) < 0) {
100
        catstrerror(reason, "open/stat", errno);
95
        catstrerror(reason, "open/stat", errno);
101
        return false;
96
        return false;
102
    }
97
    }
103
    noclosing = false;
98
    noclosing = false;
...
...
168
#include "autoconfig.h"
163
#include "autoconfig.h"
169
164
170
#include <stdio.h>
165
#include <stdio.h>
171
#include <sys/stat.h>
166
#include <sys/stat.h>
172
#include <stdlib.h>
167
#include <stdlib.h>
173
#include <unistd.h>
174
#include <sys/types.h>
168
#include <sys/types.h>
175
169
176
#include <string>
170
#include <string>
177
#include <iostream>
171
#include <iostream>
178
using namespace std;
172
using namespace std;