summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-06-11 23:48:13 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2016-06-11 23:49:00 -0700
commit5932ffcd028af9fc70c9f8e731f2776a9753d81d (patch)
tree4d9ab8f89fdc526146e5571f028147afde568e3d
parenteacdc9eb6c89346fb72535632a1c65f6483b639f (diff)
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.
-rw-r--r--src/buffer.c1
-rw-r--r--src/coding.c20
-rw-r--r--src/coding.h2
-rw-r--r--src/emacs.c10
-rw-r--r--src/fileio.c8
-rw-r--r--src/lisp.h1
-rw-r--r--src/lread.c19
-rw-r--r--src/sound.c2
-rw-r--r--src/sysdep.c8
9 files changed, 30 insertions, 41 deletions
diff --git a/src/buffer.c b/src/buffer.c
index af8c7324da..b4b83043f3 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -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"
diff --git a/src/coding.c b/src/coding.c
index 3f7d11151d..804b628d3b 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -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 */
diff --git a/src/coding.h b/src/coding.h
index 93ddff0c6b..426be6277c 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -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;
diff --git a/src/emacs.c b/src/emacs.c
index b8ba86f735..bb85733a1f 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -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
diff --git a/src/fileio.c b/src/fileio.c
index 99840457ec..facc4bef92 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -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));
diff --git a/src/lisp.h b/src/lisp.h
index 4042f4decb..3c6bf3473d 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -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. */
diff --git a/src/lread.c b/src/lread.c
index b08ce17fd9..9f804ac319 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -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));
diff --git a/src/sound.c b/src/sound.c
index 8671d4a688..f5f570190c 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -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);
}
diff --git a/src/sysdep.c b/src/sysdep.c
index a99c208003..56142a55cd 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -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 ();