+int
+cc_usb_getchar(struct cc_usb *cc)
+{
+ while (cc->in_pos == cc->in_count) {
+ if (_cc_usb_sync(cc, 5000) < 0) {
+ fprintf(stderr, "USB link timeout\n");
+ exit(1);
+ }
+ }
+ return cc->in_buf[cc->in_pos++];
+}
+
+void
+cc_usb_getline(struct cc_usb *cc, char *line, int max)
+{
+ int c;
+
+ while ((c = cc_usb_getchar(cc)) != '\n') {
+ switch (c) {
+ case '\r':
+ break;
+ default:
+ if (max > 1) {
+ *line++ = c;
+ max--;
+ }
+ break;
+ }
+ }
+ *line++ = '\0';
+}
+