|
a/src/utils/conftree.cpp |
|
b/src/utils/conftree.cpp |
|
... |
|
... |
583 |
#include <iostream>
|
583 |
#include <iostream>
|
584 |
#include <list>
|
584 |
#include <list>
|
585 |
|
585 |
|
586 |
#include "conftree.h"
|
586 |
#include "conftree.h"
|
587 |
#include "smallut.h"
|
587 |
#include "smallut.h"
|
|
|
588 |
#include "readfile.h"
|
588 |
|
589 |
|
589 |
using namespace std;
|
590 |
using namespace std;
|
590 |
|
591 |
|
591 |
static char *thisprog;
|
592 |
static char *thisprog;
|
592 |
|
|
|
593 |
static void caterrno(string *reason)
|
|
|
594 |
{
|
|
|
595 |
#define ERRBUFSZ 200
|
|
|
596 |
char errbuf[ERRBUFSZ];
|
|
|
597 |
if (reason) {
|
|
|
598 |
#ifdef sun
|
|
|
599 |
// Note: sun strerror is noted mt-safe ??
|
|
|
600 |
*reason += string("file_to_string: open failed: ") + strerror(errno);
|
|
|
601 |
#else
|
|
|
602 |
strerror_r(errno, errbuf, ERRBUFSZ);
|
|
|
603 |
*reason += string("file_to_string: open failed: ") + errbuf;
|
|
|
604 |
#endif
|
|
|
605 |
}
|
|
|
606 |
}
|
|
|
607 |
static bool file_to_string(const string &fn, string &data, string *reason)
|
|
|
608 |
{
|
|
|
609 |
bool ret = false;
|
|
|
610 |
int fd = open(fn.c_str(), O_RDONLY);
|
|
|
611 |
if (fd < 0) {
|
|
|
612 |
caterrno(reason);
|
|
|
613 |
return false;
|
|
|
614 |
}
|
|
|
615 |
char buf[4096];
|
|
|
616 |
for (;;) {
|
|
|
617 |
int n = read(fd, buf, 4096);
|
|
|
618 |
if (n < 0) {
|
|
|
619 |
caterrno(reason);
|
|
|
620 |
goto out;
|
|
|
621 |
}
|
|
|
622 |
if (n == 0)
|
|
|
623 |
break;
|
|
|
624 |
try {
|
|
|
625 |
data.append(buf, n);
|
|
|
626 |
} catch (...) {
|
|
|
627 |
caterrno(reason);
|
|
|
628 |
goto out;
|
|
|
629 |
}
|
|
|
630 |
}
|
|
|
631 |
ret = true;
|
|
|
632 |
out:
|
|
|
633 |
if (fd >= 0)
|
|
|
634 |
close(fd);
|
|
|
635 |
return ret;
|
|
|
636 |
}
|
|
|
637 |
|
593 |
|
638 |
bool complex_updates(const string& fn)
|
594 |
bool complex_updates(const string& fn)
|
639 |
{
|
595 |
{
|
640 |
int fd;
|
596 |
int fd;
|
641 |
if ((fd = open(fn.c_str(), O_RDWR|O_TRUNC|O_CREAT, 0666)) < 0) {
|
597 |
if ((fd = open(fn.c_str(), O_RDWR|O_TRUNC|O_CREAT, 0666)) < 0) {
|