More -Wwrite-strings cleanup and make sure you can actually play it.
[dragonfly.git] / contrib / diffutils-2.8.1 / lib / setmode.c
blobdbcf44e8f37a97ea6cde54042cfcf74f3589afb0
1 /* Set a file descriptor's mode to binary or to text.
3 Copyright (C) 2001 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING.
17 If not, write to the Free Software Foundation,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 /* Written by Paul Eggert <eggert@twinsun.com> */
22 #if HAVE_CONFIG_H
23 # include <config.h>
24 #endif
26 #if HAVE_STDBOOL_H
27 # include <stdbool.h>
28 #else
29 typedef enum {false = 0, true = 1} bool;
30 #endif
32 #if HAVE_SETMODE_DOS
33 # include <io.h>
34 # if HAVE_FCNTL_H
35 # include <fcntl.h>
36 # endif
37 # if HAVE_UNISTD_H
38 # include <unistd.h>
39 # endif
40 #endif
42 #include "setmode.h"
43 #undef set_binary_mode
46 /* Set the binary mode of FD to MODE, returning its previous mode.
47 MODE is 1 for binary and 0 for text. If setting the mode might
48 cause problems, ignore the request and return MODE. Always return
49 1 on POSIX platforms, which do not distinguish between text and
50 binary. */
52 bool
53 set_binary_mode (int fd, bool mode)
55 #if HAVE_SETMODE_DOS
56 if (isatty (fd))
57 return mode;
58 return setmode (fd, mode ? O_BINARY : O_TEXT) != O_TEXT;
59 #else
60 return 1;
61 #endif