]> git.eshelyaron.com Git - emacs.git/commitdiff
Be simpler and more consistent about reporting I/O errors.
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 16 Jul 2013 18:30:52 +0000 (11:30 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 16 Jul 2013 18:30:52 +0000 (11:30 -0700)
* fileio.c (Fcopy_file, Finsert_file_contents, Fwrite_region):
Say "Read error" and "Write error", rather than "I/O error", or
"IO error reading", or "IO error writing", when a read or write
error occurs.
* process.c (Fmake_network_process, wait_reading_process_output)
(send_process, Fprocess_send_eof, wait_reading_process_output):
Capitalize diagnostics consistently.  Put "failed foo" at the
start of the diagnostic, so that we don't capitalize the
function name "foo".  Consistently say "failed" for such
diagnostics.
* sysdep.c, w32.c (serial_open): Now accepts Lisp string, not C string.
All callers changed.  This is so it can use report_file_error.
* sysdep.c (serial_open, serial_configure): Capitalize I/O
diagnostics consistently as above.

src/ChangeLog
src/fileio.c
src/process.c
src/sysdep.c
src/systty.h
src/w32.c

index 0c96e4b901b4ba2b1e8a52c75b501f9a825d19a8..f234fef84a6476b0ed2741944a0f3e3fdd130a9e 100644 (file)
@@ -1,5 +1,21 @@
 2013-07-16  Paul Eggert  <eggert@cs.ucla.edu>
 
+       Be simpler and more consistent about reporting I/O errors.
+       * fileio.c (Fcopy_file, Finsert_file_contents, Fwrite_region):
+       Say "Read error" and "Write error", rather than "I/O error", or
+       "IO error reading", or "IO error writing", when a read or write
+       error occurs.
+       * process.c (Fmake_network_process, wait_reading_process_output)
+       (send_process, Fprocess_send_eof, wait_reading_process_output):
+       Capitalize diagnostics consistently.  Put "failed foo" at the
+       start of the diagnostic, so that we don't capitalize the
+       function name "foo".  Consistently say "failed" for such
+       diagnostics.
+       * sysdep.c, w32.c (serial_open): Now accepts Lisp string, not C string.
+       All callers changed.  This is so it can use report_file_error.
+       * sysdep.c (serial_open, serial_configure): Capitalize I/O
+       diagnostics consistently as above.
+
        * fileio.c (report_file_errno): Fix errno reporting bug.
        If the file name is neither null nor a pair, package it up as a
        singleton list.  All callers changed, both to this function and to
index ae9c15a016400f26ad527221f566a53c58b8db52..fba28f092736d0af9364b25deb4121c09ee03bfa 100644 (file)
@@ -2125,7 +2125,7 @@ entries (depending on how Emacs was built).  */)
   QUIT;
   while ((n = emacs_read (ifd, buf, sizeof buf)) > 0)
     if (emacs_write_sig (ofd, buf, n) != n)
-      report_file_error ("I/O error", newname);
+      report_file_error ("Write error", newname);
   immediate_quit = 0;
 
 #ifndef MSDOS
@@ -2182,7 +2182,7 @@ entries (depending on how Emacs was built).  */)
     }
 
   if (emacs_close (ofd) < 0)
-    report_file_error ("I/O error", newname);
+    report_file_error ("Write error", newname);
 
   emacs_close (ifd);
 
@@ -3697,8 +3697,7 @@ by calling `format-decode', which see.  */)
                }
 
              if (nread < 0)
-               error ("IO error reading %s: %s",
-                      SDATA (orig_filename), emacs_strerror (errno));
+               report_file_error ("Read error", orig_filename);
              else if (nread > 0)
                {
                  struct buffer *prev = current_buffer;
@@ -3813,8 +3812,7 @@ by calling `format-decode', which see.  */)
 
          nread = emacs_read (fd, read_buf, sizeof read_buf);
          if (nread < 0)
-           error ("IO error reading %s: %s",
-                  SSDATA (orig_filename), emacs_strerror (errno));
+           report_file_error ("Read error", orig_filename);
          else if (nread == 0)
            break;
 
@@ -3879,8 +3877,7 @@ by calling `format-decode', which see.  */)
            {
              nread = emacs_read (fd, read_buf + total_read, trial - total_read);
              if (nread < 0)
-               error ("IO error reading %s: %s",
-                      SDATA (orig_filename), emacs_strerror (errno));
+               report_file_error ("Read error", orig_filename);
              else if (nread == 0)
                break;
              total_read += nread;
@@ -4030,8 +4027,7 @@ by calling `format-decode', which see.  */)
       deferred_remove_unwind_protect = 1;
 
       if (this < 0)
-       error ("IO error reading %s: %s",
-              SDATA (orig_filename), emacs_strerror (errno));
+       report_file_error ("Read error", orig_filename);
 
       if (unprocessed > 0)
        {
@@ -4277,8 +4273,7 @@ by calling `format-decode', which see.  */)
   specpdl_ptr--;
 
   if (how_much < 0)
-    error ("IO error reading %s: %s",
-          SDATA (orig_filename), emacs_strerror (errno));
+    report_file_error ("Read error", orig_filename);
 
   /* Make the text read part of the buffer.  */
   GAP_SIZE -= inserted;
@@ -5071,8 +5066,7 @@ This calls `write-region-annotate-functions' at the start, and
     }
 
   if (! ok)
-    error ("IO error writing %s: %s", SDATA (filename),
-          emacs_strerror (save_errno));
+    report_file_errno ("Write error", filename, save_errno);
 
   if (visiting)
     {
index b51e3bab0334e671101a3ca0b715d02205e559e1..fe843ca2d93c71faf888b62373af29103e0bf621 100644 (file)
@@ -2573,7 +2573,7 @@ usage:  (make-serial-process &rest ARGS)  */)
   record_unwind_protect (make_serial_process_unwind, proc);
   p = XPROCESS (proc);
 
-  fd = serial_open (SSDATA (port));
+  fd = serial_open (port);
   p->infd = fd;
   p->outfd = fd;
   if (fd > max_process_desc)
@@ -3257,16 +3257,16 @@ usage: (make-network-process &rest ARGS)  */)
              if (errno == EINTR)
                goto retry_select;
              else
-               report_file_error ("select failed", Qnil);
+               report_file_error ("Failed select", Qnil);
            }
          eassert (sc > 0);
 
          len = sizeof xerrno;
          eassert (FD_ISSET (s, &fdset));
          if (getsockopt (s, SOL_SOCKET, SO_ERROR, &xerrno, &len) < 0)
-           report_file_error ("getsockopt failed", Qnil);
+           report_file_error ("Failed getsockopt", Qnil);
          if (xerrno)
-           report_file_errno ("error during connect", Qnil, xerrno);
+           report_file_errno ("Failed connect", Qnil, xerrno);
          break;
        }
 #endif /* !WINDOWSNT */
@@ -4624,7 +4624,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
          else if (xerrno == EBADF)
            emacs_abort ();
          else
-           error ("select error: %s", emacs_strerror (xerrno));
+           report_file_errno ("Failed select", Qnil, xerrno);
        }
 
       if (no_avail)
@@ -5466,7 +5466,7 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len,
              if (rv >= 0)
                written = rv;
              else if (errno == EMSGSIZE)
-               report_file_error ("sending datagram", proc);
+               report_file_error ("Sending datagram", proc);
            }
          else
 #endif
@@ -5543,7 +5543,7 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len,
                }
              else
                /* This is a real error.  */
-               report_file_error ("writing to process", proc);
+               report_file_error ("Writing to process", proc);
            }
          cur_buf += written;
          cur_len -= written;
@@ -6037,7 +6037,7 @@ process has been transmitted to the serial port.  */)
     {
 #ifndef WINDOWSNT
       if (tcdrain (XPROCESS (proc)->outfd) != 0)
-       error ("tcdrain() failed: %s", emacs_strerror (errno));
+       report_file_error ("Failed tcdrain", Qnil);
 #endif /* not WINDOWSNT */
       /* Do nothing on Windows because writes are blocking.  */
     }
@@ -6733,7 +6733,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
          if (xerrno == EINTR)
            FD_ZERO (&waitchannels);
          else
-           error ("select error: %s", emacs_strerror (xerrno));
+           report_file_errno ("Failed select", Qnil, xerrno);
        }
 
       /* Check for keyboard input */
index 82f490e9538525e2bab8f534ca5e6383fe1026f5..465d271abca89d6753754d9f3ab7a34fdabce4ad 100644 (file)
@@ -2436,14 +2436,11 @@ safe_strsignal (int code)
 #ifndef DOS_NT
 /* For make-serial-process  */
 int
-serial_open (char *port)
+serial_open (Lisp_Object port)
 {
-  int fd = emacs_open (port, O_RDWR | O_NOCTTY | O_NONBLOCK, 0);
+  int fd = emacs_open (SSDATA (port), O_RDWR | O_NOCTTY | O_NONBLOCK, 0);
   if (fd < 0)
-    {
-      error ("Could not open %s: %s",
-            port, emacs_strerror (errno));
-    }
+    report_file_error ("Opening serial port", port);
 #ifdef TIOCEXCL
   ioctl (fd, TIOCEXCL, (char *) 0);
 #endif
@@ -2491,7 +2488,7 @@ serial_configure (struct Lisp_Process *p,
   /* Read port attributes and prepare default configuration.  */
   err = tcgetattr (p->outfd, &attr);
   if (err != 0)
-    error ("tcgetattr() failed: %s", emacs_strerror (errno));
+    report_file_error ("Failed tcgetattr", Qnil);
   cfmakeraw (&attr);
 #if defined (CLOCAL)
   attr.c_cflag |= CLOCAL;
@@ -2508,8 +2505,7 @@ serial_configure (struct Lisp_Process *p,
   CHECK_NUMBER (tem);
   err = cfsetspeed (&attr, XINT (tem));
   if (err != 0)
-    error ("cfsetspeed(%"pI"d) failed: %s", XINT (tem),
-          emacs_strerror (errno));
+    report_file_error ("Failed cfsetspeed", tem);
   childp2 = Fplist_put (childp2, QCspeed, tem);
 
   /* Configure bytesize.  */
@@ -2631,7 +2627,7 @@ serial_configure (struct Lisp_Process *p,
   /* Activate configuration.  */
   err = tcsetattr (p->outfd, TCSANOW, &attr);
   if (err != 0)
-    error ("tcsetattr() failed: %s", emacs_strerror (errno));
+    report_file_error ("Failed tcsetattr", Qnil);
 
   childp2 = Fplist_put (childp2, QCsummary, build_string (summary));
   pset_childp (p, childp2);
index 6d38c9807258ddee795ecd2e8f3ca61c65f9384f..b735971c66f2fb7754879ce66b649dbdab078568 100644 (file)
@@ -79,5 +79,5 @@ struct emacs_tty {
 };
 \f
 /* From sysdep.c or w32.c  */
-extern int serial_open (char *);
+extern int serial_open (Lisp_Object);
 extern void serial_configure (struct Lisp_Process *, Lisp_Object);
index 1a3d81bbffc036855fe4a0dc5ba221a83d92cf72..fb2d7c75972326f24038e5033f4128c3b230b5aa 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -7707,8 +7707,9 @@ globals_of_w32 (void)
 
 /* For make-serial-process  */
 int
-serial_open (char *port)
+serial_open (Lisp_Object port_obj)
 {
+  char *port = SSDATA (port_obj);
   HANDLE hnd;
   child_process *cp;
   int fd = -1;