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

add Cosmopolitan

This commit is contained in:
源文雨
2022-03-29 20:47:26 +08:00
parent 42f8368a40
commit 95e9642cd3
4 changed files with 27 additions and 5 deletions

View File

@@ -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

View File

@@ -1,5 +1,3 @@
#include "base14.h"
int encode_len(int dlen) {
int outlen = dlen / 7 * 8;
int offset = dlen % 7;

View File

@@ -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 <stdio.h>
#include <stdint.h>
#include <stdlib.h>
@@ -36,6 +45,7 @@
# define htobe32(x) _byteswap_ulong(x)
#endif
#endif
#endif
#include "base14.h"
// #define DEBUG

View File

@@ -1,3 +1,6 @@
#ifdef __cosmopolitan
typedef off_t long;
#else
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
@@ -5,16 +8,21 @@
#ifdef __WINNT__
#include <windows.h>
#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;
}