mirror of
https://github.com/fumiama/base16384.git
synced 2026-06-12 07:20:23 +08:00
fix on windows
This commit is contained in:
22
32/base14.c
22
32/base14.c
@@ -18,6 +18,22 @@
|
|||||||
# define htobe16(x) ntohs(x)
|
# define htobe16(x) ntohs(x)
|
||||||
# define htobe32(x) htonl(x)
|
# define htobe32(x) htonl(x)
|
||||||
# define htobe64(x) htonll(x)
|
# define htobe64(x) htonll(x)
|
||||||
|
#elif defined(__WIN32__)
|
||||||
|
#ifdef WORDS_BIGENDIAN
|
||||||
|
# define be16toh(x) (x)
|
||||||
|
# define be32toh(x) (x)
|
||||||
|
# define be64toh(x) (x)
|
||||||
|
# define htobe16(x) (x)
|
||||||
|
# define htobe32(x) (x)
|
||||||
|
# define htobe64(x) (x)
|
||||||
|
#else
|
||||||
|
# define be16toh(x) __builtin_bswap16(x)
|
||||||
|
# define be32toh(x) __builtin_bswap32(x)
|
||||||
|
# define be64toh(x) __builtin_bswap64(x)
|
||||||
|
# define htobe16(x) __builtin_bswap16(x)
|
||||||
|
# define htobe32(x) __builtin_bswap32(x)
|
||||||
|
# define htobe64(x) __builtin_bswap64(x)
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#include "base14.h"
|
#include "base14.h"
|
||||||
|
|
||||||
@@ -75,7 +91,7 @@ LENDAT* encode(const uint8_t* data, const int32_t len) {
|
|||||||
if(o--) {
|
if(o--) {
|
||||||
sum |= ((uint32_t)data[i + 3] << 20) & 0x0f000000;
|
sum |= ((uint32_t)data[i + 3] << 20) & 0x0f000000;
|
||||||
sum += 0x004e004e;
|
sum += 0x004e004e;
|
||||||
#if BYTE_ORDER == BIG_ENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
vals[n++] = __builtin_bswap32(sum);
|
vals[n++] = __builtin_bswap32(sum);
|
||||||
#else
|
#else
|
||||||
vals[n++] = sum;
|
vals[n++] = sum;
|
||||||
@@ -93,7 +109,7 @@ LENDAT* encode(const uint8_t* data, const int32_t len) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sum += 0x004e004e;
|
sum += 0x004e004e;
|
||||||
#if BYTE_ORDER == BIG_ENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
vals[n] = __builtin_bswap32(sum);
|
vals[n] = __builtin_bswap32(sum);
|
||||||
#else
|
#else
|
||||||
vals[n] = sum;
|
vals[n] = sum;
|
||||||
@@ -146,7 +162,7 @@ LENDAT* decode(const uint8_t* data, const int32_t len) {
|
|||||||
}
|
}
|
||||||
if(offset--) {
|
if(offset--) {
|
||||||
//这里有读取越界
|
//这里有读取越界
|
||||||
#if BYTE_ORDER == BIG_ENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
register uint32_t sum = __builtin_bswap32(vals[n++]);
|
register uint32_t sum = __builtin_bswap32(vals[n++]);
|
||||||
#else
|
#else
|
||||||
register uint32_t sum = vals[n++];
|
register uint32_t sum = vals[n++];
|
||||||
|
|||||||
20
64/base14.c
20
64/base14.c
@@ -18,6 +18,22 @@
|
|||||||
# define htobe16(x) ntohs(x)
|
# define htobe16(x) ntohs(x)
|
||||||
# define htobe32(x) htonl(x)
|
# define htobe32(x) htonl(x)
|
||||||
# define htobe64(x) htonll(x)
|
# define htobe64(x) htonll(x)
|
||||||
|
#elif defined(__WIN64__)
|
||||||
|
#ifdef WORDS_BIGENDIAN
|
||||||
|
# define be16toh(x) (x)
|
||||||
|
# define be32toh(x) (x)
|
||||||
|
# define be64toh(x) (x)
|
||||||
|
# define htobe16(x) (x)
|
||||||
|
# define htobe32(x) (x)
|
||||||
|
# define htobe64(x) (x)
|
||||||
|
#else
|
||||||
|
# define be16toh(x) __builtin_bswap16(x)
|
||||||
|
# define be32toh(x) __builtin_bswap32(x)
|
||||||
|
# define be64toh(x) __builtin_bswap64(x)
|
||||||
|
# define htobe16(x) __builtin_bswap16(x)
|
||||||
|
# define htobe32(x) __builtin_bswap32(x)
|
||||||
|
# define htobe64(x) __builtin_bswap64(x)
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#include "base14.h"
|
#include "base14.h"
|
||||||
|
|
||||||
@@ -86,7 +102,7 @@ LENDAT* encode(const uint8_t* data, const int64_t len) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sum += 0x004e004e004e004e;
|
sum += 0x004e004e004e004e;
|
||||||
#if BYTE_ORDER == BIG_ENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
vals[n] = __builtin_bswap64(sum);
|
vals[n] = __builtin_bswap64(sum);
|
||||||
#else
|
#else
|
||||||
vals[n] = sum;
|
vals[n] = sum;
|
||||||
@@ -141,7 +157,7 @@ LENDAT* decode(const uint8_t* data, const int64_t len) {
|
|||||||
}
|
}
|
||||||
if(offset--) {
|
if(offset--) {
|
||||||
//这里有读取越界
|
//这里有读取越界
|
||||||
#if BYTE_ORDER == BIG_ENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
register uint64_t sum = __builtin_bswap64(vals[n]) - 0x000000000000004e;
|
register uint64_t sum = __builtin_bswap64(vals[n]) - 0x000000000000004e;
|
||||||
#else
|
#else
|
||||||
register uint64_t sum = vals[n] - 0x000000000000004e;
|
register uint64_t sum = vals[n] - 0x000000000000004e;
|
||||||
|
|||||||
@@ -4,6 +4,12 @@ SET(CMAKE_BUILD_TYPE "Release")
|
|||||||
|
|
||||||
add_executable(base16384 base16384.c)
|
add_executable(base16384 base16384.c)
|
||||||
|
|
||||||
|
include(TestBigEndian)
|
||||||
|
test_big_endian(isBigEndian)
|
||||||
|
if (${isBigEndian})
|
||||||
|
add_definitions(-DWORDS_BIGENDIAN)
|
||||||
|
endif()
|
||||||
|
|
||||||
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||||
add_definitions("-DCPUBIT64")
|
add_definitions("-DCPUBIT64")
|
||||||
add_subdirectory("./64")
|
add_subdirectory("./64")
|
||||||
|
|||||||
17
base16384.c
17
base16384.c
@@ -1,6 +1,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#if defined(__WINNT__)
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
#include "base16384.h"
|
#include "base16384.h"
|
||||||
|
|
||||||
void encode_file(const char* input, const char* output) {
|
void encode_file(const char* input, const char* output) {
|
||||||
@@ -80,22 +83,32 @@ void decode_file(const char* input, const char* output) {
|
|||||||
} else puts("Open input file error!");
|
} else puts("Open input file error!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __WINNT__
|
||||||
unsigned long get_start_ms() {
|
unsigned long get_start_ms() {
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
|
return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#define CHOICE argv[1][1]
|
#define CHOICE argv[1][1]
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
if(argc == 4) {
|
if(argc == 4) {
|
||||||
unsigned long t = get_start_ms();
|
#if defined(__WINNT__)
|
||||||
|
clock_t t = clock();
|
||||||
|
#else
|
||||||
|
unsigned long t = get_start_ms();
|
||||||
|
#endif
|
||||||
switch(CHOICE){
|
switch(CHOICE){
|
||||||
case 'e': encode_file(argv[2], argv[3]); break;
|
case 'e': encode_file(argv[2], argv[3]); break;
|
||||||
case 'd': decode_file(argv[2], argv[3]); break;
|
case 'd': decode_file(argv[2], argv[3]); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
printf("spend time: %lums\n", get_start_ms() - t);
|
#if defined(__WINNT__)
|
||||||
|
printf("spend time: %lums\n", clock() - t);
|
||||||
|
#else
|
||||||
|
printf("spend time: %lums\n", get_start_ms() - t);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
fputs("Usage: -[e|d] <inputfile> <outputfile>\n", stderr);
|
fputs("Usage: -[e|d] <inputfile> <outputfile>\n", stderr);
|
||||||
fputs("\t-e encode\n", stderr);
|
fputs("\t-e encode\n", stderr);
|
||||||
|
|||||||
Reference in New Issue
Block a user