fix errno printing
This commit is contained in:
parent
7cb1060893
commit
1173e00f19
@ -38,7 +38,7 @@ using std::string;
|
|||||||
|
|
||||||
#include "readfile.h"
|
#include "readfile.h"
|
||||||
|
|
||||||
static void caterrno(string *reason, const char *what)
|
static void caterrno(string *reason, const char *what, int _errno)
|
||||||
{
|
{
|
||||||
if (reason) {
|
if (reason) {
|
||||||
reason->append("file_to_string: ");
|
reason->append("file_to_string: ");
|
||||||
@ -46,11 +46,12 @@ static void caterrno(string *reason, const char *what)
|
|||||||
reason->append(": ");
|
reason->append(": ");
|
||||||
#ifdef sun
|
#ifdef sun
|
||||||
// Note: sun strerror is noted mt-safe ??
|
// Note: sun strerror is noted mt-safe ??
|
||||||
reason->append(strerror(errno));
|
reason->append(strerror(_errno));
|
||||||
#else
|
#else
|
||||||
#define ERRBUFSZ 200
|
#define ERRBUFSZ 200
|
||||||
char errbuf[ERRBUFSZ];
|
char errbuf[ERRBUFSZ];
|
||||||
strerror_r(errno, errbuf, ERRBUFSZ);
|
errbuf[0] = 0;
|
||||||
|
strerror_r(_errno, errbuf, ERRBUFSZ);
|
||||||
reason->append(errbuf);
|
reason->append(errbuf);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -69,7 +70,7 @@ public:
|
|||||||
try {
|
try {
|
||||||
m_data.append(buf, cnt);
|
m_data.append(buf, cnt);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
caterrno(reason, "append");
|
caterrno(reason, "append", errno);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -99,7 +100,7 @@ bool file_scan(const string &fn, FileScanDo* doer, string *reason)
|
|||||||
if (!fn.empty()) {
|
if (!fn.empty()) {
|
||||||
fd = open(fn.c_str(), O_RDONLY|O_STREAMING);
|
fd = open(fn.c_str(), O_RDONLY|O_STREAMING);
|
||||||
if (fd < 0 || fstat(fd, &st) < 0) {
|
if (fd < 0 || fstat(fd, &st) < 0) {
|
||||||
caterrno(reason, "open/stat");
|
caterrno(reason, "open/stat", errno);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
noclosing = false;
|
noclosing = false;
|
||||||
@ -112,7 +113,7 @@ bool file_scan(const string &fn, FileScanDo* doer, string *reason)
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
int n = read(fd, buf, 4096);
|
int n = read(fd, buf, 4096);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
caterrno(reason, "read");
|
caterrno(reason, "read", errno);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user