From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by mx.groups.io with SMTP id smtpd.web12.1024.1605165846094184222 for ; Wed, 11 Nov 2020 23:24:12 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=none, err=permanent DNS error (domain: byosoft.com.cn, ip: 58.240.74.242, mailfrom: gaoliming@byosoft.com.cn) Received: from DESKTOPS6D0PVI ([58.246.60.130]) (envelope-sender ) by 192.168.6.13 with ESMTP for ; Thu, 12 Nov 2020 15:23:57 +0800 X-WM-Sender: gaoliming@byosoft.com.cn X-WM-AuthFlag: YES X-WM-AuthUser: gaoliming@byosoft.com.cn From: "gaoliming" To: "'Yunhua Feng'" , Cc: "'Bob Feng'" , "'Yuwei Chen'" References: <20201110024108.2445-1-fengyunhua@byosoft.com.cn> In-Reply-To: <20201110024108.2445-1-fengyunhua@byosoft.com.cn> Subject: =?UTF-8?B?5Zue5aSNOiBbUEFUQ0hdIEJhc2VUb29sczogRml4IEJyb3RsaUNvbXByZXNzIHRvb2wgaXNzdWU=?= Date: Thu, 12 Nov 2020 15:23:59 +0800 Message-ID: <001501d6b8c4$ca15b790$5e4126b0$@byosoft.com.cn> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQEaVgJsdaSvxWEIOcM0qfUda0j4TKs83Qiw Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable Content-Language: zh-cn Reviewed-by: Liming Gao Tested-by: Liming Gao Thanks Liming > -----=D3=CA=BC=FE=D4=AD=BC=FE----- > =B7=A2=BC=FE=C8=CB: Yunhua Feng > =B7=A2=CB=CD=CA=B1=BC=E4: 2020=C4=EA11=D4=C210=C8=D5 10:41 > =CA=D5=BC=FE=C8=CB: devel@edk2.groups.io > =B3=AD=CB=CD: Bob Feng ; Liming Gao > ; Yuwei Chen > =D6=F7=CC=E2: [PATCH] BaseTools: Fix BrotliCompress tool issue >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2946 >=20 > This is the regression issue in BaseTools BrotliCompress after Brotli > is changed to submodule. BrotliCompress should store the source size > and scratch buffer size into the header of the compressed binary data. > But now, BrotliCompress doesn't store them. So, BrotliDecompress > can't work. >=20 > To fix this issue, BrotliCompress tool main() function should be = provided. > It needs to support the options of -e, -d, -o file, -g gap, -q level. >=20 > Cc: Bob Feng > Cc: Liming Gao > Cc: Yuwei Chen > Signed-off-by: Yunhua Feng > --- > .../WindowsLike/BrotliCompress.bat | 55 -- > .../Source/C/BrotliCompress/BrotliCompress.c | 572 > ++++++++++++++++++ > BaseTools/Source/C/BrotliCompress/GNUmakefile | 4 +- > BaseTools/Source/C/BrotliCompress/Makefile | 4 +- > 4 files changed, 576 insertions(+), 59 deletions(-) > delete mode 100644 > BaseTools/BinWrappers/WindowsLike/BrotliCompress.bat > create mode 100644 BaseTools/Source/C/BrotliCompress/BrotliCompress.c >=20 > diff --git a/BaseTools/BinWrappers/WindowsLike/BrotliCompress.bat > b/BaseTools/BinWrappers/WindowsLike/BrotliCompress.bat > deleted file mode 100644 > index 788c99a130..0000000000 > --- a/BaseTools/BinWrappers/WindowsLike/BrotliCompress.bat > +++ /dev/null > @@ -1,55 +0,0 @@ > -@REM @file > -@REM This script will exec Brotli tool with -e/-d options. > -@REM > -@REM Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.
> -@REM SPDX-License-Identifier: BSD-2-Clause-Patent > -@REM > - > -@echo off > -@setlocal > - > -set QLT=3D-q 9 -w 22 > -set ARGS=3D > - > -:Begin > -if "%1"=3D=3D"" goto End > - > -if "%1"=3D=3D"-d" ( > - set ARGS=3D%ARGS% %1 > - shift > - goto Begin > -) > - > -if "%1"=3D=3D"-e" ( > - shift > - goto Begin > -) > - > -if "%1"=3D=3D"-g" ( > - set ARGS=3D%ARGS% %1 %2 > - shift > - shift > - goto Begin > -) > - > -if "%1"=3D=3D"-o" ( > - set ARGS=3D%ARGS% %1 %2 > - shift > - shift > - goto Begin > -) > - > -if "%1"=3D=3D"-q" ( > - set QLT=3D%1 %2 > - shift > - shift > - goto Begin > -) > - > -set ARGS=3D%ARGS% %1 > -shift > -goto Begin > - > -:End > -Brotli %QLT% %ARGS% > -@echo on > diff --git a/BaseTools/Source/C/BrotliCompress/BrotliCompress.c > b/BaseTools/Source/C/BrotliCompress/BrotliCompress.c > new file mode 100644 > index 0000000000..5a1400fda3 > --- /dev/null > +++ b/BaseTools/Source/C/BrotliCompress/BrotliCompress.c > @@ -0,0 +1,572 @@ > +/** @file > + BrotliCompress Compress/Decompress tool (BrotliCompress) > + > + Copyright (c) 2020, ByoSoft Corporation. All rights reserved.
> + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +/* Command line interface for Brotli library. */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "./brotli/c/common/constants.h" > +#include "./brotli/c/common/version.h" > +#include > +#include > + > +#if !defined(_WIN32) > +#include > +#include > +#else > +#include > +#include > +#include > + > +#if !defined(__MINGW32__) > +#define STDIN_FILENO _fileno(stdin) > +#define STDOUT_FILENO _fileno(stdout) > +#define S_IRUSR S_IREAD > +#define S_IWUSR S_IWRITE > +#endif > + > +#define fopen ms_fopen > +#define open ms_open > + > +#if defined(_MSC_VER) && (_MSC_VER >=3D 1400) > +#define fseek _fseeki64 > +#define ftell _ftelli64 > +#endif > + > +static FILE* ms_fopen(const char* FileName, const char* Mode) { > + FILE* Result; > + Result =3D NULL; > + fopen_s(&Result, FileName, Mode); > + return Result; > +} > + > +static int ms_open(const char* FileName, int Oflag, int Pmode) { > + int Result; > + Result =3D -1; > + _sopen_s(&Result, FileName, Oflag | O_BINARY, _SH_DENYNO, Pmode); > + return Result; > +} > +#endif /* WIN32 */ > + > + > +#ifndef _MAX_PATH > +#define _MAX_PATH 500 > +#endif > + > +#define DEFAULT_LGWIN 22 > +#define DECODE_HEADER_SIZE 0x10 > +#define GAP_MEM_BLOCK 0x1000 > +size_t ScratchBufferSize =3D 0; > +static const size_t kFileBufferSize =3D 1 << 19; > + > +static void Version(void) { > + int Major; > + int Minor; > + int Patch; > + Major =3D BROTLI_VERSION >> 24; > + Minor =3D (BROTLI_VERSION >> 12) & 0xFFF; > + Patch =3D BROTLI_VERSION & 0xFFF; > + printf("BrotliCompress %d.%d.%d\n", Major, Minor, Patch); > +} > + > +static void Usage() { > + printf("Usage: %s [OPTION]... [FILE]...\n", __FILE__); > + printf( > +"Options:\n" > +" -e, --compress compress\n" > +" -d, --decompress decompress\n" > +" -h, --help display this help and exit\n"); > + printf( > +" -o FILE, --output=3DFILE output file (only if 1 input = file)\n"); > + printf( > +" -g NUM, --gap=3DNUM scratch memory gap level (1-16)\n"); > + printf( > +" -q NUM, --quality=3DNUM compression level (%d-%d)\n", > + BROTLI_MIN_QUALITY, BROTLI_MAX_QUALITY); > + printf( > +" -v, --version display version and exit\n"); > +} > + > +static int64_t FileSize(const char* Path) { > + FILE *FileHandle; > + int64_t RetVal; > + FileHandle =3D fopen(Path, "rb"); > + > + if (FileHandle =3D=3D NULL) { > + printf ("Failed to open file [%s]\n", Path); > + return -1; > + } > + if (fseek(FileHandle, 0L, SEEK_END) !=3D 0) { > + printf ("Failed to seek file [%s]\n", Path); > + fclose(FileHandle); > + return -1; > + } > + RetVal =3D ftell(FileHandle); > + if (fclose(FileHandle) !=3D 0) { > + printf ("Failed to close file [%s]\n", Path); > + return -1; > + } > + return RetVal; > +} > + > +static BROTLI_BOOL HasMoreInput(FILE *FileHandle) { > + return feof(FileHandle) ? BROTLI_FALSE : BROTLI_TRUE; > +} > + > +int OpenFiles(char *InputFile, FILE **InHandle, char *OutputFile, = FILE > **OutHandle) { > + *InHandle =3D NULL; > + *OutHandle =3D NULL; > + *InHandle =3D fopen(InputFile, "rb"); > + if (*InHandle =3D=3D NULL) { > + printf("Failed to open input file [%s]\n", InputFile); > + return BROTLI_FALSE; > + } > + > + *OutHandle =3D fopen(OutputFile, "wb+"); > + if (*OutHandle =3D=3D NULL) { > + printf("Failed to open output file [%s]\n", OutputFile); > + fclose(*InHandle); > + return BROTLI_FALSE; > + } > + return BROTLI_TRUE; > +} > + > +int CompressFile(char *InputFile, uint8_t *InputBuffer, char = *OutputFile, > uint8_t *OutputBuffer, int Quality, int Gap) { > + int64_t InputFileSize; > + FILE *InputFileHandle; > + FILE *OutputFileHandle; > + BrotliEncoderState *EncodeState; > + uint32_t LgWin; > + BROTLI_BOOL IsEof; > + size_t AvailableIn; > + const uint8_t *NextIn; > + size_t AvailableOut; > + uint8_t *NextOut; > + uint8_t *Input; > + uint8_t *Output; > + size_t OutSize; > + uint32_t SizeHint; > + BROTLI_BOOL IsOk; > + AvailableIn =3D 0; > + IsEof =3D BROTLI_FALSE; > + Input =3D InputBuffer; > + Output =3D OutputBuffer; > + IsOk =3D BROTLI_TRUE; > + LgWin =3D DEFAULT_LGWIN; > + > + InputFileSize =3D FileSize(InputFile); > + > + IsOk =3D OpenFiles(InputFile, &InputFileHandle, OutputFile, > &OutputFileHandle); > + if (!IsOk) { > + return IsOk; > + } > + > + fseek (OutputFileHandle, DECODE_HEADER_SIZE, SEEK_SET); > + > + EncodeState =3D BrotliEncoderCreateInstance(NULL, NULL, NULL); > + if (!EncodeState) { > + printf("Out of memory\n"); > + IsOk =3D BROTLI_FALSE; > + goto Finish; > + } > + BrotliEncoderSetParameter(EncodeState, BROTLI_PARAM_QUALITY, > (uint32_t)Quality); > + > + if (InputFileSize >=3D 0) { > + LgWin =3D BROTLI_MIN_WINDOW_BITS; > + while (BROTLI_MAX_BACKWARD_LIMIT(LgWin) < InputFileSize) { > + LgWin++; > + if (LgWin =3D=3D BROTLI_MAX_WINDOW_BITS) { > + break; > + } > + } > + } > + BrotliEncoderSetParameter(EncodeState, BROTLI_PARAM_LGWIN, > LgWin); > + if (InputFileSize > 0) { > + SizeHint =3D InputFileSize < (1 << 30)? (uint32_t)InputFileSize : = (1u << 30); > + BrotliEncoderSetParameter(EncodeState, BROTLI_PARAM_SIZE_HINT, > SizeHint); > + } > + > + AvailableIn =3D 0; > + NextIn =3D NULL; > + AvailableOut =3D kFileBufferSize; > + NextOut =3D Output; > + for (;;) { > + if (AvailableIn =3D=3D 0 && !IsEof) { > + AvailableIn =3D fread(Input, 1, kFileBufferSize, = InputFileHandle); > + NextIn =3D Input; > + if (ferror(InputFileHandle)) { > + printf("Failed to read input [%s]\n", InputFile); > + IsOk =3D BROTLI_FALSE; > + goto Finish; > + } > + IsEof =3D !HasMoreInput(InputFileHandle); > + } > + > + if (!BrotliEncoderCompressStream(EncodeState, > + IsEof ? BROTLI_OPERATION_FINISH : BROTLI_OPERATION_PROCESS, > + &AvailableIn, &NextIn, &AvailableOut, &NextOut, NULL)) { > + printf("Failed to compress data [%s]\n", InputFile); > + IsOk =3D BROTLI_FALSE; > + goto Finish; > + } > + if (AvailableOut =3D=3D 0) { > + OutSize =3D (size_t)(NextOut - Output); > + if (OutSize > 0) { > + fwrite(Output, 1, OutSize, OutputFileHandle); > + if (ferror(OutputFileHandle)) { > + printf("Failed to write output [%s]\n", OutputFile); > + IsOk =3D BROTLI_FALSE; > + goto Finish; > + } > + } > + AvailableOut =3D kFileBufferSize; > + NextOut =3D Output; > + } > + if (BrotliEncoderIsFinished(EncodeState)) { > + OutSize =3D (size_t)(NextOut - Output); > + if (OutSize > 0) { > + fwrite(Output, 1, OutSize, OutputFileHandle); > + if (ferror(OutputFileHandle)) { > + printf("Failed to write output [%s]\n", OutputFile); > + IsOk =3D BROTLI_FALSE; > + goto Finish; > + } > + AvailableOut =3D 0; > + } > + } > + if (IsEof) { > + break; > + } > + } > + > +Finish: > + if (EncodeState) { > + BrotliEncoderDestroyInstance(EncodeState); > + } > + if (InputFileHandle) { > + fclose(InputFileHandle); > + } > + if (OutputFileHandle) { > + fclose(OutputFileHandle); > + } > + return IsOk; > +} > + > +/* Default BrotliAllocFunc */ > +void* BrotliAllocFunc(void* Opaque, size_t Size) { > + *(size_t *)Opaque =3D *(size_t *) Opaque + Size; > + return malloc(Size); > +} > + > +/* Default BrotliFreeFunc */ > +void BrotliFreeFunc(void* Opaque, void* Address) { > + free(Address); > +} > + > +int DecompressFile(char *InputFile, uint8_t *InputBuffer, char *OutputFile, > uint8_t *OutputBuffer, int Quality, int Gap) { > + FILE *InputFileHandle; > + FILE *OutputFileHandle; > + BrotliDecoderState *DecoderState; > + BrotliDecoderResult Result; > + size_t AvailableIn; > + const uint8_t *NextIn; > + size_t AvailableOut; > + uint8_t *NextOut; > + uint8_t *Input; > + uint8_t *Output; > + size_t OutSize; > + BROTLI_BOOL IsOk; > + AvailableIn =3D 0; > + Input =3D InputBuffer; > + Output =3D OutputBuffer; > + IsOk =3D BROTLI_TRUE; > + > + IsOk =3D OpenFiles(InputFile, &InputFileHandle, OutputFile, > &OutputFileHandle); > + if (!IsOk) { > + return IsOk; > + } > + fseek(InputFileHandle, DECODE_HEADER_SIZE, SEEK_SET); > + > + DecoderState =3D BrotliDecoderCreateInstance(BrotliAllocFunc, > BrotliFreeFunc, &ScratchBufferSize); > + if (!DecoderState) { > + printf("Out of memory\n"); > + IsOk =3D BROTLI_FALSE; > + goto Finish; > + } > + /* This allows decoding "large-window" streams. Though it creates > + fragmentation (new builds decode streams that old builds = don't), > + it is better from used experience perspective. */ > + BrotliDecoderSetParameter(DecoderState, > BROTLI_DECODER_PARAM_LARGE_WINDOW, 1u); > + > + AvailableIn =3D 0; > + NextIn =3D NULL; > + AvailableOut =3D kFileBufferSize; > + NextOut =3D Output; > + Result =3D BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT; > + for (;;) { > + if (Result =3D=3D BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT) { > + if (!HasMoreInput(InputFileHandle)) { > + printf("Corrupt input [%s]\n", InputFile); > + IsOk =3D BROTLI_FALSE; > + goto Finish; > + } > + AvailableIn =3D fread(Input, 1, kFileBufferSize, = InputFileHandle); > + NextIn =3D Input; > + if (ferror(InputFileHandle)) { > + printf("Failed to read input [%s]\n", InputFile); > + IsOk =3D BROTLI_FALSE; > + goto Finish; > + } > + } else if (Result =3D=3D BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT) > { > + OutSize =3D (size_t) (NextOut - Output); > + if (OutSize > 0) { > + fwrite(Output, 1, OutSize, OutputFileHandle); > + if (ferror(OutputFileHandle)) { > + printf("Failed to write output [%s]\n", OutputFile); > + IsOk =3D BROTLI_FALSE; > + goto Finish; > + } > + } > + AvailableOut =3D kFileBufferSize; > + NextOut =3D Output; > + } else if (Result =3D=3D BROTLI_DECODER_RESULT_SUCCESS) { > + OutSize =3D (size_t) (NextOut - Output); > + if (OutSize > 0) { > + fwrite(Output, 1, OutSize, OutputFileHandle); > + if (ferror(OutputFileHandle)) { > + printf("Failed to write output [%s]\n", OutputFile); > + IsOk =3D BROTLI_FALSE; > + goto Finish; > + } > + } > + AvailableOut =3D 0; > + if (AvailableIn !=3D 0 || HasMoreInput(InputFileHandle)) { > + printf("Corrupt input [%s]\n", InputFile); > + IsOk =3D BROTLI_FALSE; > + goto Finish; > + } > + } else { > + printf("Corrupt input [%s]\n", InputFile); > + IsOk =3D BROTLI_FALSE; > + goto Finish; > + } > + if (!HasMoreInput(InputFileHandle) && Result =3D=3D > BROTLI_DECODER_RESULT_SUCCESS ) { > + break; > + } > + Result =3D BrotliDecoderDecompressStream(DecoderState, = &AvailableIn, > &NextIn, &AvailableOut, &NextOut, 0); > + } > +Finish: > + if (DecoderState) { > + BrotliDecoderDestroyInstance(DecoderState); > + } > + if (InputFileHandle) { > + fclose(InputFileHandle); > + } > + if (OutputFileHandle) { > + fclose(OutputFileHandle); > + } > + return IsOk; > +} > + > +int main(int argc, char** argv) { > + BROTLI_BOOL CompressBool; > + BROTLI_BOOL DecompressBool; > + char *OutputFile; > + char *InputFile; > + char OutputTmpFile[_MAX_PATH]; > + FILE *OutputHandle; > + int Quality; > + int Gap; > + int OutputFileLength; > + int InputFileLength; > + int Ret; > + size_t InputFileSize; > + uint8_t *Buffer; > + uint8_t *InputBuffer; > + uint8_t *OutputBuffer; > + int64_t Size; > + > + InputFile =3D NULL; > + OutputFile =3D NULL; > + CompressBool =3D BROTLI_FALSE; > + DecompressBool =3D BROTLI_FALSE; > + // > + //Set default Quality and Gap > + // > + Quality =3D 9; > + Gap =3D 1; > + InputFileSize =3D 0; > + Ret =3D 0; > + > + if (argc < 2) { > + Usage(); > + return 1; > + } > + if (strcmp(argv[1], "-h") =3D=3D 0 || strcmp (argv[1], "--help") = =3D=3D 0 ) { > + Usage(); > + return 0; > + } > + if (strcmp(argv[1], "-v") =3D=3D 0 || strcmp (argv[1], "--version") = =3D=3D 0 ) { > + Version(); > + return 0; > + } > + while (argc > 1) { > + if (strcmp(argv[1], "-e") =3D=3D 0 || strcmp(argv[1], = "--compress") =3D=3D 0 ) { > + CompressBool =3D BROTLI_TRUE; > + if (DecompressBool) { > + printf("Can't use -e/--compress with -d/--decompess on the = same > time\n"); > + return 1; > + } > + argc--; > + argv++; > + continue; > + } > + if (strcmp(argv[1], "-d") =3D=3D 0 || strcmp(argv[1], = "--decompress") =3D=3D 0 ) { > + DecompressBool =3D BROTLI_TRUE; > + if (CompressBool) { > + printf("Can't use -e/--compress with -d/--decompess on the = same > time\n"); > + return 1; > + } > + argc--; > + argv++; > + continue; > + } > + if (strcmp(argv[1], "-o") =3D=3D 0 || strncmp(argv[1], = "--output", 8) =3D=3D 0) { > + if (strcmp(argv[1], "-o") =3D=3D 0) { > + OutputFileLength =3D strlen(argv[2]); > + if (OutputFileLength > _MAX_PATH) { > + printf ("The file path %s is too long\n", argv[2]); > + return 1; > + } > + OutputFile =3D argv[2]; > + if (OutputFile =3D=3D NULL) { > + fprintf(stderr, "Input file can't be null\n"); > + return 1; > + } > + argc--; > + argv++; > + } else { > + OutputFileLength =3D strlen(argv[1] - 9); > + OutputFile =3D (char *)argv[1] + 9; > + } > + argc--; > + argv++; > + continue; > + } > + if (strcmp(argv[1], "-q") =3D=3D 0 || strncmp(argv[1], = "--quality", 9) =3D=3D 0) { > + if (strcmp(argv[1], "-q") =3D=3D 0) { > + Quality =3D strtol(argv[2], NULL, 16); > + argc--; > + argv++; > + } else { > + Quality =3D strtol((char *)argv[1] + 10, NULL, 16); > + } > + argc--; > + argv++; > + continue; > + } > + if (strcmp(argv[1], "-g") =3D=3D 0 || strncmp(argv[1], "--gap", = 5) =3D=3D 0) { > + if (strcmp(argv[1], "-g") =3D=3D 0) { > + Gap =3D strtol(argv[2], NULL, 16); > + argc--; > + argv++; > + } else { > + Gap =3D strtol((char *)argv[1] + 6, NULL, 16); > + } > + argc--; > + argv++; > + continue; > + } > + if (argc > 1) { > + InputFileLength =3D strlen(argv[1]); > + if (InputFileLength > _MAX_PATH - 1) { > + printf ("The file path %s is too long\n", argv[2]); > + return 1; > + } > + InputFile =3D argv[1]; > + if (InputFile =3D=3D NULL) { > + printf("Input file can't be null\n"); > + return 1; > + } > + argc--; > + argv++; > + } > + } > + > + Buffer =3D (uint8_t*)malloc(kFileBufferSize * 2); > + if (!Buffer) { > + printf("Out of memory\n"); > + goto Finish; > + } > + memset(Buffer, 0, kFileBufferSize*2); > + InputBuffer =3D Buffer; > + OutputBuffer =3D Buffer + kFileBufferSize; > + if (CompressBool) { > + // > + // Compress file > + // > + Ret =3D CompressFile(InputFile, InputBuffer, OutputFile, = OutputBuffer, > Quality, Gap); > + if (!Ret) { > + printf ("Failed to compress file [%s]\n", InputFile); > + goto Finish; > + } > + // > + // Decompress file for get Outputfile size > + // > + strcpy (OutputTmpFile, OutputFile); > + if (strlen(InputFile) + strlen(".tmp") < _MAX_PATH) { > + strcat(OutputTmpFile, ".tmp"); > + } else { > + printf ("Output file path is too long[%s]\n", OutputFile); > + Ret =3D BROTLI_FALSE; > + goto Finish; > + } > + memset(Buffer, 0, kFileBufferSize*2); > + Ret =3D DecompressFile(OutputFile, InputBuffer, OutputTmpFile, > OutputBuffer, Quality, Gap); > + if (!Ret) { > + printf ("Failed to decompress file [%s]\n", OutputFile); > + goto Finish; > + } > + remove (OutputTmpFile); > + > + // > + // fill decoder header > + // > + InputFileSize =3D FileSize(InputFile); > + Size =3D (int64_t)InputFileSize; > + OutputHandle =3D fopen(OutputFile, "rb+"); /* open output_path = file and > add in head info */ > + fwrite(&Size, 1, sizeof(int64_t), OutputHandle); > + ScratchBufferSize +=3D Gap * GAP_MEM_BLOCK; /* there is a memory > gap between IA32 and X64 environment*/ > + ScratchBufferSize +=3D kFileBufferSize * 2; > + Size =3D (int64_t) ScratchBufferSize; > + fwrite(&Size, 1, sizeof(int64_t), OutputHandle); > + if (fclose(OutputHandle) !=3D 0) { > + printf("Failed to close output file [%s]\n", OutputFile); > + Ret =3D BROTLI_FALSE; > + goto Finish; > + } > + } else { > + Ret =3D DecompressFile(InputFile, InputBuffer, OutputFile, OutputBuffer, > Quality, Gap); > + if (!Ret) { > + printf ("Failed to decompress file [%s]\n", InputFile); > + goto Finish; > + } > + } > + Finish: > + if (Buffer !=3D NULL) { > + free (Buffer); > + } > + return !Ret; > +} > diff --git a/BaseTools/Source/C/BrotliCompress/GNUmakefile > b/BaseTools/Source/C/BrotliCompress/GNUmakefile > index 9544837263..b150e5dd2b 100644 > --- a/BaseTools/Source/C/BrotliCompress/GNUmakefile > +++ b/BaseTools/Source/C/BrotliCompress/GNUmakefile > @@ -6,10 +6,10 @@ > # > MAKEROOT ?=3D .. >=20 > -APPNAME =3D Brotli > +APPNAME =3D BrotliCompress >=20 > OBJECTS =3D \ > - brotli/c/tools/brotli.o \ > + BrotliCompress.o \ > brotli/c/common/dictionary.o \ > brotli/c/common/transform.o \ > brotli/c/dec/bit_reader.o \ > diff --git a/BaseTools/Source/C/BrotliCompress/Makefile > b/BaseTools/Source/C/BrotliCompress/Makefile > index b805ff1e58..038d1ec242 100644 > --- a/BaseTools/Source/C/BrotliCompress/Makefile > +++ b/BaseTools/Source/C/BrotliCompress/Makefile > @@ -9,7 +9,7 @@ > INC =3D -I .\brotli\c\include $(INC) > CFLAGS =3D $(CFLAGS) /W2 >=20 > -APPNAME =3D Brotli > +APPNAME =3D BrotliCompress >=20 > #LIBS =3D $(LIB_PATH)\Common.lib >=20 > @@ -40,7 +40,7 @@ ENC_OBJ =3D \ > brotli\c\enc\utf8_util.obj >=20 > OBJECTS =3D \ > - brotli\c\tools\brotli.obj \ > + BrotliCompress.obj \ > $(COMMON_OBJ) \ > $(DEC_OBJ) \ > $(ENC_OBJ) > -- > 2.27.0.windows.1