diff options
| author | Paul Eggert | 2017-02-23 09:14:06 -0800 |
|---|---|---|
| committer | Paul Eggert | 2017-02-23 09:15:06 -0800 |
| commit | 7204577bf90ba8574a0199680626a5ae3f075554 (patch) | |
| tree | 46062d3c37fa6cc291b9e0ce25a2f28992217094 /lib/binary-io.h | |
| parent | 23e64facf9f74133c6bacedeec56ad782ae69b65 (diff) | |
| download | emacs-7204577bf90ba8574a0199680626a5ae3f075554.tar.gz emacs-7204577bf90ba8574a0199680626a5ae3f075554.zip | |
Merge from gnulib
This incorporates:
2017-02-16 xbinary-io: rename from xsetmode
2017-02-15 xsetmode: new module
* lib-src/etags.c (main):
* lib-src/hexl.c (main):
* src/emacs.c (main) [MSDOS]:
Prefer set_binary_mode to the obsolescent SET_BINARY.
* lib/binary-io.c, lib/binary-io.h: Copy from gnulib.
Diffstat (limited to 'lib/binary-io.h')
| -rw-r--r-- | lib/binary-io.h | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/lib/binary-io.h b/lib/binary-io.h index f766439e2fb..9f1dde108eb 100644 --- a/lib/binary-io.h +++ b/lib/binary-io.h | |||
| @@ -33,15 +33,12 @@ _GL_INLINE_HEADER_BEGIN | |||
| 33 | # define BINARY_IO_INLINE _GL_INLINE | 33 | # define BINARY_IO_INLINE _GL_INLINE |
| 34 | #endif | 34 | #endif |
| 35 | 35 | ||
| 36 | /* set_binary_mode (fd, mode) | ||
| 37 | sets the binary/text I/O mode of file descriptor fd to the given mode | ||
| 38 | (must be O_BINARY or O_TEXT) and returns the previous mode. */ | ||
| 39 | #if O_BINARY | 36 | #if O_BINARY |
| 40 | # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__ | 37 | # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__ |
| 41 | # include <io.h> /* declares setmode() */ | 38 | # include <io.h> /* declares setmode() */ |
| 42 | # define set_binary_mode setmode | 39 | # define __gl_setmode setmode |
| 43 | # else | 40 | # else |
| 44 | # define set_binary_mode _setmode | 41 | # define __gl_setmode _setmode |
| 45 | # undef fileno | 42 | # undef fileno |
| 46 | # define fileno _fileno | 43 | # define fileno _fileno |
| 47 | # endif | 44 | # endif |
| @@ -50,7 +47,7 @@ _GL_INLINE_HEADER_BEGIN | |||
| 50 | /* Use a function rather than a macro, to avoid gcc warnings | 47 | /* Use a function rather than a macro, to avoid gcc warnings |
| 51 | "warning: statement with no effect". */ | 48 | "warning: statement with no effect". */ |
| 52 | BINARY_IO_INLINE int | 49 | BINARY_IO_INLINE int |
| 53 | set_binary_mode (int fd, int mode) | 50 | __gl_setmode (int fd, int mode) |
| 54 | { | 51 | { |
| 55 | (void) fd; | 52 | (void) fd; |
| 56 | (void) mode; | 53 | (void) mode; |
| @@ -58,18 +55,29 @@ set_binary_mode (int fd, int mode) | |||
| 58 | } | 55 | } |
| 59 | #endif | 56 | #endif |
| 60 | 57 | ||
| 61 | /* SET_BINARY (fd); | ||
| 62 | changes the file descriptor fd to perform binary I/O. */ | ||
| 63 | #if defined __DJGPP__ || defined __EMX__ | 58 | #if defined __DJGPP__ || defined __EMX__ |
| 64 | # include <unistd.h> /* declares isatty() */ | 59 | extern int __gl_setmode_check (int); |
| 65 | /* Avoid putting stdin/stdout in binary mode if it is connected to | ||
| 66 | the console, because that would make it impossible for the user | ||
| 67 | to interrupt the program through Ctrl-C or Ctrl-Break. */ | ||
| 68 | # define SET_BINARY(fd) ((void) (!isatty (fd) ? (set_binary_mode (fd, O_BINARY), 0) : 0)) | ||
| 69 | #else | 60 | #else |
| 70 | # define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY)) | 61 | BINARY_IO_INLINE int |
| 62 | __gl_setmode_check (int fd) { return 0; } | ||
| 71 | #endif | 63 | #endif |
| 72 | 64 | ||
| 65 | /* Set FD's mode to MODE, which should be either O_TEXT or O_BINARY. | ||
| 66 | Return the old mode if successful, -1 (setting errno) on failure. | ||
| 67 | Ordinarily this function would be called 'setmode', since that is | ||
| 68 | its name on MS-Windows, but it is called 'set_binary_mode' here | ||
| 69 | to avoid colliding with a BSD function of another name. */ | ||
| 70 | |||
| 71 | BINARY_IO_INLINE int | ||
| 72 | set_binary_mode (int fd, int mode) | ||
| 73 | { | ||
| 74 | int r = __gl_setmode_check (fd); | ||
| 75 | return r != 0 ? r : __gl_setmode (fd, mode); | ||
| 76 | } | ||
| 77 | |||
| 78 | /* This macro is obsolescent. */ | ||
| 79 | #define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY)) | ||
| 80 | |||
| 73 | _GL_INLINE_HEADER_END | 81 | _GL_INLINE_HEADER_END |
| 74 | 82 | ||
| 75 | #endif /* _BINARY_H */ | 83 | #endif /* _BINARY_H */ |