Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(445)

Unified Diff: utility/eficompress.c

Issue 6880176: Build EFI compression utilities on host (Closed) Base URL: ssh://gitrw.chromium.org:9222/vboot_reference.git@master
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utility/Makefile ('k') | utility/efidecompress.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utility/eficompress.c
diff --git a/utility/eficompress.c b/utility/eficompress.c
index b0cf4fb38f15d885522cac852bad512c9470c3f1..b59870062e2f92edaaf9edaa7b9f12dbecfecf27 100644
--- a/utility/eficompress.c
+++ b/utility/eficompress.c
@@ -1607,3 +1607,126 @@ Returns:
//
return k;
}
+
+
+#ifdef STANDALONE
+int main(int argc, char *argv[])
+{
+ char *progname;
+ int retval = 1;
+
+ progname = strrchr(argv[0], '/');
+ if (progname)
+ progname++;
+ else
+ progname = argv[0];
+
+ if (argc != 3)
+ {
+ fprintf(stderr, "\nUsage: %s INFILE OUTFILE\n\n", progname);
+ exit(1);
+ }
+
+ char *infile = argv[1];
+ char *outfile = argv[2];
+
+ struct stat istat;
+ if (0 != stat(infile, &istat)) {
+ fprintf(stderr, "%s: can't stat %s: %s\n",
+ progname,
+ infile,
+ strerror(errno));
+ exit(1);
+ }
+ uint32_t isize = (uint32_t)istat.st_size;
+
+ printf("%s is %d bytes\n", infile, isize);
+
+ FILE *ifp = fopen(infile, "rb");
+ if (!ifp)
+ {
+ fprintf(stderr, "%s: can't read %s: %s\n",
+ progname,
+ infile,
+ strerror(errno));
+ exit(1);
+ }
+ printf("opened %s\n", infile);
+
+ // read input file into buffer
+ uint8_t *ibuf = malloc(isize);
+ if (!ibuf) {
+ fprintf(stderr, "%s: can't malloc %d bytes: %s\n",
+ progname,
+ isize,
+ strerror(errno));
+ goto done1;
+ }
+ if (1 != fread(ibuf, isize, 1, ifp)) {
+ fprintf(stderr, "%s: can't read %d bytes: %s\n",
+ progname,
+ isize,
+ strerror(errno));
+ goto done2;
+ }
+
+ // assume compression will actually work
+ uint32_t osize = isize;
+ uint8_t *obuf = malloc(osize);
+ if (!obuf) {
+ fprintf(stderr, "%s: can't allocate %d bytes: %s\n",
+ progname,
+ osize,
+ strerror(errno));
+ goto done2;
+ }
+
+ // try it and see
+ EFI_STATUS r = EfiCompress(ibuf, isize, obuf, &osize);
+ if (r != EFI_SUCCESS) {
+ fprintf(stderr, "%s: compression failed with code %d\n",
+ progname,
+ r);
+ goto done3;
+ }
+
+ printf("Compressed %d bytes to %d bytes\n", isize, osize);
+
+ // Write it out
+ FILE *ofp = fopen(outfile, "wb");
+ if (!ofp)
+ {
+ fprintf(stderr, "%s: can't open %s for writing: %s\n",
+ progname,
+ outfile,
+ strerror(errno));
+ goto done3;
+ }
+ printf("opened %s\n", outfile);
+
+ if (1 != fwrite(obuf, osize, 1, ofp)) {
+ fprintf(stderr, "%s: can't write %d bytes: %s\n",
+ progname,
+ osize,
+ strerror(errno));
+ goto done4;
+ }
+
+ printf("wrote %d bytes to %s\n", osize, outfile);
+ retval = 0;
+
+done4:
+ fclose(ofp);
+
+done3:
+ free(obuf);
+
+done2:
+ free(ibuf);
+
+done1:
+ fclose(ifp);
+
+ return retval;
+}
+#endif // STANDALONE
« no previous file with comments | « utility/Makefile ('k') | utility/efidecompress.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698