FreeCalypso > hg > freecalypso-tools
comparison rvinterf/libasync/interf.c @ 63:09b4fd9b3827
rvinterf/libasync: use the newly adopted exit code convention
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Wed, 26 Oct 2016 22:00:39 +0000 |
| parents | e7502631a0f9 |
| children |
comparison
equal
deleted
inserted
replaced
| 62:2dd9dbe3f4a7 | 63:09b4fd9b3827 |
|---|---|
| 5 #include <sys/types.h> | 5 #include <sys/types.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 #include "localsock.h" | 9 #include "localsock.h" |
| 10 #include "exitcodes.h" | |
| 10 | 11 |
| 11 extern int sock; | 12 extern int sock; |
| 12 | 13 |
| 13 u_char rvi_msg[LOCALSOCK_MAX_MSG]; | 14 u_char rvi_msg[LOCALSOCK_MAX_MSG]; |
| 14 int rvi_msg_len; | 15 int rvi_msg_len; |
| 45 if (rvi_msg[1] == '+') | 46 if (rvi_msg[1] == '+') |
| 46 return; | 47 return; |
| 47 tty_cleanup(); | 48 tty_cleanup(); |
| 48 fprintf(stderr, "Error from rvinterf: %.*s\n", rvi_msg_len - 1, | 49 fprintf(stderr, "Error from rvinterf: %.*s\n", rvi_msg_len - 1, |
| 49 rvi_msg + 1); | 50 rvi_msg + 1); |
| 50 exit(1); | 51 exit(ERROR_RVINTERF); |
| 51 default: | 52 default: |
| 52 bad: | 53 bad: |
| 53 tty_cleanup(); | 54 tty_cleanup(); |
| 54 fprintf(stderr, | 55 fprintf(stderr, |
| 55 "Error: unexpected message type %02X from rvinterf\n", | 56 "Error: unexpected message type %02X from rvinterf\n", |
| 56 rvi_msg[0]); | 57 rvi_msg[0]); |
| 57 exit(1); | 58 exit(ERROR_RVINTERF); |
| 58 } | 59 } |
| 59 } | 60 } |
| 60 | 61 |
| 61 void | 62 void |
| 62 handle_rvinterf_input() | 63 handle_rvinterf_input() |
| 65 | 66 |
| 66 cc = read(sock, rx_ptr, rx_left); | 67 cc = read(sock, rx_ptr, rx_left); |
| 67 if (cc <= 0) { | 68 if (cc <= 0) { |
| 68 tty_cleanup(); | 69 tty_cleanup(); |
| 69 perror("read from rvinterf socket"); | 70 perror("read from rvinterf socket"); |
| 70 exit(1); | 71 exit(ERROR_RVINTERF); |
| 71 } | 72 } |
| 72 rx_ptr += cc; | 73 rx_ptr += cc; |
| 73 rx_left -= cc; | 74 rx_left -= cc; |
| 74 if (rx_left) | 75 if (rx_left) |
| 75 return; | 76 return; |
| 82 if (rvi_msg_len < 1 || rvi_msg_len > LOCALSOCK_MAX_MSG) { | 83 if (rvi_msg_len < 1 || rvi_msg_len > LOCALSOCK_MAX_MSG) { |
| 83 tty_cleanup(); | 84 tty_cleanup(); |
| 84 fprintf(stderr, | 85 fprintf(stderr, |
| 85 "Invalid length from rvinterf: %02X%02X\n", | 86 "Invalid length from rvinterf: %02X%02X\n", |
| 86 rvi_msg[0], rvi_msg[1]); | 87 rvi_msg[0], rvi_msg[1]); |
| 87 exit(1); | 88 exit(ERROR_RVINTERF); |
| 88 } | 89 } |
| 89 prep_for_message_rx(); | 90 prep_for_message_rx(); |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 | 93 |
