fix portability issues and other minor bugs in the wrt350nv2 image builder
SVN-Revision: 18762
This commit is contained in:
parent
a5e97547c6
commit
54f40f36f7
1 changed files with 10 additions and 19 deletions
|
@ -73,6 +73,7 @@
|
||||||
#include <stdlib.h> // system(), etc.
|
#include <stdlib.h> // system(), etc.
|
||||||
#include <string.h> // basename(), strerror(), strdup(), etc.
|
#include <string.h> // basename(), strerror(), strdup(), etc.
|
||||||
#include <unistd.h> // optopt(), access(), etc.
|
#include <unistd.h> // optopt(), access(), etc.
|
||||||
|
#include <libgen.h>
|
||||||
#include <sys/wait.h> // WEXITSTATUS, etc.
|
#include <sys/wait.h> // WEXITSTATUS, etc.
|
||||||
|
|
||||||
// custom includes
|
// custom includes
|
||||||
|
@ -186,8 +187,8 @@ int parse_par_file(FILE *f_par) {
|
||||||
int lineno;
|
int lineno;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
char *string1;
|
char string1[64];
|
||||||
char *string2;
|
char string2[64];
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
mtd_info *mtd;
|
mtd_info *mtd;
|
||||||
|
@ -207,7 +208,7 @@ int parse_par_file(FILE *f_par) {
|
||||||
}
|
}
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
exitcode = 1;
|
exitcode = 1;
|
||||||
printf("parse_par_file: can not allocate %i bytes\n", buffer_size);
|
printf("parse_par_file: can not allocate %i bytes\n", (int) buffer_size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,15 +251,13 @@ int parse_par_file(FILE *f_par) {
|
||||||
|
|
||||||
lprintf(DEBUG_LVL2, " line %i (%i) %s", lineno, count, line);
|
lprintf(DEBUG_LVL2, " line %i (%i) %s", lineno, count, line);
|
||||||
|
|
||||||
string1 = NULL;
|
|
||||||
string2 = NULL;
|
|
||||||
value = 0;
|
value = 0;
|
||||||
mtd = NULL;
|
mtd = NULL;
|
||||||
|
|
||||||
// split line if starting with a colon
|
// split line if starting with a colon
|
||||||
switch (line[0]) {
|
switch (line[0]) {
|
||||||
case ':':
|
case ':':
|
||||||
count = sscanf(line, ":%ms %i %ms", &string1, &value, &string2);
|
count = sscanf(line, ":%64s %i %64s", string1, &value, string2);
|
||||||
if (count != 3) {
|
if (count != 3) {
|
||||||
printf("line %i does not meet defined format (:<mtdname> <mtdsize> <file>)\n", lineno);
|
printf("line %i does not meet defined format (:<mtdname> <mtdsize> <file>)\n", lineno);
|
||||||
} else {
|
} else {
|
||||||
|
@ -278,8 +277,7 @@ int parse_par_file(FILE *f_par) {
|
||||||
printf("mtd %s in line %i multiple definitions\n", string1, lineno);
|
printf("mtd %s in line %i multiple definitions\n", string1, lineno);
|
||||||
} else {
|
} else {
|
||||||
mtd->size = value;
|
mtd->size = value;
|
||||||
mtd->filename = string2;
|
mtd->filename = strdup(string2);
|
||||||
string2 = NULL; // do not free
|
|
||||||
|
|
||||||
// Get file size
|
// Get file size
|
||||||
f_in = fopen(mtd->filename, "rb");
|
f_in = fopen(mtd->filename, "rb");
|
||||||
|
@ -318,7 +316,7 @@ int parse_par_file(FILE *f_par) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '#': // integer values
|
case '#': // integer values
|
||||||
count = sscanf(line, "#%ms %i", &string1, &value);
|
count = sscanf(line, "#%64s %i", string1, &value);
|
||||||
if (count != 2) {
|
if (count != 2) {
|
||||||
printf("line %i does not meet defined format (:<variable name> <integer>\n", lineno);
|
printf("line %i does not meet defined format (:<variable name> <integer>\n", lineno);
|
||||||
} else {
|
} else {
|
||||||
|
@ -334,7 +332,7 @@ int parse_par_file(FILE *f_par) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '$': // strings
|
case '$': // strings
|
||||||
count = sscanf(line, "$%ms %ms", &string1, &string2);
|
count = sscanf(line, "$%64s %64s", string1, string2);
|
||||||
if (count != 2) {
|
if (count != 2) {
|
||||||
printf("line %i does not meet defined format (:<mtdname> <mtdsize> <file>)\n", lineno);
|
printf("line %i does not meet defined format (:<mtdname> <mtdsize> <file>)\n", lineno);
|
||||||
} else {
|
} else {
|
||||||
|
@ -352,13 +350,6 @@ int parse_par_file(FILE *f_par) {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string1) {
|
|
||||||
free(string1);
|
|
||||||
}
|
|
||||||
if (string2) {
|
|
||||||
free(string2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
|
@ -561,7 +552,7 @@ int create_zip_file(char *zip_filename, char *bin_filename) {
|
||||||
}
|
}
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
exitcode = 1;
|
exitcode = 1;
|
||||||
printf("create_zip_file: can not allocate %i bytes\n", buffer_size);
|
printf("create_zip_file: can not allocate %i bytes\n", (int) buffer_size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -979,7 +970,7 @@ int main(int argc, char *argv[]) {
|
||||||
if (mtd == &mtd_kernel) {
|
if (mtd == &mtd_kernel) {
|
||||||
if (mtd->filesize < 0x00050000) {
|
if (mtd->filesize < 0x00050000) {
|
||||||
exitcode = 1;
|
exitcode = 1;
|
||||||
printf("mtd %s input file %s too unrealistic small (0x%08lX)\n", mtd->name, mtd->filesize);
|
printf("mtd %s input file %s too unrealistic small (0x%08lX)\n", mtd->name, mtd->filename, mtd->filesize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue