1
0
mirror of https://github.com/fumiama/base16384.git synced 2026-06-05 02:00:31 +08:00

chore: adapt to MSVC

This commit is contained in:
源文雨
2024-04-07 20:51:27 +09:00
parent 3b4925e013
commit 3ee12395e0
5 changed files with 52 additions and 19 deletions

View File

@@ -264,20 +264,20 @@ int base16384_decode_safe(const char* data, int dlen, char* buf) {
#else #else
register uint64_t sum = valbuf.val - 0x000000000000004e; register uint64_t sum = valbuf.val - 0x000000000000004e;
#endif #endif
buf[i++] = ((sum & 0x000000000000003f) << 2) | ((sum & 0x000000000000c000) >> 14); buf[i++] = (char)(((sum & 0x000000000000003f) << 2) | ((sum & 0x000000000000c000) >> 14));
if(offset--) { if(offset--) {
sum -= 0x00000000004e0000; sum -= 0x00000000004e0000;
buf[i++] = ((sum & 0x0000000000003f00) >> 6) | ((sum & 0x0000000000300000) >> 20); buf[i++] = (char)(((sum & 0x0000000000003f00) >> 6) | ((sum & 0x0000000000300000) >> 20));
if(offset--) { if(offset--) {
buf[i++] = ((sum & 0x00000000000f0000) >> 12) | ((sum & 0x00000000f0000000) >> 28); buf[i++] = (char)(((sum & 0x00000000000f0000) >> 12) | ((sum & 0x00000000f0000000) >> 28));
if(offset--) { if(offset--) {
sum -= 0x0000004e00000000; sum -= 0x0000004e00000000;
buf[i++] = ((sum & 0x000000000f000000) >> 20) | ((sum & 0x0000003c00000000) >> 34); buf[i++] = (char)(((sum & 0x000000000f000000) >> 20) | ((sum & 0x0000003c00000000) >> 34));
if(offset--) { if(offset--) {
buf[i++] = ((sum & 0x0000000300000000) >> 26) | ((sum & 0x0000fc0000000000) >> 42); buf[i++] = (char)(((sum & 0x0000000300000000) >> 26) | ((sum & 0x0000fc0000000000) >> 42));
if(offset--) { if(offset--) {
sum -= 0x004e000000000000; sum -= 0x004e000000000000;
buf[i] = ((sum & 0x0000030000000000) >> 34) | ((sum & 0x003f000000000000) >> 48); buf[i] = (char)(((sum & 0x0000030000000000) >> 34) | ((sum & 0x003f000000000000) >> 48));
} }
} }
} }
@@ -328,20 +328,20 @@ int base16384_decode(const char* data, int dlen, char* buf) {
#else #else
register uint64_t sum = vals[n] - 0x000000000000004e; register uint64_t sum = vals[n] - 0x000000000000004e;
#endif #endif
buf[i++] = ((sum & 0x000000000000003f) << 2) | ((sum & 0x000000000000c000) >> 14); buf[i++] = (char)(((sum & 0x000000000000003f) << 2) | ((sum & 0x000000000000c000) >> 14));
if(offset--) { if(offset--) {
sum -= 0x00000000004e0000; sum -= 0x00000000004e0000;
buf[i++] = ((sum & 0x0000000000003f00) >> 6) | ((sum & 0x0000000000300000) >> 20); buf[i++] = (char)(((sum & 0x0000000000003f00) >> 6) | ((sum & 0x0000000000300000) >> 20));
if(offset--) { if(offset--) {
buf[i++] = ((sum & 0x00000000000f0000) >> 12) | ((sum & 0x00000000f0000000) >> 28); buf[i++] = (char)(((sum & 0x00000000000f0000) >> 12) | ((sum & 0x00000000f0000000) >> 28));
if(offset--) { if(offset--) {
sum -= 0x0000004e00000000; sum -= 0x0000004e00000000;
buf[i++] = ((sum & 0x000000000f000000) >> 20) | ((sum & 0x0000003c00000000) >> 34); buf[i++] = (char)(((sum & 0x000000000f000000) >> 20) | ((sum & 0x0000003c00000000) >> 34));
if(offset--) { if(offset--) {
buf[i++] = ((sum & 0x0000000300000000) >> 26) | ((sum & 0x0000fc0000000000) >> 42); buf[i++] = (char)(((sum & 0x0000000300000000) >> 26) | ((sum & 0x0000fc0000000000) >> 42));
if(offset--) { if(offset--) {
sum -= 0x004e000000000000; sum -= 0x004e000000000000;
buf[i] = ((sum & 0x0000030000000000) >> 34) | ((sum & 0x003f000000000000) >> 48); buf[i] = (char)(((sum & 0x0000030000000000) >> 34) | ((sum & 0x003f000000000000) >> 48));
} }
} }
} }

View File

@@ -23,10 +23,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#endif #endif
#ifdef _MSC_VER
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif
enum base16384_err_t { enum base16384_err_t {
base16384_err_ok, base16384_err_ok,
@@ -63,6 +59,13 @@ typedef enum base16384_err_t base16384_err_t;
// forcely do sumcheck without checking data length // forcely do sumcheck without checking data length
#define BASE16384_FLAG_DO_SUM_CHECK_FORCELY (1<<2) #define BASE16384_FLAG_DO_SUM_CHECK_FORCELY (1<<2)
#ifdef _MSC_VER
#include <BaseTsd.h>
#ifndef ssize_t
#define SSIZE_T ssize_t;
#endif
#endif
/** /**
* @brief custom reader function interface * @brief custom reader function interface
* @param client_data the data pointer defined by the client * @param client_data the data pointer defined by the client
@@ -81,6 +84,12 @@ typedef ssize_t (*base16384_reader_t)(const void *client_data, void *buffer, siz
*/ */
typedef ssize_t (*base16384_writer_t)(const void *client_data, const void *buffer, size_t count); typedef ssize_t (*base16384_writer_t)(const void *client_data, const void *buffer, size_t count);
#ifdef _MSC_VER
#ifdef ssize_t
#undef ssize_t
#endif
#endif
union base16384_io_function_t { union base16384_io_function_t {
base16384_reader_t reader; base16384_reader_t reader;
base16384_writer_t writer; base16384_writer_t writer;

View File

@@ -90,7 +90,11 @@
// initial sum value used in BASE16384_FLAG_SUM_CHECK_ON_REMAIN // initial sum value used in BASE16384_FLAG_SUM_CHECK_ON_REMAIN
#define BASE16384_SIMPLE_SUM_INIT_VALUE (0x8e29c213) #define BASE16384_SIMPLE_SUM_INIT_VALUE (0x8e29c213)
#ifdef _MSC_VER
static inline uint32_t calc_sum(uint32_t sum, int cnt, const char* encbuf) {
#else
static inline uint32_t calc_sum(uint32_t sum, size_t cnt, const char* encbuf) { static inline uint32_t calc_sum(uint32_t sum, size_t cnt, const char* encbuf) {
#endif
size_t i; size_t i;
uint32_t buf; uint32_t buf;
for(i = 0; i < cnt; i++) { for(i = 0; i < cnt; i++) {

20
file.c
View File

@@ -16,6 +16,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifdef _MSC_VER
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#endif
#ifndef __cosmopolitan #ifndef __cosmopolitan
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
@@ -91,7 +97,11 @@ base16384_err_t base16384_encode_file_detailed(const char* input, const char* ou
fputc(0xFE, fpo); fputc(0xFE, fpo);
fputc(0xFF, fpo); fputc(0xFF, fpo);
} }
size_t cnt; #ifdef _MSC_VER
int cnt;
#else
size_t cnt;
#endif
uint32_t sum = BASE16384_SIMPLE_SUM_INIT_VALUE; uint32_t sum = BASE16384_SIMPLE_SUM_INIT_VALUE;
while((cnt = fread(encbuf, sizeof(char), inputsize, fp)) > 0) { while((cnt = fread(encbuf, sizeof(char), inputsize, fp)) > 0) {
int n; int n;
@@ -159,7 +169,11 @@ base16384_err_t base16384_encode_fp_detailed(FILE* input, FILE* output, char* en
} }
off_t inputsize = _BASE16384_ENCBUFSZ; off_t inputsize = _BASE16384_ENCBUFSZ;
uint32_t sum = BASE16384_SIMPLE_SUM_INIT_VALUE; uint32_t sum = BASE16384_SIMPLE_SUM_INIT_VALUE;
size_t cnt; #ifdef _MSC_VER
int cnt;
#else
size_t cnt;
#endif
while((cnt = fread(encbuf, sizeof(char), inputsize, input)) > 0) { while((cnt = fread(encbuf, sizeof(char), inputsize, input)) > 0) {
int n; int n;
while(cnt%7) { while(cnt%7) {
@@ -228,7 +242,7 @@ base16384_err_t base16384_encode_stream_detailed(base16384_stream_t* input, base
uint32_t sum = BASE16384_SIMPLE_SUM_INIT_VALUE; uint32_t sum = BASE16384_SIMPLE_SUM_INIT_VALUE;
if(!(flag&BASE16384_FLAG_NOHEADER)) call_writer(output, "\xfe\xff", 2); if(!(flag&BASE16384_FLAG_NOHEADER)) call_writer(output, "\xfe\xff", 2);
while((cnt = call_reader(input, encbuf, inputsize)) > 0) { while((cnt = call_reader(input, encbuf, inputsize)) > 0) {
int n; ssize_t n;
while(cnt%7) { while(cnt%7) {
n = call_reader(input, encbuf+cnt, sizeof(char)); n = call_reader(input, encbuf+cnt, sizeof(char));
if(n > 0) cnt++; if(n > 0) cnt++;

View File

@@ -19,6 +19,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifdef _MSC_VER
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#endif
#include <stdint.h> #include <stdint.h>
#define ok(has_failed, reason) \ #define ok(has_failed, reason) \