diff options
| author | Paul Eggert | 2016-06-11 23:48:13 -0700 |
|---|---|---|
| committer | Paul Eggert | 2016-06-11 23:49:00 -0700 |
| commit | 5932ffcd028af9fc70c9f8e731f2776a9753d81d (patch) | |
| tree | 4d9ab8f89fdc526146e5571f028147afde568e3d /src | |
| parent | eacdc9eb6c89346fb72535632a1c65f6483b639f (diff) | |
| download | emacs-5932ffcd028af9fc70c9f8e731f2776a9753d81d.tar.gz emacs-5932ffcd028af9fc70c9f8e731f2776a9753d81d.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/buffer.c | 1 | ||||
| -rw-r--r-- | src/coding.c | 20 | ||||
| -rw-r--r-- | src/coding.h | 2 | ||||
| -rw-r--r-- | src/emacs.c | 10 | ||||
| -rw-r--r-- | src/fileio.c | 8 | ||||
| -rw-r--r-- | src/lisp.h | 1 | ||||
| -rw-r--r-- | src/lread.c | 19 | ||||
| -rw-r--r-- | src/sound.c | 2 | ||||
| -rw-r--r-- | src/sysdep.c | 8 |
9 files changed, 30 insertions, 41 deletions
diff --git a/src/buffer.c b/src/buffer.c index af8c7324da1..b4b83043f36 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/>. */ | |||
| 30 | #include <verify.h> | 30 | #include <verify.h> |
| 31 | 31 | ||
| 32 | #include "lisp.h" | 32 | #include "lisp.h" |
| 33 | #include "coding.h" | ||
| 34 | #include "intervals.h" | 33 | #include "intervals.h" |
| 35 | #include "systime.h" | 34 | #include "systime.h" |
| 36 | #include "window.h" | 35 | #include "window.h" |
diff --git a/src/coding.c b/src/coding.c index 3f7d11151d4..804b628d3be 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -11303,24 +11303,4 @@ internal character representation. */); | |||
| 11303 | #endif | 11303 | #endif |
| 11304 | staticpro (&system_eol_type); | 11304 | staticpro (&system_eol_type); |
| 11305 | } | 11305 | } |
| 11306 | |||
| 11307 | char * | ||
| 11308 | emacs_strerror (int error_number) | ||
| 11309 | { | ||
| 11310 | char *str; | ||
| 11311 | |||
| 11312 | synchronize_system_messages_locale (); | ||
| 11313 | str = strerror (error_number); | ||
| 11314 | |||
| 11315 | if (! NILP (Vlocale_coding_system)) | ||
| 11316 | { | ||
| 11317 | Lisp_Object dec = code_convert_string_norecord (build_string (str), | ||
| 11318 | Vlocale_coding_system, | ||
| 11319 | 0); | ||
| 11320 | str = SSDATA (dec); | ||
| 11321 | } | ||
| 11322 | |||
| 11323 | return str; | ||
| 11324 | } | ||
| 11325 | |||
| 11326 | #endif /* emacs */ | 11306 | #endif /* emacs */ |
diff --git a/src/coding.h b/src/coding.h index 93ddff0c6bd..426be6277ca 100644 --- a/src/coding.h +++ b/src/coding.h | |||
| @@ -768,8 +768,6 @@ extern Lisp_Object preferred_coding_system (void); | |||
| 768 | 768 | ||
| 769 | #ifdef emacs | 769 | #ifdef emacs |
| 770 | 770 | ||
| 771 | extern char *emacs_strerror (int); | ||
| 772 | |||
| 773 | /* Coding system to be used to encode text for terminal display when | 771 | /* Coding system to be used to encode text for terminal display when |
| 774 | terminal coding system is nil. */ | 772 | terminal coding system is nil. */ |
| 775 | extern struct coding_system safe_terminal_coding; | 773 | extern struct coding_system safe_terminal_coding; |
diff --git a/src/emacs.c b/src/emacs.c index b8ba86f7356..bb85733a1f2 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/>. */ | |||
| 66 | #include TERM_HEADER | 66 | #include TERM_HEADER |
| 67 | #endif /* HAVE_WINDOW_SYSTEM */ | 67 | #endif /* HAVE_WINDOW_SYSTEM */ |
| 68 | 68 | ||
| 69 | #include "coding.h" | ||
| 70 | #include "intervals.h" | 69 | #include "intervals.h" |
| 71 | #include "character.h" | 70 | #include "character.h" |
| 72 | #include "buffer.h" | 71 | #include "buffer.h" |
| @@ -2226,6 +2225,15 @@ synchronize_system_messages_locale (void) | |||
| 2226 | #endif | 2225 | #endif |
| 2227 | } | 2226 | } |
| 2228 | #endif /* HAVE_SETLOCALE */ | 2227 | #endif /* HAVE_SETLOCALE */ |
| 2228 | |||
| 2229 | /* Return a diagnostic string for ERROR_NUMBER, in the wording | ||
| 2230 | and encoding appropriate for the current locale. */ | ||
| 2231 | char * | ||
| 2232 | emacs_strerror (int error_number) | ||
| 2233 | { | ||
| 2234 | synchronize_system_messages_locale (); | ||
| 2235 | return strerror (error_number); | ||
| 2236 | } | ||
| 2229 | 2237 | ||
| 2230 | 2238 | ||
| 2231 | Lisp_Object | 2239 | Lisp_Object |
diff --git a/src/fileio.c b/src/fileio.c index 99840457ec5..facc4bef927 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -185,8 +185,7 @@ void | |||
| 185 | report_file_errno (char const *string, Lisp_Object name, int errorno) | 185 | report_file_errno (char const *string, Lisp_Object name, int errorno) |
| 186 | { | 186 | { |
| 187 | Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name); | 187 | Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name); |
| 188 | synchronize_system_messages_locale (); | 188 | char *str = emacs_strerror (errorno); |
| 189 | char *str = strerror (errorno); | ||
| 190 | AUTO_STRING (unibyte_str, str); | 189 | AUTO_STRING (unibyte_str, str); |
| 191 | Lisp_Object errstring | 190 | Lisp_Object errstring |
| 192 | = code_convert_string_norecord (unibyte_str, Vlocale_coding_system, 0); | 191 | = code_convert_string_norecord (unibyte_str, Vlocale_coding_system, 0); |
| @@ -214,12 +213,11 @@ report_file_error (char const *string, Lisp_Object name) | |||
| 214 | void | 213 | void |
| 215 | report_file_notify_error (const char *string, Lisp_Object name) | 214 | report_file_notify_error (const char *string, Lisp_Object name) |
| 216 | { | 215 | { |
| 217 | Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name); | 216 | char *str = emacs_strerror (errno); |
| 218 | synchronize_system_messages_locale (); | ||
| 219 | char *str = strerror (errno); | ||
| 220 | AUTO_STRING (unibyte_str, str); | 217 | AUTO_STRING (unibyte_str, str); |
| 221 | Lisp_Object errstring | 218 | Lisp_Object errstring |
| 222 | = code_convert_string_norecord (unibyte_str, Vlocale_coding_system, 0); | 219 | = code_convert_string_norecord (unibyte_str, Vlocale_coding_system, 0); |
| 220 | Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name); | ||
| 223 | Lisp_Object errdata = Fcons (errstring, data); | 221 | Lisp_Object errdata = Fcons (errstring, data); |
| 224 | 222 | ||
| 225 | xsignal (Qfile_notify_error, Fcons (build_string (string), errdata)); | 223 | xsignal (Qfile_notify_error, Fcons (build_string (string), errdata)); |
diff --git a/src/lisp.h b/src/lisp.h index 4042f4decb1..3c6bf3473d8 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -4131,6 +4131,7 @@ INLINE void fixup_locale (void) {} | |||
| 4131 | INLINE void synchronize_system_messages_locale (void) {} | 4131 | INLINE void synchronize_system_messages_locale (void) {} |
| 4132 | INLINE void synchronize_system_time_locale (void) {} | 4132 | INLINE void synchronize_system_time_locale (void) {} |
| 4133 | #endif | 4133 | #endif |
| 4134 | extern char *emacs_strerror (int); | ||
| 4134 | extern void shut_down_emacs (int, Lisp_Object); | 4135 | extern void shut_down_emacs (int, Lisp_Object); |
| 4135 | 4136 | ||
| 4136 | /* True means don't do interactive redisplay and don't change tty modes. */ | 4137 | /* True means don't do interactive redisplay and don't change tty modes. */ |
diff --git a/src/lread.c b/src/lread.c index b08ce17fd9c..9f804ac3194 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/>. */ | |||
| 36 | #include "character.h" | 36 | #include "character.h" |
| 37 | #include "buffer.h" | 37 | #include "buffer.h" |
| 38 | #include "charset.h" | 38 | #include "charset.h" |
| 39 | #include "coding.h" | ||
| 40 | #include <epaths.h> | 39 | #include <epaths.h> |
| 41 | #include "commands.h" | 40 | #include "commands.h" |
| 42 | #include "keyboard.h" | 41 | #include "keyboard.h" |
| @@ -4484,18 +4483,24 @@ void | |||
| 4484 | dir_warning (char const *use, Lisp_Object dirname) | 4483 | dir_warning (char const *use, Lisp_Object dirname) |
| 4485 | { | 4484 | { |
| 4486 | static char const format[] = "Warning: %s '%s': %s\n"; | 4485 | static char const format[] = "Warning: %s '%s': %s\n"; |
| 4487 | int access_errno = errno; | 4486 | char *diagnostic = emacs_strerror (errno); |
| 4488 | fprintf (stderr, format, use, SSDATA (ENCODE_SYSTEM (dirname)), | 4487 | fprintf (stderr, format, use, SSDATA (ENCODE_SYSTEM (dirname)), diagnostic); |
| 4489 | strerror (access_errno)); | ||
| 4490 | 4488 | ||
| 4491 | /* Don't log the warning before we've initialized!! */ | 4489 | /* Don't log the warning before we've initialized!! */ |
| 4492 | if (initialized) | 4490 | if (initialized) |
| 4493 | { | 4491 | { |
| 4494 | char const *diagnostic = emacs_strerror (access_errno); | 4492 | ptrdiff_t diaglen = strlen (diagnostic); |
| 4493 | AUTO_STRING_WITH_LEN (diag, diagnostic, diaglen); | ||
| 4494 | if (! NILP (Vlocale_coding_system)) | ||
| 4495 | { | ||
| 4496 | Lisp_Object s | ||
| 4497 | = code_convert_string_norecord (diag, Vlocale_coding_system, false); | ||
| 4498 | diagnostic = SSDATA (s); | ||
| 4499 | diaglen = SBYTES (s); | ||
| 4500 | } | ||
| 4495 | USE_SAFE_ALLOCA; | 4501 | USE_SAFE_ALLOCA; |
| 4496 | char *buffer = SAFE_ALLOCA (sizeof format - 3 * (sizeof "%s" - 1) | 4502 | char *buffer = SAFE_ALLOCA (sizeof format - 3 * (sizeof "%s" - 1) |
| 4497 | + strlen (use) + SBYTES (dirname) | 4503 | + strlen (use) + SBYTES (dirname) + diaglen); |
| 4498 | + strlen (diagnostic)); | ||
| 4499 | ptrdiff_t message_len = esprintf (buffer, format, use, SSDATA (dirname), | 4504 | ptrdiff_t message_len = esprintf (buffer, format, use, SSDATA (dirname), |
| 4500 | diagnostic); | 4505 | diagnostic); |
| 4501 | message_dolog (buffer, message_len, 0, STRING_MULTIBYTE (dirname)); | 4506 | message_dolog (buffer, message_len, 0, STRING_MULTIBYTE (dirname)); |
diff --git a/src/sound.c b/src/sound.c index 8671d4a6885..f5f570190ca 100644 --- a/src/sound.c +++ b/src/sound.c | |||
| @@ -310,7 +310,7 @@ sound_perror (const char *msg) | |||
| 310 | } | 310 | } |
| 311 | #endif | 311 | #endif |
| 312 | if (saved_errno != 0) | 312 | if (saved_errno != 0) |
| 313 | error ("%s: %s", msg, strerror (saved_errno)); | 313 | error ("%s: %s", msg, emacs_strerror (saved_errno)); |
| 314 | else | 314 | else |
| 315 | error ("%s", msg); | 315 | error ("%s", msg); |
| 316 | } | 316 | } |
diff --git a/src/sysdep.c b/src/sysdep.c index a99c2080032..56142a55cdf 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -2498,7 +2498,7 @@ void | |||
| 2498 | emacs_perror (char const *message) | 2498 | emacs_perror (char const *message) |
| 2499 | { | 2499 | { |
| 2500 | int err = errno; | 2500 | int err = errno; |
| 2501 | char const *error_string = strerror (err); | 2501 | char const *error_string = emacs_strerror (err); |
| 2502 | char const *command = (initial_argv && initial_argv[0] | 2502 | char const *command = (initial_argv && initial_argv[0] |
| 2503 | ? initial_argv[0] : "emacs"); | 2503 | ? initial_argv[0] : "emacs"); |
| 2504 | /* Write it out all at once, if it's short; this is less likely to | 2504 | /* 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, | |||
| 3865 | locale_t loc = newlocale (LC_COLLATE_MASK | LC_CTYPE_MASK, | 3865 | locale_t loc = newlocale (LC_COLLATE_MASK | LC_CTYPE_MASK, |
| 3866 | SSDATA (locale), 0); | 3866 | SSDATA (locale), 0); |
| 3867 | if (!loc) | 3867 | if (!loc) |
| 3868 | error ("Invalid locale %s: %s", SSDATA (locale), strerror (errno)); | 3868 | error ("Invalid locale %s: %s", SSDATA (locale), emacs_strerror (errno)); |
| 3869 | 3869 | ||
| 3870 | if (! NILP (ignore_case)) | 3870 | if (! NILP (ignore_case)) |
| 3871 | for (int i = 1; i < 3; i++) | 3871 | for (int i = 1; i < 3; i++) |
| @@ -3896,10 +3896,10 @@ str_collate (Lisp_Object s1, Lisp_Object s2, | |||
| 3896 | } | 3896 | } |
| 3897 | # ifndef HAVE_NEWLOCALE | 3897 | # ifndef HAVE_NEWLOCALE |
| 3898 | if (err) | 3898 | if (err) |
| 3899 | error ("Invalid locale or string for collation: %s", strerror (err)); | 3899 | error ("Invalid locale or string for collation: %s", emacs_strerror (err)); |
| 3900 | # else | 3900 | # else |
| 3901 | if (err) | 3901 | if (err) |
| 3902 | error ("Invalid string for collation: %s", strerror (err)); | 3902 | error ("Invalid string for collation: %s", emacs_strerror (err)); |
| 3903 | # endif | 3903 | # endif |
| 3904 | 3904 | ||
| 3905 | SAFE_FREE (); | 3905 | SAFE_FREE (); |