Last active
January 23, 2021 23:17
-
-
Save neauoire/121c06034a2ba9e9aedade866b469c67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdarg.h> | |
#include "c9.h" | |
C9ctx ctx; | |
uint32_t wrsize; | |
uint8_t wrbuf[64 * 1024]; | |
uint8_t rdbuf[64 * 1024]; | |
uint8_t * | |
myread(C9ctx *c, uint32_t size, int *err) | |
{ | |
(void)c; | |
if(fread(rdbuf, size, 1, stdin) != 1) { | |
*err = -1; | |
return NULL; | |
} | |
return rdbuf; | |
} | |
uint8_t * | |
mybegin(C9ctx *c, uint32_t size) | |
{ | |
(void)c; | |
wrsize = size; | |
return wrbuf; | |
} | |
int | |
myend(C9ctx *c) | |
{ | |
(void)c; | |
fwrite(wrbuf, wrsize, 1, stdout); | |
fflush(stdout); | |
return 0; | |
} | |
void | |
myr(C9ctx *c, C9r *r) | |
{ | |
switch(r->type) { | |
case Rversion: | |
fprintf(stderr, "version tag=%d\n", r->tag); | |
fflush(stderr); | |
break; | |
} | |
} | |
void | |
myerror(const char *fmt, ...) | |
{ | |
va_list ap; | |
va_start(ap, fmt); | |
vfprintf(stderr, fmt, ap); | |
fprintf(stderr, "\n"); | |
va_end(ap); | |
} | |
int | |
main(int argc, char **argv) | |
{ | |
C9tag tag; | |
ctx.read = myread; | |
ctx.begin = mybegin; | |
ctx.end = myend; | |
ctx.r = myr; | |
ctx.error = myerror; | |
c9version(&ctx, &tag, 64 * 1024); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment