FreeCalypso > hg > fc-sim-tools
comparison libcommon/atr.c @ 9:c9ef9e91dd8e
new libcommon, initial version
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Mar 2021 06:55:38 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
8:34bbb0585cab | 9:c9ef9e91dd8e |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <strings.h> | |
5 | |
6 extern FILE *cpipeF, *rpipeF; | |
7 extern char be_atr_string[]; | |
8 | |
9 cmd_atr() | |
10 { | |
11 char inbuf[128], *cp; | |
12 | |
13 /* do we have it already? */ | |
14 if (be_atr_string[0]) { | |
15 printf("ATR: %s\n", be_atr_string); | |
16 return(0); | |
17 } | |
18 /* nope - request it from the BE */ | |
19 fputs("atr\n", cpipeF); | |
20 fflush(cpipeF); | |
21 /* collect BE response */ | |
22 if (!fgets(inbuf, sizeof inbuf, rpipeF)) { | |
23 fprintf(stderr, "comm error: EOF reading from back end\n"); | |
24 return(-1); | |
25 } | |
26 cp = index(inbuf, '\n'); | |
27 if (!cp) { | |
28 fprintf(stderr, | |
29 "comm error: response from back end has no newline\n"); | |
30 return(-1); | |
31 } | |
32 *cp = '\0'; | |
33 if (!inbuf[0]) { | |
34 fprintf(stderr, | |
35 "comm error: response from back end is an empty line\n"); | |
36 return(-1); | |
37 } | |
38 puts(inbuf); | |
39 return(0); | |
40 } |