]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/TianoTools/EfiCompress/EfiCompressMain.c
3 Copyright (c) 1999-2006 Intel Corporation. All rights reserved
4 This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
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");