|
a/HelperStructs/Helper.cpp |
|
b/HelperStructs/Helper.cpp |
|
... |
|
... |
20 |
#include <sys/stat.h>
|
20 |
#include <sys/stat.h>
|
21 |
#include <stdio.h>
|
21 |
#include <stdio.h>
|
22 |
#include <string.h>
|
22 |
#include <string.h>
|
23 |
#include <errno.h>
|
23 |
#include <errno.h>
|
24 |
#include <fcntl.h>
|
24 |
#include <fcntl.h>
|
25 |
#include <unistd.h>
|
|
|
26 |
|
25 |
|
27 |
#include <ctime>
|
26 |
#include <ctime>
|
28 |
#include <string>
|
27 |
#include <string>
|
29 |
#include <iostream>
|
28 |
#include <iostream>
|
30 |
#include <sstream>
|
29 |
#include <sstream>
|
|
... |
|
... |
46 |
#include "HelperStructs/globals.h"
|
45 |
#include "HelperStructs/globals.h"
|
47 |
#include "HelperStructs/CSettingsStorage.h"
|
46 |
#include "HelperStructs/CSettingsStorage.h"
|
48 |
|
47 |
|
49 |
using namespace std;
|
48 |
using namespace std;
|
50 |
|
49 |
|
51 |
QByteArray Helper::readFileToByteArray(const char *fn)
|
50 |
QByteArray Helper::readFileToByteArray(const QString& fn)
|
52 |
{
|
51 |
{
|
53 |
int fd = -1;
|
52 |
QFile qf(fn);
|
54 |
char *cp = 0;
|
|
|
55 |
QByteArray ret;
|
53 |
QByteArray ret;
|
56 |
struct stat st;
|
54 |
if (qf.open(QIODevice::ReadOnly)) {
|
57 |
|
55 |
ret = qf.read(1000 * 1000);
|
58 |
fd = open(fn, 0);
|
|
|
59 |
if (fd < 0 || fstat(fd, &st) < 0) {
|
|
|
60 |
qDebug() << "readfile: open/fstat [" << fn << "] errno " << errno;
|
|
|
61 |
goto out;
|
|
|
62 |
}
|
|
|
63 |
cp = (char *)malloc(st.st_size);
|
|
|
64 |
if (cp == 0) {
|
|
|
65 |
qDebug() << "readfile: no mem: can't allocate " << st.st_size;
|
|
|
66 |
goto out;
|
|
|
67 |
}
|
|
|
68 |
if (read(fd, cp, st.st_size) != st.st_size) {
|
|
|
69 |
qDebug() << "readfile: read [" << fn << "] errno " << errno;
|
|
|
70 |
goto out;
|
|
|
71 |
}
|
|
|
72 |
ret.append(cp, st.st_size);
|
|
|
73 |
out:
|
|
|
74 |
if (fd >= 0) {
|
|
|
75 |
close(fd);
|
|
|
76 |
}
|
|
|
77 |
if (cp) {
|
|
|
78 |
free(cp);
|
|
|
79 |
}
|
56 |
}
|
80 |
return ret;
|
57 |
return ret;
|
81 |
}
|
58 |
}
|
82 |
|
59 |
|
83 |
QString Helper::cvtQString2FirstUpper(QString str)
|
60 |
QString Helper::cvtQString2FirstUpper(QString str)
|