Mercurial > gnulib
annotate lib/binary-io.h @ 40186:8964917f9574
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Mon, 18 Feb 2019 08:02:49 -0800 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
4273 | 1 /* Binary mode I/O. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19551
diff
changeset
|
2 Copyright (C) 2001, 2003, 2005, 2008-2019 Free Software Foundation, Inc. |
4273 | 3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
5916
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
4273 | 5 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
5916
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
5916
diff
changeset
|
7 (at your option) any later version. |
4273 | 8 |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
19190 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
4273 | 16 |
17 #ifndef _BINARY_H | |
18 #define _BINARY_H | |
19 | |
20 /* For systems that distinguish between text and binary I/O. | |
14182
f6ec6d171e52
binary-io: fix O_TEXT on Haiku
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
21 O_BINARY is guaranteed by the gnulib <fcntl.h>. */ |
4608 | 22 #include <fcntl.h> |
23 | |
24 /* The MSVC7 <stdio.h> doesn't like to be included after '#define fileno ...', | |
25 so we include it here first. */ | |
26 #include <stdio.h> | |
27 | |
17473
1f9070ef79b0
headers: check that _GL_INLINE_HEADER_BEGIN is defined
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
28 #ifndef _GL_INLINE_HEADER_BEGIN |
1f9070ef79b0
headers: check that _GL_INLINE_HEADER_BEGIN is defined
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
29 #error "Please include config.h first." |
1f9070ef79b0
headers: check that _GL_INLINE_HEADER_BEGIN is defined
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
30 #endif |
17102
9e72d3927af1
binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
17094
diff
changeset
|
31 _GL_INLINE_HEADER_BEGIN |
9e72d3927af1
binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
17094
diff
changeset
|
32 #ifndef BINARY_IO_INLINE |
9e72d3927af1
binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
17094
diff
changeset
|
33 # define BINARY_IO_INLINE _GL_INLINE |
9e72d3927af1
binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
17094
diff
changeset
|
34 #endif |
9e72d3927af1
binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
17094
diff
changeset
|
35 |
4273 | 36 #if O_BINARY |
9905 | 37 # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__ |
38 # include <io.h> /* declares setmode() */ | |
18699 | 39 # define __gl_setmode setmode |
9905 | 40 # else |
18699 | 41 # define __gl_setmode _setmode |
5916
e9721cce07d6
Avoid gcc warning on mingw.
Bruno Haible <bruno@clisp.org>
parents:
5848
diff
changeset
|
42 # undef fileno |
4273 | 43 # define fileno _fileno |
44 # endif | |
45 #else | |
16851
2ef869fa79b4
binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
46 /* On reasonable systems, binary I/O is the only choice. */ |
17094
67cb7096523b
misc: don't limit commentary to inline functions
Paul Eggert <eggert@cs.ucla.edu>
parents:
16851
diff
changeset
|
47 /* Use a function rather than a macro, to avoid gcc warnings |
16851
2ef869fa79b4
binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
48 "warning: statement with no effect". */ |
17102
9e72d3927af1
binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
17094
diff
changeset
|
49 BINARY_IO_INLINE int |
19551
f334871ce439
binary-io: pacify gcc -Wunused-parameter
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
50 __gl_setmode (int fd _GL_UNUSED, int mode _GL_UNUSED) |
16851
2ef869fa79b4
binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
51 { |
2ef869fa79b4
binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
52 return O_BINARY; |
2ef869fa79b4
binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
53 } |
2ef869fa79b4
binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
54 #endif |
2ef869fa79b4
binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
55 |
18202
6cd707b3f1bb
binary-io: don't put fd in binary mode if it is a console on EMX
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
56 #if defined __DJGPP__ || defined __EMX__ |
18699 | 57 extern int __gl_setmode_check (int); |
16851
2ef869fa79b4
binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
58 #else |
18699 | 59 BINARY_IO_INLINE int |
19551
f334871ce439
binary-io: pacify gcc -Wunused-parameter
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
60 __gl_setmode_check (int fd _GL_UNUSED) { return 0; } |
4273 | 61 #endif |
62 | |
18701
7b67f85ec2c9
xbinary-io: rename from xsetmode
Paul Eggert <eggert@cs.ucla.edu>
parents:
18699
diff
changeset
|
63 /* Set FD's mode to MODE, which should be either O_TEXT or O_BINARY. |
7b67f85ec2c9
xbinary-io: rename from xsetmode
Paul Eggert <eggert@cs.ucla.edu>
parents:
18699
diff
changeset
|
64 Return the old mode if successful, -1 (setting errno) on failure. |
7b67f85ec2c9
xbinary-io: rename from xsetmode
Paul Eggert <eggert@cs.ucla.edu>
parents:
18699
diff
changeset
|
65 Ordinarily this function would be called 'setmode', since that is |
7b67f85ec2c9
xbinary-io: rename from xsetmode
Paul Eggert <eggert@cs.ucla.edu>
parents:
18699
diff
changeset
|
66 its name on MS-Windows, but it is called 'set_binary_mode' here |
7b67f85ec2c9
xbinary-io: rename from xsetmode
Paul Eggert <eggert@cs.ucla.edu>
parents:
18699
diff
changeset
|
67 to avoid colliding with a BSD function of another name. */ |
7b67f85ec2c9
xbinary-io: rename from xsetmode
Paul Eggert <eggert@cs.ucla.edu>
parents:
18699
diff
changeset
|
68 |
18699 | 69 BINARY_IO_INLINE int |
70 set_binary_mode (int fd, int mode) | |
71 { | |
72 int r = __gl_setmode_check (fd); | |
73 return r != 0 ? r : __gl_setmode (fd, mode); | |
74 } | |
75 | |
18701
7b67f85ec2c9
xbinary-io: rename from xsetmode
Paul Eggert <eggert@cs.ucla.edu>
parents:
18699
diff
changeset
|
76 /* This macro is obsolescent. */ |
7b67f85ec2c9
xbinary-io: rename from xsetmode
Paul Eggert <eggert@cs.ucla.edu>
parents:
18699
diff
changeset
|
77 #define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY)) |
7b67f85ec2c9
xbinary-io: rename from xsetmode
Paul Eggert <eggert@cs.ucla.edu>
parents:
18699
diff
changeset
|
78 |
17102
9e72d3927af1
binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
17094
diff
changeset
|
79 _GL_INLINE_HEADER_END |
9e72d3927af1
binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
17094
diff
changeset
|
80 |
4273 | 81 #endif /* _BINARY_H */ |