annotate lib/binary-io.h @ 4608:a079d84287d0

Make it work with MSVC.
author Bruno Haible <bruno@clisp.org>
date Mon, 25 Aug 2003 11:04:49 +0000
parents 72b1283160ce
children 35fed2680490
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.
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2001, 2003 Free Software Foundation, Inc.
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
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
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 any later version.
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
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program; if not, write to the Free Software Foundation,
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #ifndef _BINARY_H
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #define _BINARY_H
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 /* For systems that distinguish between text and binary I/O.
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 O_BINARY is usually declared in <fcntl.h>. */
4608
a079d84287d0 Make it work with MSVC.
Bruno Haible <bruno@clisp.org>
parents: 4273
diff changeset
23 #include <fcntl.h>
a079d84287d0 Make it work with MSVC.
Bruno Haible <bruno@clisp.org>
parents: 4273
diff changeset
24
a079d84287d0 Make it work with MSVC.
Bruno Haible <bruno@clisp.org>
parents: 4273
diff changeset
25 /* 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
26 so we include it here first. */
a079d84287d0 Make it work with MSVC.
Bruno Haible <bruno@clisp.org>
parents: 4273
diff changeset
27 #include <stdio.h>
a079d84287d0 Make it work with MSVC.
Bruno Haible <bruno@clisp.org>
parents: 4273
diff changeset
28
4273
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #if !defined O_BINARY && defined _O_BINARY
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 /* For MSC-compatible compilers. */
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 # define O_BINARY _O_BINARY
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 # define O_TEXT _O_TEXT
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 #endif
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 #ifdef __BEOS__
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 # undef O_BINARY
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 # undef O_TEXT
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 #endif
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 #if O_BINARY
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 # if !(defined __EMX__ || defined __DJGPP__)
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 # define setmode _setmode
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 # define fileno _fileno
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 # endif
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 # ifdef __DJGPP__
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 # include <io.h> /* declares setmode() */
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 # include <unistd.h> /* declares isatty() */
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 # /* Avoid putting stdin/stdout in binary mode if it is connected to the
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 # console, because that would make it impossible for the user to
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 # interrupt the program through Ctrl-C or Ctrl-Break. */
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 # define SET_BINARY(fd) (!isatty (fd) ? (setmode (fd, O_BINARY), 0) : 0)
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 # else
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 # define SET_BINARY(fd) setmode (fd, O_BINARY)
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 # endif
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 #else
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 /* On reasonable systems, binary I/O is the default. */
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 # define O_BINARY 0
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 # define SET_BINARY(fd) /* nothing */
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 #endif
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
72b1283160ce New module 'binary-io'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 #endif /* _BINARY_H */