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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utility/Makefile ('k') | utility/efidecompress.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 */ 4 */
5 5
6 /*++ 6 /*++
7 7
8 Copyright (c) 2006, Intel Corporation 8 Copyright (c) 2006, Intel Corporation
9 All rights reserved. This program and the accompanying materials 9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD Licens e 10 are licensed and made available under the terms and conditions of the BSD Licens e
(...skipping 1589 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 1600
1601 mSortPtr = CodeParm; 1601 mSortPtr = CodeParm;
1602 MakeLen(k); 1602 MakeLen(k);
1603 MakeCode(NParm, LenParm, CodeParm); 1603 MakeCode(NParm, LenParm, CodeParm);
1604 1604
1605 // 1605 //
1606 // return root 1606 // return root
1607 // 1607 //
1608 return k; 1608 return k;
1609 } 1609 }
1610
1611
1612 #ifdef STANDALONE
1613 int main(int argc, char *argv[])
1614 {
1615 char *progname;
1616 int retval = 1;
1617
1618 progname = strrchr(argv[0], '/');
1619 if (progname)
1620 progname++;
1621 else
1622 progname = argv[0];
1623
1624 if (argc != 3)
1625 {
1626 fprintf(stderr, "\nUsage: %s INFILE OUTFILE\n\n", progname);
1627 exit(1);
1628 }
1629
1630 char *infile = argv[1];
1631 char *outfile = argv[2];
1632
1633 struct stat istat;
1634 if (0 != stat(infile, &istat)) {
1635 fprintf(stderr, "%s: can't stat %s: %s\n",
1636 progname,
1637 infile,
1638 strerror(errno));
1639 exit(1);
1640 }
1641 uint32_t isize = (uint32_t)istat.st_size;
1642
1643 printf("%s is %d bytes\n", infile, isize);
1644
1645 FILE *ifp = fopen(infile, "rb");
1646 if (!ifp)
1647 {
1648 fprintf(stderr, "%s: can't read %s: %s\n",
1649 progname,
1650 infile,
1651 strerror(errno));
1652 exit(1);
1653 }
1654 printf("opened %s\n", infile);
1655
1656 // read input file into buffer
1657 uint8_t *ibuf = malloc(isize);
1658 if (!ibuf) {
1659 fprintf(stderr, "%s: can't malloc %d bytes: %s\n",
1660 progname,
1661 isize,
1662 strerror(errno));
1663 goto done1;
1664 }
1665 if (1 != fread(ibuf, isize, 1, ifp)) {
1666 fprintf(stderr, "%s: can't read %d bytes: %s\n",
1667 progname,
1668 isize,
1669 strerror(errno));
1670 goto done2;
1671 }
1672
1673 // assume compression will actually work
1674 uint32_t osize = isize;
1675 uint8_t *obuf = malloc(osize);
1676 if (!obuf) {
1677 fprintf(stderr, "%s: can't allocate %d bytes: %s\n",
1678 progname,
1679 osize,
1680 strerror(errno));
1681 goto done2;
1682 }
1683
1684 // try it and see
1685 EFI_STATUS r = EfiCompress(ibuf, isize, obuf, &osize);
1686 if (r != EFI_SUCCESS) {
1687 fprintf(stderr, "%s: compression failed with code %d\n",
1688 progname,
1689 r);
1690 goto done3;
1691 }
1692
1693 printf("Compressed %d bytes to %d bytes\n", isize, osize);
1694
1695 // Write it out
1696 FILE *ofp = fopen(outfile, "wb");
1697 if (!ofp)
1698 {
1699 fprintf(stderr, "%s: can't open %s for writing: %s\n",
1700 progname,
1701 outfile,
1702 strerror(errno));
1703 goto done3;
1704 }
1705 printf("opened %s\n", outfile);
1706
1707 if (1 != fwrite(obuf, osize, 1, ofp)) {
1708 fprintf(stderr, "%s: can't write %d bytes: %s\n",
1709 progname,
1710 osize,
1711 strerror(errno));
1712 goto done4;
1713 }
1714
1715 printf("wrote %d bytes to %s\n", osize, outfile);
1716 retval = 0;
1717
1718 done4:
1719 fclose(ofp);
1720
1721 done3:
1722 free(obuf);
1723
1724 done2:
1725 free(ibuf);
1726
1727 done1:
1728 fclose(ifp);
1729
1730 return retval;
1731 }
1732 #endif // STANDALONE
OLDNEW
« 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