Mercurial > hg > octave-lojdl > gnulib-hg
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 |
rev | line source |
---|---|
4273 | 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 | 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 | |
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 | 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 | |
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 | 36 #if O_BINARY |
9905 | 37 # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__ |
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 | 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 | 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 |
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 | 68 #endif |
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 | 72 #endif /* _BINARY_H */ |