]>
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.
29 #include <Common/UefiBaseTypes.h>
31 #include "EfiCompress.h"
42 Compresses the input files
46 argc - number of arguments passed into the command line.
47 argv[] - files to compress and files to output compressed data to.
51 int: 0 for successful execution of the function.
65 // Added for makefile debug - KCE
69 for (arg_counter
= 0; arg_counter
< argc
; arg_counter
++) {
70 printf ("%s ", argv
[arg_counter
]);
75 SrcBuffer
= DstBuffer
= NULL
;
77 infile
= outfile
= NULL
;
80 printf ("Usage: EFICOMPRESS <infile> <outfile>\n");
84 if ((outfile
= fopen (argv
[2], "wb")) == NULL
) {
85 printf ("Can't open output file\n");
89 if ((infile
= fopen (argv
[1], "rb")) == NULL
) {
90 printf ("Can't open input file\n");
94 // Get the size of source file
97 while (fread (Buffer
, 1, 1, infile
)) {
102 // Read in the source data
104 if ((SrcBuffer
= malloc (SrcSize
)) == NULL
) {
105 printf ("Can't allocate memory\n");
110 if (fread (SrcBuffer
, 1, SrcSize
, infile
) != SrcSize
) {
111 printf ("Can't read from source\n");
115 // Get destination data size and do the compression
118 Status
= Compress (SrcBuffer
, SrcSize
, DstBuffer
, &DstSize
);
119 if (Status
== EFI_BUFFER_TOO_SMALL
) {
120 if ((DstBuffer
= malloc (DstSize
)) == NULL
) {
121 printf ("Can't allocate memory\n");
125 Status
= Compress (SrcBuffer
, SrcSize
, DstBuffer
, &DstSize
);
128 if (EFI_ERROR (Status
)) {
129 printf ("Compress Error\n");
133 printf ("\nOrig Size = %ld\n", SrcSize
);
134 printf ("Comp Size = %ld\n", DstSize
);
136 if (DstBuffer
== NULL
) {
137 printf ("No destination to write to.\n");
141 // Write out the result
143 if (fwrite (DstBuffer
, 1, DstSize
, outfile
) != DstSize
) {
144 printf ("Can't write to destination file\n");