]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Updated parallel backend to ignore an initial ENOTTY error to avoid Solaris
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Tue, 27 Jun 2000 20:15:54 +0000 (20:15 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Tue, 27 Jun 2000 20:15:54 +0000 (20:15 +0000)
ioctl() bug with parallel devices.

Updated parallel, serial, and USB backends to do an "intelligent" write
to avoid possible data loss with non-compliant character devices.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@1167 7a7537e8-13f0-0310-91df-b6672ffda945

backend/parallel.c
backend/serial.c
backend/usb.c

index 37e0498835e3cc904486f6467d9aac4a33172340..e637384bebe85b0b1c6252ae68a00d1af8724076 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: parallel.c,v 1.20 2000/04/27 21:31:38 mike Exp $"
+ * "$Id: parallel.c,v 1.21 2000/06/27 20:15:54 mike Exp $"
  *
  *   Parallel port backend for the Common UNIX Printing System (CUPS).
  *
@@ -86,9 +86,11 @@ main(int  argc,              /* I - Number of command-line arguments (6 or 7) */
   FILE         *fp;            /* Print file */
   int          copies;         /* Number of copies to print */
   int          fd;             /* Parallel device */
-  size_t       nbytes,         /* Number of bytes written */
+  int          wbytes;         /* Number of bytes written */
+  size_t       nbytes,         /* Number of bytes read */
                tbytes;         /* Total number of bytes written */
-  char         buffer[8192];   /* Output buffer */
+  char         buffer[8192],   /* Output buffer */
+               *bufptr;        /* Pointer into buffer */
   struct termios opts;         /* Parallel port options */
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
   struct sigaction action;     /* Actions for POSIX signals */
@@ -224,13 +226,24 @@ main(int  argc,           /* I - Number of command-line arguments (6 or 7) */
       * Write the print data to the printer...
       */
 
-      if (write(fd, buffer, nbytes) < nbytes)
+      tbytes += nbytes;
+      bufptr = buffer;
+
+      while (nbytes > 0)
       {
-       perror("ERROR: Unable to send print file to printer");
-       break;
+       if ((wbytes = write(fd, bufptr, nbytes)) < 0)
+         if (errno == ENOTTY)
+           wbytes = write(fd, bufptr, nbytes);
+
+       if (wbytes < 0)
+       {
+         perror("ERROR: Unable to send print file to printer");
+         break;
+       }
+
+       nbytes -= wbytes;
+       bufptr += wbytes;
       }
-      else
-       tbytes += nbytes;
 
       if (argc > 6)
        fprintf(stderr, "INFO: Sending print file, %u bytes...\n", tbytes);
@@ -546,5 +559,5 @@ list_devices(void)
 
 
 /*
- * End of "$Id: parallel.c,v 1.20 2000/04/27 21:31:38 mike Exp $".
+ * End of "$Id: parallel.c,v 1.21 2000/06/27 20:15:54 mike Exp $".
  */
index a55738578254b9edc35f8453a86e9c8ec77d09d0..48dc92bd8cddf09dfa015bad98a17780defc5981 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: serial.c,v 1.16 2000/04/27 21:31:38 mike Exp $"
+ * "$Id: serial.c,v 1.17 2000/06/27 20:15:54 mike Exp $"
  *
  *   Serial port backend for the Common UNIX Printing System (CUPS).
  *
@@ -89,9 +89,11 @@ main(int  argc,              /* I - Number of command-line arguments (6 or 7) */
   FILE         *fp;            /* Print file */
   int          copies;         /* Number of copies to print */
   int          fd;             /* Parallel device */
-  size_t       nbytes,         /* Number of bytes written */
+  int          wbytes;         /* Number of bytes written */
+  size_t       nbytes,         /* Number of bytes read */
                tbytes;         /* Total number of bytes written */
-  char         buffer[8192];   /* Output buffer */
+  char         buffer[8192],   /* Output buffer */
+               *bufptr;        /* Pointer into buffer */
   struct termios opts;         /* Parallel port options */
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
   struct sigaction action;     /* Actions for POSIX signals */
@@ -342,13 +344,24 @@ main(int  argc,           /* I - Number of command-line arguments (6 or 7) */
       * Write the print data to the printer...
       */
 
-      if (write(fd, buffer, nbytes) < nbytes)
+      tbytes += nbytes;
+      bufptr = buffer;
+
+      while (nbytes > 0)
       {
-       perror("ERROR: Unable to send print file to printer");
-       break;
+       if ((wbytes = write(fd, bufptr, nbytes)) < 0)
+         if (errno == ENOTTY)
+           wbytes = write(fd, bufptr, nbytes);
+
+       if (wbytes < 0)
+       {
+         perror("ERROR: Unable to send print file to printer");
+         break;
+       }
+
+       nbytes -= wbytes;
+       bufptr += wbytes;
       }
-      else
-       tbytes += nbytes;
 
       if (argc > 6)
        fprintf(stderr, "INFO: Sending print file, %u bytes...\n", tbytes);
@@ -688,5 +701,5 @@ list_devices(void)
 
 
 /*
- * End of "$Id: serial.c,v 1.16 2000/04/27 21:31:38 mike Exp $".
+ * End of "$Id: serial.c,v 1.17 2000/06/27 20:15:54 mike Exp $".
  */
index 30e8338e13a89ee1eda09958f90733ce8bcb9b7d..83b8dc26d4d522db7d862d878ea26231ad9cb9f6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: usb.c,v 1.8 2000/06/02 20:58:59 mike Exp $"
+ * "$Id: usb.c,v 1.9 2000/06/27 20:15:54 mike Exp $"
  *
  *   USB port backend for the Common UNIX Printing System (CUPS).
  *
@@ -75,9 +75,11 @@ main(int  argc,              /* I - Number of command-line arguments (6 or 7) */
   FILE         *fp;            /* Print file */
   int          copies;         /* Number of copies to print */
   int          fd;             /* Parallel device */
-  size_t       nbytes,         /* Number of bytes written */
+  int          wbytes;         /* Number of bytes written */
+  size_t       nbytes,         /* Number of bytes read */
                tbytes;         /* Total number of bytes written */
-  char         buffer[8192];   /* Output buffer */
+  char         buffer[8192],   /* Output buffer */
+               *bufptr;        /* Pointer into buffer */
   struct termios opts;         /* Parallel port options */
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
   struct sigaction action;     /* Actions for POSIX signals */
@@ -213,13 +215,24 @@ main(int  argc,           /* I - Number of command-line arguments (6 or 7) */
       * Write the print data to the printer...
       */
 
-      if (write(fd, buffer, nbytes) < nbytes)
+      tbytes += nbytes;
+      bufptr = buffer;
+
+      while (nbytes > 0)
       {
-       perror("ERROR: Unable to send print file to printer");
-       break;
+       if ((wbytes = write(fd, bufptr, nbytes)) < 0)
+         if (errno == ENOTTY)
+           wbytes = write(fd, bufptr, nbytes);
+
+       if (wbytes < 0)
+       {
+         perror("ERROR: Unable to send print file to printer");
+         break;
+       }
+
+       nbytes -= wbytes;
+       bufptr += wbytes;
       }
-      else
-       tbytes += nbytes;
 
       if (argc > 6)
        fprintf(stderr, "INFO: Sending print file, %u bytes...\n", tbytes);
@@ -353,5 +366,5 @@ list_devices(void)
 
 
 /*
- * End of "$Id: usb.c,v 1.8 2000/06/02 20:58:59 mike Exp $".
+ * End of "$Id: usb.c,v 1.9 2000/06/27 20:15:54 mike Exp $".
  */