Fixed some compilation warnings.
Signed-off-by: Davide Fioravanti <pantanastyle@gmail.com>
{
struct stat s;
int fd = open(name, O_RDONLY);
{
struct stat s;
int fd = open(name, O_RDONLY);
err(1, "cannot open \"%s\"", name);
err(1, "cannot open \"%s\"", name);
- }
- if (fstat(fd, &s) == -1) {
+
+ if (fstat(fd, &s) == -1)
err(1, "cannot stat \"%s\"", name);
err(1, "cannot stat \"%s\"", name);
*size = s.st_size;
return fd;
}
*size = s.st_size;
return fd;
}
void *payload = (void *)h + sizeof(*h);
time_t t;
void *payload = (void *)h + sizeof(*h);
time_t t;
- if (source_date_epoch != -1) {
+ if (source_date_epoch != -1)
- } else if ((time(&t) == (time_t)(-1))) {
+ else if ((time(&t) == (time_t)(-1)))
err(1, "time call failed");
err(1, "time call failed");
- if (version != NULL) {
- if (sscanf(version, "%hu.%hu", &major, &minor) != 2) {
+
+ if (version != NULL)
+ if (sscanf(version, "%hu.%hu", &major, &minor) != 2)
err(1, "cannot parse version \"%s\"", version);
err(1, "cannot parse version \"%s\"", version);
memset(h, 0, sizeof(*h));
h->jh_magic = htonl(JH_MAGIC);
memset(h, 0, sizeof(*h));
h->jh_magic = htonl(JH_MAGIC);
a = ~dcrc;
for (i = 0; i < 32; i++) {
a = ~dcrc;
for (i = 0; i < 32; i++) {
patch = (patch >> 1) ^ 0xedb88320L;
patch = (patch >> 1) ^ 0xedb88320L;
a >>= 1;
}
patch ^= ~crc32(crc, buf, len - 4);
a >>= 1;
}
patch ^= ~crc32(crc, buf, len - 4);
/* Verify that we actually get the desired result */
crc = crc32(0L, Z_NULL, 0);
crc = crc32(crc, buf, len);
/* Verify that we actually get the desired result */
crc = crc32(0L, Z_NULL, 0);
crc = crc32(crc, buf, len);
errx(1, "CRC patching is broken: wanted %08x, but got %08x.",
dcrc, crc);
errx(1, "CRC patching is broken: wanted %08x, but got %08x.",
dcrc, crc);
imagefile = optarg;
break;
case 'k':
imagefile = optarg;
break;
case 'k':
- if (mode == MODE_UIMAGE) {
+ if (mode == MODE_UIMAGE)
errx(1,"-k cannot be combined with -u");
errx(1,"-k cannot be combined with -u");
mode = MODE_KR;
file1 = optarg;
break;
case 'f':
mode = MODE_KR;
file1 = optarg;
break;
case 'f':
- if (mode == MODE_UIMAGE) {
+ if (mode == MODE_UIMAGE)
errx(1,"-f cannot be combined with -u");
errx(1,"-f cannot be combined with -u");
mode = MODE_KR;
file2 = optarg;
break;
case 'u':
mode = MODE_KR;
file2 = optarg;
break;
case 'u':
errx(1,"-u cannot be combined with -k and -r");
errx(1,"-u cannot be combined with -k and -r");
mode = MODE_UIMAGE;
file1 = optarg;
break;
mode = MODE_UIMAGE;
file1 = optarg;
break;
errx(1, "illegal arg \"%s\"", argv[optind]);
errx(1, "illegal arg \"%s\"", argv[optind]);
- }
- if (imagefile == NULL) {
+
+ if (imagefile == NULL)
errx(1, "no output file specified");
errx(1, "no output file specified");
- }
- if (mode == MODE_UNKNOWN) {
+
+ if (mode == MODE_UNKNOWN)
errx(1, "specify either -u or -k and -r");
errx(1, "specify either -u or -k and -r");
- if (file1 == NULL || file2 == NULL) {
- errx(1,"need -k and -r");
- }
+ if (file1 == NULL || file2 == NULL)
+ errx(1, "need -k and -r");
+
fd2 = opensize(file2, &size2);
}
fd1 = opensize(file1, &size1);
fd2 = opensize(file2, &size2);
}
fd1 = opensize(file1, &size1);
sizeo = sizeof(*jh) + sizeu;
}
sizeo = sizeof(*jh) + sizeu;
}
- if (sizeo > MAXSIZE) {
- errx(1,"payload too large: %zd > %zd\n", sizeo, MAXSIZE);
- }
+ if (sizeo > MAXSIZE)
+ errx(1, "payload too large: %zd > %zd\n", sizeo, MAXSIZE);
+
fdo = open(imagefile, O_RDWR | O_CREAT | O_TRUNC, 00644);
fdo = open(imagefile, O_RDWR | O_CREAT | O_TRUNC, 00644);
err(1, "cannot open \"%s\"", imagefile);
err(1, "cannot open \"%s\"", imagefile);
- if (ftruncate(fdo, sizeo) == -1) {
+
+ if (ftruncate(fdo, sizeo) == -1)
err(1, "cannot grow \"%s\" to %zd bytes", imagefile, sizeo);
err(1, "cannot grow \"%s\" to %zd bytes", imagefile, sizeo);
map = mmap(NULL, sizeo, PROT_READ|PROT_WRITE, MAP_SHARED, fdo, 0);
uh = map + sizeof(*jh);
map = mmap(NULL, sizeo, PROT_READ|PROT_WRITE, MAP_SHARED, fdo, 0);
uh = map + sizeof(*jh);
- if (map == MAP_FAILED) {
err(1, "cannot mmap \"%s\"", imagefile);
err(1, "cannot mmap \"%s\"", imagefile);
- if (read(fd1, map + off1, size1) != size1) {
+
+ if (read(fd1, map + off1, size1) != size1)
err(1, "cannot copy %s", file1);
err(1, "cannot copy %s", file1);
- if (read(fd2, map+off2, size2) != size2) {
+ if (read(fd2, map+off2, size2) != size2)
err(1, "cannot copy %s", file2);
err(1, "cannot copy %s", file2);
mkuheader(uh, size1, size2);
mkuheader(uh, size1, size2);
- } else if (mode == MODE_UIMAGE) {
+ } else if (mode == MODE_UIMAGE)
craftcrc(ntohl(uh->ih_dcrc), (void*)uh + sizeof(*uh),
sizeu - sizeof(*uh));
craftcrc(ntohl(uh->ih_dcrc), (void*)uh + sizeof(*uh),
sizeu - sizeof(*uh));
mkjcgheader(map, sizeu, version);
munmap(map, sizeo);
close(fdo);
mkjcgheader(map, sizeu, version);
munmap(map, sizeo);
close(fdo);