mirror of
https://github.com/fumiama/base16384.git
synced 2026-06-11 23:00:24 +08:00
add Cosmopolitan
This commit is contained in:
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -26,7 +26,7 @@ jobs:
|
|||||||
- name: Build Cosmopolitan
|
- name: Build Cosmopolitan
|
||||||
run: |
|
run: |
|
||||||
gcc -g -Os -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone \
|
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 \
|
-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
|
-include cosmopolitan.h crt.o ape.o cosmopolitan.a
|
||||||
objcopy -S -O binary base16384.com.dbg base16384.com
|
objcopy -S -O binary base16384.com.dbg base16384.com
|
||||||
|
|||||||
2
base14.c
2
base14.c
@@ -1,5 +1,3 @@
|
|||||||
#include "base14.h"
|
|
||||||
|
|
||||||
int encode_len(int dlen) {
|
int encode_len(int dlen) {
|
||||||
int outlen = dlen / 7 * 8;
|
int outlen = dlen / 7 * 8;
|
||||||
int offset = dlen % 7;
|
int offset = dlen % 7;
|
||||||
|
|||||||
10
base1432.c
10
base1432.c
@@ -1,5 +1,14 @@
|
|||||||
// base1432.c
|
// base1432.c
|
||||||
// fumiama 20220319
|
// 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 <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -36,6 +45,7 @@
|
|||||||
# define htobe32(x) _byteswap_ulong(x)
|
# define htobe32(x) _byteswap_ulong(x)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#include "base14.h"
|
#include "base14.h"
|
||||||
|
|
||||||
// #define DEBUG
|
// #define DEBUG
|
||||||
|
|||||||
18
base16384.c
18
base16384.c
@@ -1,3 +1,6 @@
|
|||||||
|
#ifdef __cosmopolitan
|
||||||
|
typedef off_t long;
|
||||||
|
#else
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -5,16 +8,21 @@
|
|||||||
#ifdef __WINNT__
|
#ifdef __WINNT__
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#include "base14.h"
|
#include "base14.h"
|
||||||
|
|
||||||
|
#ifdef __cosmopolitan
|
||||||
|
#define get_file_size(filepath) ((off_t)GetFileSize(filepath))
|
||||||
|
#else
|
||||||
static off_t get_file_size(const char* filepath) {
|
static off_t get_file_size(const char* filepath) {
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
return stat(filepath, &statbuf)?-1:statbuf.st_size;
|
return stat(filepath, &statbuf)?-1:statbuf.st_size;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void encode_file(const char* input, const char* output) {
|
void encode_file(const char* input, const char* output) {
|
||||||
off_t inputsize = get_file_size(input);
|
off_t inputsize = get_file_size(input);
|
||||||
if(inputsize < 0) {
|
if(inputsize <= 0) {
|
||||||
puts("Get file size error!");
|
puts("Get file size error!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -77,7 +85,7 @@ static int is_next_end(FILE* fp) {
|
|||||||
|
|
||||||
void decode_file(const char* input, const char* output) {
|
void decode_file(const char* input, const char* output) {
|
||||||
off_t inputsize = get_file_size(input);
|
off_t inputsize = get_file_size(input);
|
||||||
if(inputsize < 0) {
|
if(inputsize <= 0) {
|
||||||
puts("Get file size error!");
|
puts("Get file size error!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -127,6 +135,7 @@ void decode_file(const char* input, const char* output) {
|
|||||||
以缩短程序运行时间 */
|
以缩短程序运行时间 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __cosmopolitan
|
||||||
#ifndef __WINNT__
|
#ifndef __WINNT__
|
||||||
unsigned long get_start_ms() {
|
unsigned long get_start_ms() {
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
@@ -134,6 +143,7 @@ unsigned long get_start_ms() {
|
|||||||
return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
|
return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#define CHOICE argv[1][1]
|
#define CHOICE argv[1][1]
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
@@ -143,20 +153,24 @@ int main(int argc, char** argv) {
|
|||||||
fputs("\t-d decode\n", stderr);
|
fputs("\t-d decode\n", stderr);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
#ifndef __cosmopolitan
|
||||||
#ifdef __WINNT__
|
#ifdef __WINNT__
|
||||||
clock_t t = clock();
|
clock_t t = clock();
|
||||||
#else
|
#else
|
||||||
unsigned long t = get_start_ms();
|
unsigned long t = get_start_ms();
|
||||||
#endif
|
#endif
|
||||||
|
#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;
|
||||||
}
|
}
|
||||||
|
#ifndef __cosmopolitan
|
||||||
#ifdef __WINNT__
|
#ifdef __WINNT__
|
||||||
printf("spend time: %lums\n", clock() - t);
|
printf("spend time: %lums\n", clock() - t);
|
||||||
#else
|
#else
|
||||||
printf("spend time: %lums\n", get_start_ms() - t);
|
printf("spend time: %lums\n", get_start_ms() - t);
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user