]> code.delx.au - gnu-emacs/commitdiff
emacs_strerror cleanups
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 12 Jun 2016 06:48:13 +0000 (23:48 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 12 Jun 2016 06:49:00 +0000 (23:49 -0700)
* 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.

src/buffer.c
src/coding.c
src/coding.h
src/emacs.c
src/fileio.c
src/lisp.h
src/lread.c
src/sound.c
src/sysdep.c

index af8c7324da10ab23017fcfa7d28683590c728d64..b4b83043f36d2c1733c709236caf9881c5c9d11f 100644 (file)
@@ -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"
index 3f7d11151d451ba0d759a76bc93d0fd6de13c23f..804b628d3bed20853ec828ff88040a9f6013e93a 100644 (file)
@@ -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 */
index 93ddff0c6bd4dd523fa5676c912a6feb87f9b1c2..426be6277cabbb790cc5590677a3338884b3896e 100644 (file)
@@ -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;
index b8ba86f735665b6fe988ea2be8309239a2e90bb8..bb85733a1f20d3933b1a50475e63b672e50fb202 100644 (file)
@@ -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);
+}
 \f
 
 Lisp_Object
index 99840457ec53d668f162f18790b0030f5de02950..facc4bef927d54fd2f4772dce083232a34c71a41 100644 (file)
@@ -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));
index 4042f4decb13017bb00e6bdb75c5b1c0d5461c10..3c6bf3473d8a1d015000638692b16045ca18cb2e 100644 (file)
@@ -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.  */
index b08ce17fd9c1bfe51fb33ed3d29b75264ddd6258..9f804ac319412dd7bc38b097b15205388f6e6a06 100644 (file)
@@ -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));
index 8671d4a688578557182b8d4231f94857019d5537..f5f570190ca9899bc3c5d129caa8a04bf0bebf34 100644 (file)
@@ -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);
 }
index a99c2080032ff3ec1cce52f9feef28872973f1b5..56142a55cdfd700093d8f36b02442a7cfe37ff36 100644 (file)
@@ -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 ();