Commit 4e604a5d authored by Paul Eggert's avatar Paul Eggert

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.
parent a9757f6a
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
......
......@@ -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)
{
......
......@@ -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 */
......
......@@ -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);
......
......@@ -79,5 +79,5 @@ struct emacs_tty {
};
/* 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);
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment