Commit f2b600b2 authored by Ed Maste's avatar Ed Maste
Browse files

intel-ucode-split: add -n flag to skip creating output files

Sponsored by:	The FreeBSD Foundation
parent 3a327967
......@@ -112,7 +112,7 @@ static void
usage(void)
{
printf("ucode-split [-v] microcode_file\n");
printf("ucode-split [-nv] microcode_file\n");
exit(1);
}
......@@ -124,11 +124,14 @@ main(int argc, char *argv[])
size_t len, resid;
ssize_t rv;
int c, ifd, ofd;
bool vflag;
bool nflag, vflag;
vflag = false;
while ((c = getopt(argc, argv, "v")) != -1) {
nflag = vflag = false;
while ((c = getopt(argc, argv, "nv")) != -1) {
switch (c) {
case 'n':
nflag = true;
break;
case 'v':
vflag = true;
break;
......@@ -166,13 +169,24 @@ main(int argc, char *argv[])
if (vflag)
dump_header(&hdr);
resid = (hdr.total_size != 0 ? hdr.total_size : 2048) -
sizeof(hdr);
if (resid > 1 << 24) /* Arbitrary chosen maximum size. */
errx(1, "header total_size too large");
if (nflag) {
if (lseek(ifd, resid, SEEK_CUR) == -1)
err(1, "lseek");
printf("\n");
} else {
sig_str = format_signature(hdr.processor_signature);
asprintf(&output_file, "%s.%02x", sig_str,
hdr.processor_flags & 0xff);
free(sig_str);
if (output_file == NULL)
err(1, "asprintf");
ofd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
ofd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC,
0600);
if (ofd < 0)
err(1, "open");
......@@ -182,10 +196,6 @@ main(int argc, char *argv[])
err(1, "write");
/* Copy data. */
resid = (hdr.total_size != 0 ? hdr.total_size : 2048) -
sizeof(hdr);
if (resid > 1 << 24) /* Arbitrary chosen maximum size. */
errx(1, "header total_size too large");
while (resid > 0) {
len = resid < bufsize ? resid : bufsize;
rv = read(ifd, buf, len);
......@@ -202,4 +212,5 @@ main(int argc, char *argv[])
close(ofd);
free(output_file);
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment