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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4273
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18701
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
4273
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #ifndef _BINARY_H
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #define _BINARY_H
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
a079d84287d0 Make it work with MSVC.
Bruno Haible <bruno@clisp.org>
parents: 4273
diff changeset
22 #include <fcntl.h>
a079d84287d0 Make it work with MSVC.
Bruno Haible <bruno@clisp.org>
parents: 4273
diff changeset
23
a079d84287d0 Make it work with MSVC.
Bruno Haible <bruno@clisp.org>
parents: 4273
diff changeset
24 /* The MSVC7 <stdio.h> doesn't like to be included after '#define fileno ...',
a079d84287d0 Make it work with MSVC.
Bruno Haible <bruno@clisp.org>
parents: 4273
diff changeset
25 so we include it here first. */
a079d84287d0 Make it work with MSVC.
Bruno Haible <bruno@clisp.org>
parents: 4273
diff changeset
26 #include <stdio.h>
a079d84287d0 Make it work with MSVC.
Bruno Haible <bruno@clisp.org>
parents: 4273
diff changeset
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
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 #if O_BINARY
9905
f2fd1d89ec4b Avoid warning on emx+gcc.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
37 # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
f2fd1d89ec4b Avoid warning on emx+gcc.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
38 # include <io.h> /* declares setmode() */
18699
eae8d879de1e xsetmode: new module
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
39 # define __gl_setmode setmode
9905
f2fd1d89ec4b Avoid warning on emx+gcc.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
40 # else
18699
eae8d879de1e xsetmode: new module
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
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
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 # define fileno _fileno
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 # endif
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
eae8d879de1e xsetmode: new module
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
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
eae8d879de1e xsetmode: new module
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
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
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 #endif
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
eae8d879de1e xsetmode: new module
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
69 BINARY_IO_INLINE int
eae8d879de1e xsetmode: new module
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
70 set_binary_mode (int fd, int mode)
eae8d879de1e xsetmode: new module
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
71 {
eae8d879de1e xsetmode: new module
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
72 int r = __gl_setmode_check (fd);
eae8d879de1e xsetmode: new module
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
73 return r != 0 ? r : __gl_setmode (fd, mode);
eae8d879de1e xsetmode: new module
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
74 }
eae8d879de1e xsetmode: new module
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
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
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 #endif /* _BINARY_H */