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
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
}
if (emacs_close (ofd) < 0)
- report_file_error ("I/O error", newname);
+ report_file_error ("Write error", newname);
emacs_close (ifd);
}
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;
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;
{
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;
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)
{
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;
}
if (! ok)
- error ("IO error writing %s: %s", SDATA (filename),
- emacs_strerror (save_errno));
+ report_file_errno ("Write error", filename, save_errno);
if (visiting)
{
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)
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 */
else if (xerrno == EBADF)
emacs_abort ();
else
- error ("select error: %s", emacs_strerror (xerrno));
+ report_file_errno ("Failed select", Qnil, xerrno);
}
if (no_avail)
if (rv >= 0)
written = rv;
else if (errno == EMSGSIZE)
- report_file_error ("sending datagram", proc);
+ report_file_error ("Sending datagram", proc);
}
else
#endif
}
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;
{
#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. */
}
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 */
#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
/* 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;
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. */
/* 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);
};
\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);
/* 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;