An example that shows how to read logs from a librpc-capable USB device.
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#define BUFSIZE 1024
int
main(int argc, const char *argv[])
{
ssize_t nread;
char buf[BUFSIZE];
int fds[2];
if (argc < 2) {
fprintf(stderr, "Usage: log-reader <URI>\n");
return (1);
}
if (pipe(fds) < 0) {
fprintf(stderr, "pipe() failed: %s\n", strerror(errno));
return (1);
}
if (client == NULL) {
fprintf(stderr, "connect failed: %s\n", strerror(errno));
return (1);
}
printf("(Connected to %s)\n", argv[1]);
for (;;) {
nread = read(fds[0], buf, sizeof(buf));
if (nread == 0)
break;
if (nread < 0) {
fprintf(stderr, "read() failed: %s\n", strerror(errno));
return (1);
}
printf("%*s", (int)nread, buf);
fflush(stdout);
}
return (0);
}