#include <ventoy_define.h>
#include <ventoy_util.h>
-
static int g_tar_filenum = 0;
static char *g_tar_buffer = NULL;
static ventoy_file *g_tar_filelist = NULL;
return (uint64_t)GB;
}
-int ventoy_read_file_to_buf(const char *FileName, int ExtLen, void **Bufer, int *BufLen)
-{
- int FileSize;
- FILE *fp = NULL;
- void *Data = NULL;
-
-#if defined(_MSC_VER) || defined(WIN32)
- fopen_s(&fp, FileName, "rb");
-#else
- fp = fopen(FileName, "rb");
-#endif
- if (fp == NULL)
- {
- vlog("Failed to open file %s", FileName);
- return 1;
- }
-
- fseek(fp, 0, SEEK_END);
- FileSize = (int)ftell(fp);
-
- Data = malloc(FileSize + ExtLen);
- if (!Data)
- {
- fclose(fp);
- return 1;
- }
-
- fseek(fp, 0, SEEK_SET);
- fread(Data, 1, FileSize, fp);
-
- fclose(fp);
-
- *Bufer = Data;
- *BufLen = FileSize;
-
- return 0;
-}
-
ventoy_file * ventoy_tar_find_file(const char *path)
{
int i;
if (ventoy_decompress_tar(g_tar_buffer, TAR_BUF_MAX, &tarsize))
{
+ vlog("Failed to decompress tar\n");
return 1;
}
#endif
}
+static const char g_encoding_table[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
+ 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+ 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
+ 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
+ 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+ 'w', 'x', 'y', 'z', '0', '1', '2', '3',
+ '4', '5', '6', '7', '8', '9', '+', '/'};
+
+char * ventoy_base64_encode(const char *data, int input_length, int *output_length)
+{
+ int i = 0;
+ int j = 0;
+ char *encoded_data = NULL;
+ int mod_table[] = {0, 2, 1};
+
+ *output_length = 4 * ((input_length + 2) / 3);
+ encoded_data = malloc(*output_length + 4);
+ if (!encoded_data)
+ {
+ return NULL;
+ }
+
+ while (i < input_length)
+ {
+ unsigned int octet_a = i < input_length ? (unsigned char)data[i++] : 0;
+ unsigned int octet_b = i < input_length ? (unsigned char)data[i++] : 0;
+ unsigned int octet_c = i < input_length ? (unsigned char)data[i++] : 0;
+
+ unsigned int triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c;
+
+ encoded_data[j++] = g_encoding_table[(triple >> 3 * 6) & 0x3F];
+ encoded_data[j++] = g_encoding_table[(triple >> 2 * 6) & 0x3F];
+ encoded_data[j++] = g_encoding_table[(triple >> 1 * 6) & 0x3F];
+ encoded_data[j++] = g_encoding_table[(triple >> 0 * 6) & 0x3F];
+ }
+
+ for (i = 0; i < mod_table[input_length % 3]; i++)
+ {
+ encoded_data[*output_length - 1 - i] = '=';
+ }
+
+ return encoded_data;
+}