|
a/src/utils/readfile.cpp |
|
b/src/utils/readfile.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: readfile.cpp,v 1.7 2007-12-13 06:58:22 dockes Exp $ (C) 2004 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: readfile.cpp,v 1.8 2008-04-18 11:37:50 dockes Exp $ (C) 2004 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
/*
|
4 |
/*
|
5 |
* This program is free software; you can redistribute it and/or modify
|
5 |
* This program is free software; you can redistribute it and/or modify
|
6 |
* it under the terms of the GNU General Public License as published by
|
6 |
* it under the terms of the GNU General Public License as published by
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
... |
|
... |
49 |
}
|
49 |
}
|
50 |
|
50 |
|
51 |
bool file_to_string(const string &fn, string &data, string *reason)
|
51 |
bool file_to_string(const string &fn, string &data, string *reason)
|
52 |
{
|
52 |
{
|
53 |
bool ret = false;
|
53 |
bool ret = false;
|
|
|
54 |
bool noclosing = true;
|
|
|
55 |
int fd = 0;
|
54 |
|
56 |
|
|
|
57 |
if (!fn.empty()) {
|
55 |
int fd = open(fn.c_str(), O_RDONLY|O_STREAMING);
|
58 |
fd = open(fn.c_str(), O_RDONLY|O_STREAMING);
|
56 |
if (fd < 0) {
|
59 |
if (fd < 0) {
|
57 |
caterrno(reason);
|
60 |
caterrno(reason);
|
58 |
return false;
|
61 |
return false;
|
|
|
62 |
}
|
|
|
63 |
noclosing = false;
|
59 |
}
|
64 |
}
|
|
|
65 |
|
60 |
char buf[4096];
|
66 |
char buf[4096];
|
61 |
for (;;) {
|
67 |
for (;;) {
|
62 |
int n = read(fd, buf, 4096);
|
68 |
int n = read(fd, buf, 4096);
|
63 |
if (n < 0) {
|
69 |
if (n < 0) {
|
64 |
caterrno(reason);
|
70 |
caterrno(reason);
|
|
... |
|
... |
75 |
}
|
81 |
}
|
76 |
}
|
82 |
}
|
77 |
|
83 |
|
78 |
ret = true;
|
84 |
ret = true;
|
79 |
out:
|
85 |
out:
|
80 |
if (fd >= 0)
|
86 |
if (fd >= 0 && !noclosing)
|
81 |
close(fd);
|
87 |
close(fd);
|
82 |
return ret;
|
88 |
return ret;
|
83 |
}
|
89 |
}
|