diff options
| author | Eli Zaretskii | 2015-01-15 17:50:50 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2015-01-15 17:50:50 +0200 |
| commit | 0f238ea450b3a976f04c95c4cf8befaadad1cdd0 (patch) | |
| tree | cd278a1441bd610bd91eb7fbd6f38aea7aa4bca8 /src | |
| parent | 3b7eed4ebb3c18799ec791d0c6bd53c019f48f73 (diff) | |
| download | emacs-0f238ea450b3a976f04c95c4cf8befaadad1cdd0.tar.gz emacs-0f238ea450b3a976f04c95c4cf8befaadad1cdd0.zip | |
Add set-binary-mode primitive to switch a standard stream to binary I/O.
src/fileio.c: Include binary-io.h.
(Fset_binary_mode): New function.
(syms_of_fileio): Defsubr it.
(syms_of_fileio) <Qstdin, Qstdout, Qstderr>: DEFSYM them.
admin/unidata/unidata/uvs.el (uvs-print-table-ivd): Call set-binary-mode on
stdout.
doc/lispref/streams.texi (Input Functions): Document 'set-binary-mode'.
(Output Functions): Cross-reference to documentation of
'set-binary-mode'.
etc/NEWS: Mention 'set-binary-mode'.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 7 | ||||
| -rw-r--r-- | src/fileio.c | 50 |
2 files changed, 57 insertions, 0 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 898c10a48e1..40d8b267d84 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2015-01-15 Eli Zaretskii <eliz@gnu.org> | ||
| 2 | |||
| 3 | * fileio.c: Include binary-io.h. | ||
| 4 | (Fset_binary_mode): New function. | ||
| 5 | (syms_of_fileio): Defsubr it. | ||
| 6 | (syms_of_fileio) <Qstdin, Qstdout, Qstderr>: DEFSYM them. | ||
| 7 | |||
| 1 | 2015-01-15 Teodor Zlatanov <tzz@lifelogs.com> | 8 | 2015-01-15 Teodor Zlatanov <tzz@lifelogs.com> |
| 2 | 9 | ||
| 3 | * gnutls.c (init_gnutls_functions): Import gnutls_x509_crt_check_issuer. | 10 | * gnutls.c (init_gnutls_functions): Import gnutls_x509_crt_check_issuer. |
diff --git a/src/fileio.c b/src/fileio.c index 6c443c91db7..dc67a00ed2a 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -86,6 +86,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 86 | #include <careadlinkat.h> | 86 | #include <careadlinkat.h> |
| 87 | #include <stat-time.h> | 87 | #include <stat-time.h> |
| 88 | 88 | ||
| 89 | #include <binary-io.h> | ||
| 90 | |||
| 89 | #ifdef HPUX | 91 | #ifdef HPUX |
| 90 | #include <netio.h> | 92 | #include <netio.h> |
| 91 | #endif | 93 | #endif |
| @@ -5754,6 +5756,48 @@ before any other event (mouse or keypress) is handled. */) | |||
| 5754 | return Qnil; | 5756 | return Qnil; |
| 5755 | } | 5757 | } |
| 5756 | 5758 | ||
| 5759 | |||
| 5760 | DEFUN ("set-binary-mode", Fset_binary_mode, Sset_binary_mode, 2, 2, 0, | ||
| 5761 | doc: /* Switch STREAM to binary I/O mode or text I/O mode. | ||
| 5762 | STREAM can be one of the symbols `stdin', `stdout', or `stderr'. | ||
| 5763 | If MODE is non-nil, switch STREAM to binary mode, otherwise switch | ||
| 5764 | it to text mode. | ||
| 5765 | |||
| 5766 | As a side effect, this function flushes any pending STREAM's data. | ||
| 5767 | |||
| 5768 | Value is the previous value of STREAM's I/O mode, nil for text mode, | ||
| 5769 | non-nil for binary mode. | ||
| 5770 | |||
| 5771 | On MS-Windows and MS-DOS, binary mode is needed to read or write | ||
| 5772 | arbitrary binary data, and for disabling translation between CR-LF | ||
| 5773 | pairs and a single newline character. Examples include generation | ||
| 5774 | of text files with Unix-style end-of-line format using `princ' in | ||
| 5775 | batch mode, with standard output redirected to a file. | ||
| 5776 | |||
| 5777 | On Posix systems, this function always returns non-nil, and has no | ||
| 5778 | effect except for flushing STREAM's data. */) | ||
| 5779 | (Lisp_Object stream, Lisp_Object mode) | ||
| 5780 | { | ||
| 5781 | FILE *fp = NULL; | ||
| 5782 | int binmode; | ||
| 5783 | |||
| 5784 | CHECK_SYMBOL (stream); | ||
| 5785 | if (EQ (stream, Qstdin)) | ||
| 5786 | fp = stdin; | ||
| 5787 | else if (EQ (stream, Qstdout)) | ||
| 5788 | fp = stdout; | ||
| 5789 | else if (EQ (stream, Qstderr)) | ||
| 5790 | fp = stderr; | ||
| 5791 | else | ||
| 5792 | xsignal2 (Qerror, build_string ("unsupported stream"), stream); | ||
| 5793 | |||
| 5794 | binmode = NILP (mode) ? O_TEXT : O_BINARY; | ||
| 5795 | if (fp != stdin) | ||
| 5796 | fflush (fp); | ||
| 5797 | |||
| 5798 | return (set_binary_mode (fileno (fp), binmode) == O_BINARY) ? Qt : Qnil; | ||
| 5799 | } | ||
| 5800 | |||
| 5757 | void | 5801 | void |
| 5758 | init_fileio (void) | 5802 | init_fileio (void) |
| 5759 | { | 5803 | { |
| @@ -6040,6 +6084,10 @@ This includes interactive calls to `delete-file' and | |||
| 6040 | DEFSYM (Qsubstitute_env_in_file_name, "substitute-env-in-file-name"); | 6084 | DEFSYM (Qsubstitute_env_in_file_name, "substitute-env-in-file-name"); |
| 6041 | DEFSYM (Qget_buffer_window_list, "get-buffer-window-list"); | 6085 | DEFSYM (Qget_buffer_window_list, "get-buffer-window-list"); |
| 6042 | 6086 | ||
| 6087 | DEFSYM (Qstdin, "stdin"); | ||
| 6088 | DEFSYM (Qstdout, "stdout"); | ||
| 6089 | DEFSYM (Qstderr, "stderr"); | ||
| 6090 | |||
| 6043 | defsubr (&Sfind_file_name_handler); | 6091 | defsubr (&Sfind_file_name_handler); |
| 6044 | defsubr (&Sfile_name_directory); | 6092 | defsubr (&Sfile_name_directory); |
| 6045 | defsubr (&Sfile_name_nondirectory); | 6093 | defsubr (&Sfile_name_nondirectory); |
| @@ -6089,6 +6137,8 @@ This includes interactive calls to `delete-file' and | |||
| 6089 | 6137 | ||
| 6090 | defsubr (&Snext_read_file_uses_dialog_p); | 6138 | defsubr (&Snext_read_file_uses_dialog_p); |
| 6091 | 6139 | ||
| 6140 | defsubr (&Sset_binary_mode); | ||
| 6141 | |||
| 6092 | #ifdef HAVE_SYNC | 6142 | #ifdef HAVE_SYNC |
| 6093 | defsubr (&Sunix_sync); | 6143 | defsubr (&Sunix_sync); |
| 6094 | #endif | 6144 | #endif |