mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-06-26 16:41:42 +00:00
mkenvimage: More error handling
Verbosly fail if the target environment size or the padding byte are badly formated. Verbosly fail if something bad happens when reading from standard input. Signed-off-by: David Wagner <david.wagner@free-electrons.com> Acked-by: Mike Frysinger <vapier@gentoo.org>
This commit is contained in:
parent
d1acdae986
commit
3d0f9bd034
1 changed files with 29 additions and 2 deletions
|
@ -63,6 +63,24 @@ static void usage(const char *exec_name)
|
||||||
exec_name);
|
exec_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long int xstrtol(const char *s)
|
||||||
|
{
|
||||||
|
long int tmp;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
tmp = strtol(s, NULL, 0);
|
||||||
|
if (!errno)
|
||||||
|
return tmp;
|
||||||
|
|
||||||
|
if (errno == ERANGE)
|
||||||
|
fprintf(stderr, "Bad integer format: %s\n", s);
|
||||||
|
else
|
||||||
|
fprintf(stderr, "Error while parsing %s: %s\n", s,
|
||||||
|
strerror(errno));
|
||||||
|
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
uint32_t crc, targetendian_crc;
|
uint32_t crc, targetendian_crc;
|
||||||
|
@ -92,7 +110,7 @@ int main(int argc, char **argv)
|
||||||
while ((option = getopt(argc, argv, ":s:o:rbp:hV")) != -1) {
|
while ((option = getopt(argc, argv, ":s:o:rbp:hV")) != -1) {
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case 's':
|
case 's':
|
||||||
datasize = strtol(optarg, NULL, 0);
|
datasize = xstrtol(optarg);
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
bin_filename = strdup(optarg);
|
bin_filename = strdup(optarg);
|
||||||
|
@ -108,7 +126,7 @@ int main(int argc, char **argv)
|
||||||
bigendian = 1;
|
bigendian = 1;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
padbyte = strtol(optarg, NULL, 0);
|
padbyte = xstrtol(optarg);
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
usage(prg);
|
usage(prg);
|
||||||
|
@ -166,7 +184,16 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
filebuf = realloc(filebuf, readlen);
|
filebuf = realloc(filebuf, readlen);
|
||||||
|
if (!filebuf) {
|
||||||
|
fprintf(stderr, "Can't realloc memory for the input file buffer\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
readbytes = read(txt_fd, filebuf + filesize, readlen);
|
readbytes = read(txt_fd, filebuf + filesize, readlen);
|
||||||
|
if (errno) {
|
||||||
|
fprintf(stderr, "Error while reading stdin: %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
filesize += readbytes;
|
filesize += readbytes;
|
||||||
} while (readbytes == readlen);
|
} while (readbytes == readlen);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue