Commit 5932ffcd authored by Paul Eggert's avatar Paul Eggert

emacs_strerror cleanups

* src/buffer.c, src/emacs.c, src/lread.c: Don’t include coding.h;
no longer needed, now that emacs_strerror is declared by lisp.h.
* src/coding.c (emacs_strerror): Remove; moved to emacs.c.
* src/coding.h (emacs_strerror) [emacs]: Remove decl; moved
to lisp.h.
* src/emacs.c (emacs_strerror): Move here from coding.c.  Do not
convert result string; this is now the caller’s responsibility,
as some need conversion and others don’t.
* src/fileio.c (report_file_errno, report_file_notify_error):
Use emacs_strerror rather than rolling it ourselves.
* src/lisp.h (emacs_strerror): Move decl here from coding.h.
* src/lread.c (dir_warning): Just call emacs_strerror rather than
both strerror and emacs_strerror.  Convert its result from
locale-coding-system, since it no longer does that conversion.
* src/sound.c (sound_perror):
* src/sysdep.c (emacs_perror, str_collate):
Use emacs_strerror, not strerror.
parent eacdc9eb
......@@ -30,7 +30,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <verify.h>
#include "lisp.h"
#include "coding.h"
#include "intervals.h"
#include "systime.h"
#include "window.h"
......
......@@ -11303,24 +11303,4 @@ internal character representation. */);
#endif
staticpro (&system_eol_type);
}
char *
emacs_strerror (int error_number)
{
char *str;
synchronize_system_messages_locale ();
str = strerror (error_number);
if (! NILP (Vlocale_coding_system))
{
Lisp_Object dec = code_convert_string_norecord (build_string (str),
Vlocale_coding_system,
0);
str = SSDATA (dec);
}
return str;
}
#endif /* emacs */
......@@ -768,8 +768,6 @@ extern Lisp_Object preferred_coding_system (void);
#ifdef emacs
extern char *emacs_strerror (int);
/* Coding system to be used to encode text for terminal display when
terminal coding system is nil. */
extern struct coding_system safe_terminal_coding;
......
......@@ -66,7 +66,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include TERM_HEADER
#endif /* HAVE_WINDOW_SYSTEM */
#include "coding.h"
#include "intervals.h"
#include "character.h"
#include "buffer.h"
......@@ -2226,6 +2225,15 @@ synchronize_system_messages_locale (void)
#endif
}
#endif /* HAVE_SETLOCALE */
/* Return a diagnostic string for ERROR_NUMBER, in the wording
and encoding appropriate for the current locale. */
char *
emacs_strerror (int error_number)
{
synchronize_system_messages_locale ();
return strerror (error_number);
}
Lisp_Object
......
......@@ -185,8 +185,7 @@ void
report_file_errno (char const *string, Lisp_Object name, int errorno)
{
Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name);
synchronize_system_messages_locale ();
char *str = strerror (errorno);
char *str = emacs_strerror (errorno);
AUTO_STRING (unibyte_str, str);
Lisp_Object errstring
= code_convert_string_norecord (unibyte_str, Vlocale_coding_system, 0);
......@@ -214,12 +213,11 @@ report_file_error (char const *string, Lisp_Object name)
void
report_file_notify_error (const char *string, Lisp_Object name)
{
Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name);
synchronize_system_messages_locale ();
char *str = strerror (errno);
char *str = emacs_strerror (errno);
AUTO_STRING (unibyte_str, str);
Lisp_Object errstring
= code_convert_string_norecord (unibyte_str, Vlocale_coding_system, 0);
Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name);
Lisp_Object errdata = Fcons (errstring, data);
xsignal (Qfile_notify_error, Fcons (build_string (string), errdata));
......
......@@ -4131,6 +4131,7 @@ INLINE void fixup_locale (void) {}
INLINE void synchronize_system_messages_locale (void) {}
INLINE void synchronize_system_time_locale (void) {}
#endif
extern char *emacs_strerror (int);
extern void shut_down_emacs (int, Lisp_Object);
/* True means don't do interactive redisplay and don't change tty modes. */
......
......@@ -36,7 +36,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "character.h"
#include "buffer.h"
#include "charset.h"
#include "coding.h"
#include <epaths.h>
#include "commands.h"
#include "keyboard.h"
......@@ -4484,18 +4483,24 @@ void
dir_warning (char const *use, Lisp_Object dirname)
{
static char const format[] = "Warning: %s '%s': %s\n";
int access_errno = errno;
fprintf (stderr, format, use, SSDATA (ENCODE_SYSTEM (dirname)),
strerror (access_errno));
char *diagnostic = emacs_strerror (errno);
fprintf (stderr, format, use, SSDATA (ENCODE_SYSTEM (dirname)), diagnostic);
/* Don't log the warning before we've initialized!! */
if (initialized)
{
char const *diagnostic = emacs_strerror (access_errno);
ptrdiff_t diaglen = strlen (diagnostic);
AUTO_STRING_WITH_LEN (diag, diagnostic, diaglen);
if (! NILP (Vlocale_coding_system))
{
Lisp_Object s
= code_convert_string_norecord (diag, Vlocale_coding_system, false);
diagnostic = SSDATA (s);
diaglen = SBYTES (s);
}
USE_SAFE_ALLOCA;
char *buffer = SAFE_ALLOCA (sizeof format - 3 * (sizeof "%s" - 1)
+ strlen (use) + SBYTES (dirname)
+ strlen (diagnostic));
+ strlen (use) + SBYTES (dirname) + diaglen);
ptrdiff_t message_len = esprintf (buffer, format, use, SSDATA (dirname),
diagnostic);
message_dolog (buffer, message_len, 0, STRING_MULTIBYTE (dirname));
......
......@@ -310,7 +310,7 @@ sound_perror (const char *msg)
}
#endif
if (saved_errno != 0)
error ("%s: %s", msg, strerror (saved_errno));
error ("%s: %s", msg, emacs_strerror (saved_errno));
else
error ("%s", msg);
}
......
......@@ -2498,7 +2498,7 @@ void
emacs_perror (char const *message)
{
int err = errno;
char const *error_string = strerror (err);
char const *error_string = emacs_strerror (err);
char const *command = (initial_argv && initial_argv[0]
? initial_argv[0] : "emacs");
/* Write it out all at once, if it's short; this is less likely to
......@@ -3865,7 +3865,7 @@ str_collate (Lisp_Object s1, Lisp_Object s2,
locale_t loc = newlocale (LC_COLLATE_MASK | LC_CTYPE_MASK,
SSDATA (locale), 0);
if (!loc)
error ("Invalid locale %s: %s", SSDATA (locale), strerror (errno));
error ("Invalid locale %s: %s", SSDATA (locale), emacs_strerror (errno));
if (! NILP (ignore_case))
for (int i = 1; i < 3; i++)
......@@ -3896,10 +3896,10 @@ str_collate (Lisp_Object s1, Lisp_Object s2,
}
# ifndef HAVE_NEWLOCALE
if (err)
error ("Invalid locale or string for collation: %s", strerror (err));
error ("Invalid locale or string for collation: %s", emacs_strerror (err));
# else
if (err)
error ("Invalid string for collation: %s", strerror (err));
error ("Invalid string for collation: %s", emacs_strerror (err));
# endif
SAFE_FREE ();
......
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