]>
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 "TianoCommon.h"
29 #include "EfiCompress.h"
40 Compresses the input files
44 argc - number of arguments passed into the command line.
45 argv[] - files to compress and files to output compressed data to.
49 int: 0 for successful execution of the function.
63 // Added for makefile debug - KCE
67 for (arg_counter
= 0; arg_counter
< argc
; arg_counter
++) {
68 printf ("%s ", argv
[arg_counter
]);
73 SrcBuffer
= DstBuffer
= NULL
;
75 infile
= outfile
= NULL
;
78 printf ("Usage: EFICOMPRESS <infile> <outfile>\n");
82 if ((outfile
= fopen (argv
[2], "wb")) == NULL
) {
83 printf ("Can't open output file\n");
87 if ((infile
= fopen (argv
[1], "rb")) == NULL
) {
88 printf ("Can't open input file\n");
92 // Get the size of source file
95 while (fread (Buffer
, 1, 1, infile
)) {
100 // Read in the source data
102 if ((SrcBuffer
= malloc (SrcSize
)) == NULL
) {
103 printf ("Can't allocate memory\n");
108 if (fread (SrcBuffer
, 1, SrcSize
, infile
) != SrcSize
) {
109 printf ("Can't read from source\n");
113 // Get destination data size and do the compression
116 Status
= Compress (SrcBuffer
, SrcSize
, DstBuffer
, &DstSize
);
117 if (Status
== EFI_BUFFER_TOO_SMALL
) {
118 if ((DstBuffer
= malloc (DstSize
)) == NULL
) {
119 printf ("Can't allocate memory\n");
123 Status
= Compress (SrcBuffer
, SrcSize
, DstBuffer
, &DstSize
);
126 if (EFI_ERROR (Status
)) {
127 printf ("Compress Error\n");
131 printf ("\nOrig Size = %ld\n", SrcSize
);
132 printf ("Comp Size = %ld\n", DstSize
);
134 if (DstBuffer
== NULL
) {
135 printf ("No destination to write to.\n");
139 // Write out the result
141 if (fwrite (DstBuffer
, 1, DstSize
, outfile
) != DstSize
) {
142 printf ("Can't write to destination file\n");