1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-25 17:58:27 +02:00

Cleaned up code that loads a manual from an OPK file

Most of it is for readability only, but there is also a leak that was
plugged: opk_close() is now called if extraction fails.
This commit is contained in:
Maarten ter Huurne 2015-04-25 15:26:50 +02:00
parent 00d3c3b570
commit 510d67359c

View File

@ -414,28 +414,21 @@ void LinkApp::showManual() {
#ifdef HAVE_LIBOPK #ifdef HAVE_LIBOPK
if (isOPK) { if (isOPK) {
vector<string> readme; struct OPK *opk = opk_open(opkFile.c_str());
char *ptr;
struct OPK *opk;
int err;
void *buf;
size_t len;
opk = opk_open(opkFile.c_str());
if (!opk) { if (!opk) {
WARNING("Unable to open OPK to read manual\n"); WARNING("Unable to open OPK to read manual\n");
return; return;
} }
err = opk_extract_file(opk, manual.c_str(), &buf, &len); void *buf;
size_t len;
int err = opk_extract_file(opk, manual.c_str(), &buf, &len);
opk_close(opk);
if (err < 0) { if (err < 0) {
WARNING("Unable to read manual from OPK\n"); WARNING("Unable to extract manual from OPK\n");
return; return;
} }
opk_close(opk); string str((char *) buf, len);
ptr = (char *) buf;
string str(ptr, len);
free(buf); free(buf);
if (manual.substr(manual.size()-8,8)==".man.txt") { if (manual.substr(manual.size()-8,8)==".man.txt") {