annotate lib/binary-io.h @ 17102:9e72d3927af1

binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline' * lib/binary-io.c, lib/eealloc.c, lib/mbfile.c, lib/mbiter.c: * lib/mbuiter.c, lib/xsize.c: New files. * lib/binary-io.h (BINARY_IO_INLINE): * lib/eealloc.h (EEALLOC_INLINE): * lib/mbfile.h (MBFILE_INLINE): * lib/mbiter.h (MBITER_INLINE): * lib/mbuiter.h (MBUITER_INLINE): * lib/xsize.h (XSIZE_INLINE): New macros. Replace all uses of 'static inline' with them. Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END. * m4/eealloc.m4 (gl_EEALLOC): * m4/mbfile.m4 (gl_MBFILE): * m4/mbiter.m4 (gl_MBITER): * m4/xsize.m4 (gl_XSIZE): Do not require AC_C_INLINE. * modules/binary-io (Files, lib_SOURCES): Add lib/binary-io.c * modules/eealloc (Files, lib_SOURCES): Add lib/eealloc.c. * modules/mbfile (Files, lib_SOURCES): Add lib/mbfile.c. * modules/mbiter (Files, lib_SOURCES): Add lib/mbiter.c. * modules/mbuiter (Files, lib_SOURCES): Add lib/mbuiter.c. * modules/xsize (Files, lib_SOURCES): Add lib/xsize.c. * modules/binary-io, modules/eealloc, modules/mbfile: * modules/mbiter, modules/mbuiter: (Depends-on): Add extern-inline.
author Paul Eggert <eggert@cs.ucla.edu>
date Wed, 29 Aug 2012 23:13:42 -0700
parents 67cb7096523b
children e542fd46ad6f
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.
16201
8250f2777afc maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents: 14182
diff changeset
2 Copyright (C) 2001, 2003, 2005, 2008-2012 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
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 5916
diff changeset
15 along with this program. If not, see <http://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
17102
9e72d3927af1 binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents: 17094
diff changeset
28 _GL_INLINE_HEADER_BEGIN
9e72d3927af1 binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents: 17094
diff changeset
29 #ifndef BINARY_IO_INLINE
9e72d3927af1 binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents: 17094
diff changeset
30 # 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
31 #endif
9e72d3927af1 binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents: 17094
diff changeset
32
16851
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
33 /* set_binary_mode (fd, mode)
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
34 sets the binary/text I/O mode of file descriptor fd to the given mode
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
35 (must be O_BINARY or O_TEXT) and returns the previous mode. */
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() */
16851
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
39 # define set_binary_mode setmode
9905
f2fd1d89ec4b Avoid warning on emx+gcc.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
40 # else
16851
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
41 # define set_binary_mode _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
16851
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
50 set_binary_mode (int fd, int mode)
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 (void) fd;
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
53 (void) mode;
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
54 return O_BINARY;
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
55 }
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
56 #endif
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
57
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
58 /* SET_BINARY (fd);
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
59 changes the file descriptor fd to perform binary I/O. */
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
60 #ifdef __DJGPP__
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
61 # include <unistd.h> /* declares isatty() */
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
62 /* Avoid putting stdin/stdout in binary mode if it is connected to
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
63 the console, because that would make it impossible for the user
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
64 to interrupt the program through Ctrl-C or Ctrl-Break. */
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
65 # define SET_BINARY(fd) ((void) (!isatty (fd) ? (set_binary_mode (fd, O_BINARY), 0) : 0))
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
66 #else
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
67 # define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
4273
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 #endif
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69
17102
9e72d3927af1 binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents: 17094
diff changeset
70 _GL_INLINE_HEADER_END
9e72d3927af1 binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents: 17094
diff changeset
71
4273
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 #endif /* _BINARY_H */