diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6fa78a9..d247b8c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,7 +26,7 @@ jobs: - name: Build Cosmopolitan run: | gcc -g -Os -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone \ - -fno-omit-frame-pointer -pg -mnop-mcount \ + -fno-omit-frame-pointer -pg -mnop-mcount -D__cosmopolitan \ -o base16384.com.dbg base16384.c base1432.c base14.c -fuse-ld=bfd -Wl,-T,ape.lds \ -include cosmopolitan.h crt.o ape.o cosmopolitan.a objcopy -S -O binary base16384.com.dbg base16384.com diff --git a/base14.c b/base14.c index 0db1263..15a85c8 100644 --- a/base14.c +++ b/base14.c @@ -1,5 +1,3 @@ -#include "base14.h" - int encode_len(int dlen) { int outlen = dlen / 7 * 8; int offset = dlen % 7; diff --git a/base1432.c b/base1432.c index 4256bc2..48d5430 100644 --- a/base1432.c +++ b/base1432.c @@ -1,5 +1,14 @@ // base1432.c // fumiama 20220319 +#ifdef __cosmopolitan // always le +# define be16toh(x) __builtin_bswap16(x) +# define be32toh(x) __builtin_bswap32(x) +# define htobe16(x) __builtin_bswap16(x) +# define htobe32(x) __builtin_bswap32(x) +typedef unsigned int uint32_t; +typedef int int32_t; +typedef unsigned char uint8_t; +#else #include #include #include @@ -36,6 +45,7 @@ # define htobe32(x) _byteswap_ulong(x) #endif #endif +#endif #include "base14.h" // #define DEBUG diff --git a/base16384.c b/base16384.c index 766621e..903b0b2 100644 --- a/base16384.c +++ b/base16384.c @@ -1,3 +1,6 @@ +#ifdef __cosmopolitan +typedef off_t long; +#else #include #include #include @@ -5,16 +8,21 @@ #ifdef __WINNT__ #include #endif +#endif #include "base14.h" +#ifdef __cosmopolitan +#define get_file_size(filepath) ((off_t)GetFileSize(filepath)) +#else static off_t get_file_size(const char* filepath) { struct stat statbuf; return stat(filepath, &statbuf)?-1:statbuf.st_size; } +#endif void encode_file(const char* input, const char* output) { off_t inputsize = get_file_size(input); - if(inputsize < 0) { + if(inputsize <= 0) { puts("Get file size error!"); return; } @@ -77,7 +85,7 @@ static int is_next_end(FILE* fp) { void decode_file(const char* input, const char* output) { off_t inputsize = get_file_size(input); - if(inputsize < 0) { + if(inputsize <= 0) { puts("Get file size error!"); return; } @@ -127,6 +135,7 @@ void decode_file(const char* input, const char* output) { 以缩短程序运行时间 */ } +#ifndef __cosmopolitan #ifndef __WINNT__ unsigned long get_start_ms() { struct timespec ts; @@ -134,6 +143,7 @@ unsigned long get_start_ms() { return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000); } #endif +#endif #define CHOICE argv[1][1] int main(int argc, char** argv) { @@ -143,20 +153,24 @@ int main(int argc, char** argv) { fputs("\t-d decode\n", stderr); exit(EXIT_FAILURE); } + #ifndef __cosmopolitan #ifdef __WINNT__ clock_t t = clock(); #else unsigned long t = get_start_ms(); #endif + #endif switch(CHOICE) { case 'e': encode_file(argv[2], argv[3]); break; case 'd': decode_file(argv[2], argv[3]); break; default: break; } + #ifndef __cosmopolitan #ifdef __WINNT__ printf("spend time: %lums\n", clock() - t); #else printf("spend time: %lums\n", get_start_ms() - t); #endif + #endif return 0; }