Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int
- read_printer_data()
- {
- struct pollfd fd[1];
- /* Open device file for printer gadget. */
- fd[0].fd = open(PRINTER_FILE, O_RDWR);
- if (fd[0].fd < 0) {
- printf("Error %d opening %s\n", fd[0].fd, PRINTER_FILE);
- close(fd[0].fd);
- return(-1);
- }
- fd[0].events = POLLIN | POLLRDNORM;
- while (1) {
- static char buf[BUF_SIZE];
- int bytes_read;
- int retval;
- /* Wait for up to 1 second for data. */
- retval = poll(fd, 1, 1000);
- if (retval && (fd[0].revents & POLLRDNORM)) {
- /* Read data from printer gadget driver. */
- bytes_read = read(fd[0].fd, buf, BUF_SIZE);
- if (bytes_read < 0) {
- printf("Error %d reading from %s\n",
- fd[0].fd, PRINTER_FILE);
- close(fd[0].fd);
- return(-1);
- } else if (bytes_read > 0) {
- /* Write data to standard OUTPUT (stdout). */
- fwrite(buf, 1, bytes_read, stdout);
- fflush(stdout);
- }
- }
- }
- /* Close the device file. */
- close(fd[0].fd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement