1
0
mirror of https://github.com/fumiama/base16384.git synced 2026-06-10 13:40:26 +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

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