]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/TianoTools/EfiCompress/EfiCompressMain.c
3 Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
4 This software and associated documentation (if any) is furnished
5 under a license and may only be used or copied in accordance
6 with the terms of the license. Except as permitted by such
7 license, no part of this software or documentation may be
8 reproduced, stored in a retrieval system, or transmitted in any
9 form or by any means without the express written consent of
19 The main function for the compression utility.
28 #include <UefiBaseTypes.h>
30 #include "EfiCompress.h"
41 Compresses the input files
45 argc - number of arguments passed into the command line.
46 argv[] - files to compress and files to output compressed data to.
50 int: 0 for successful execution of the function.
64 // Added for makefile debug - KCE
68 for (arg_counter
= 0; arg_counter
< argc
; arg_counter
++) {
69 printf ("%s ", argv
[arg_counter
]);
74 SrcBuffer
= DstBuffer
= NULL
;
76 infile
= outfile
= NULL
;
79 printf ("Usage: EFICOMPRESS <infile> <outfile>\n");
83 if ((outfile
= fopen (argv
[2], "wb")) == NULL
) {
84 printf ("Can't open output file\n");
88 if ((infile
= fopen (argv
[1], "rb")) == NULL
) {
89 printf ("Can't open input file\n");
93 // Get the size of source file
96 while (fread (Buffer
, 1, 1, infile
)) {
101 // Read in the source data
103 if ((SrcBuffer
= malloc (SrcSize
)) == NULL
) {
104 printf ("Can't allocate memory\n");
109 if (fread (SrcBuffer
, 1, SrcSize
, infile
) != SrcSize
) {
110 printf ("Can't read from source\n");
114 // Get destination data size and do the compression
117 Status
= Compress (SrcBuffer
, SrcSize
, DstBuffer
, &DstSize
);
118 if (Status
== EFI_BUFFER_TOO_SMALL
) {
119 if ((DstBuffer
= malloc (DstSize
)) == NULL
) {
120 printf ("Can't allocate memory\n");
124 Status
= Compress (SrcBuffer
, SrcSize
, DstBuffer
, &DstSize
);
127 if (EFI_ERROR (Status
)) {
128 printf ("Compress Error\n");
132 printf ("\nOrig Size = %ld\n", SrcSize
);
133 printf ("Comp Size = %ld\n", DstSize
);
135 if (DstBuffer
== NULL
) {
136 printf ("No destination to write to.\n");
140 // Write out the result
142 if (fwrite (DstBuffer
, 1, DstSize
, outfile
) != DstSize
) {
143 printf ("Can't write to destination file\n");