]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/CCode/Source/CompressDll/CompressDll.c
More moves for Tool Packages
[mirror_edk2.git] / Tools / CCode / Source / CompressDll / CompressDll.c
1 /** @file
2 Compression DLL used by PCD Tools
3
4 Copyright (c) 2006, Intel Corporation All rights reserved.
5 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14 #if defined(__GNUC__)
15 typedef long long __int64;/*For cygwin build*/
16 #endif
17 #include "CompressDll.h"
18 #include "EfiCompress.h"
19
20 extern
21 EFI_STATUS
22 Compress (
23 IN UINT8 *SrcBuffer,
24 IN UINT32 SrcSize,
25 IN UINT8 *DstBuffer,
26 IN OUT UINT32 *DstSize
27 );
28
29 JNIEXPORT jbyteArray JNICALL Java_org_tianocore_framework_tasks_Compress_CallCompress
30 (JNIEnv *env, jobject obj, jbyteArray SourceBuffer, jint SourceSize, jstring path)
31 {
32 char* DestBuffer;
33 int DestSize;
34 int Result;
35 char *InputBuffer;
36 jbyteArray OutputBuffer;
37 jbyte *TempByte;
38
39 DestSize = 0;
40 DestBuffer = NULL;
41
42 TempByte = (*env)->GetByteArrayElements(env, SourceBuffer, 0);
43 InputBuffer = (char*) TempByte;
44
45
46 //
47 // First call compress function and get need buffer size
48 //
49
50 Result = Compress (
51 (char*) InputBuffer,
52 SourceSize,
53 DestBuffer,
54 &DestSize
55 );
56
57 if (Result = EFI_BUFFER_TOO_SMALL) {
58 DestBuffer = malloc (DestSize);
59 }
60
61 //
62 // Second call compress and get the DestBuffer value
63 //
64 Result = Compress(
65 (char*) InputBuffer,
66 SourceSize,
67 DestBuffer,
68 &DestSize
69 );
70
71 //
72 // new a MV array to store the return compressed buffer
73 //
74 OutputBuffer = (*env)->NewByteArray(env, DestSize);
75 (*env)->SetByteArrayRegion(env, OutputBuffer,0, DestSize, (jbyte*) DestBuffer);
76
77 //
78 // Free Ouputbuffer.
79 //
80 free (DestBuffer);
81
82
83 if (Result != 0) {
84 return NULL;
85 } else {
86 return OutputBuffer;
87 }
88 }
89
90 #ifdef _MSC_VER
91 BOOLEAN
92 __stdcall
93 DllMainCRTStartup(
94 unsigned int hDllHandle,
95 unsigned int nReason,
96 void* Reserved
97 )
98 {
99 return TRUE;
100 }
101 #else
102 #ifdef __GNUC__
103 #endif
104 #endif
105