diff options
author | Max Kellermann <max@duempel.org> | 2010-05-20 06:59:25 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2010-05-20 09:13:39 +0200 |
commit | c727e8698020f69516cb62e001ac6f8254025fe1 (patch) | |
tree | 925ec857d42dc44b743a31de36691b64e59914b0 /src | |
parent | 57b4013306c18a1c510d00845a9915bea0bcf525 (diff) | |
download | mpd-c727e8698020f69516cb62e001ac6f8254025fe1.tar.gz mpd-c727e8698020f69516cb62e001ac6f8254025fe1.tar.xz mpd-c727e8698020f69516cb62e001ac6f8254025fe1.zip |
input/file, output/{fifo,recorder}: add O_BINARY to open() flags
Windows compatibility.
Diffstat (limited to '')
-rw-r--r-- | src/input/file_input_plugin.c | 4 | ||||
-rw-r--r-- | src/open.h | 41 | ||||
-rw-r--r-- | src/output/fifo_output_plugin.c | 6 | ||||
-rw-r--r-- | src/output/recorder_output_plugin.c | 5 |
4 files changed, 49 insertions, 7 deletions
diff --git a/src/input/file_input_plugin.c b/src/input/file_input_plugin.c index a18de67b8..3646c656e 100644 --- a/src/input/file_input_plugin.c +++ b/src/input/file_input_plugin.c @@ -21,9 +21,9 @@ #include "input/file_input_plugin.h" #include "input_plugin.h" #include "fd_util.h" +#include "open.h" #include <sys/stat.h> -#include <fcntl.h> #include <unistd.h> #include <errno.h> #include <string.h> @@ -54,7 +54,7 @@ input_file_open(const char *filename, GError **error_r) if (!g_path_is_absolute(filename)) return false; - fd = open_cloexec(filename, O_RDONLY, 0); + fd = open_cloexec(filename, O_RDONLY|O_BINARY, 0); if (fd < 0) { if (errno != ENOENT && errno != ENOTDIR) g_set_error(error_r, file_quark(), errno, diff --git a/src/open.h b/src/open.h new file mode 100644 index 000000000..e39c64a97 --- /dev/null +++ b/src/open.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2003-2010 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** \file + * + * Portability macros for opening files. + */ + +#ifndef MPD_OPEN_H +#define MPD_OPEN_H + +#include <fcntl.h> + +/* On Windows, files are opened in "text" mode by default, and the C + library will mangle data being read/written; this must be switched + off by specifying the proprietary "O_BINARY" flag. That sucks! */ +#ifndef O_BINARY +#ifdef _O_BINARY +#define O_BINARY _O_BINARY +#else +#define O_BINARY 0 +#endif +#endif + +#endif diff --git a/src/output/fifo_output_plugin.c b/src/output/fifo_output_plugin.c index a92c689f9..f4217ec4d 100644 --- a/src/output/fifo_output_plugin.c +++ b/src/output/fifo_output_plugin.c @@ -22,12 +22,12 @@ #include "utils.h" #include "timer.h" #include "fd_util.h" +#include "open.h" #include <glib.h> #include <sys/types.h> #include <sys/stat.h> -#include <fcntl.h> #include <errno.h> #include <string.h> #include <unistd.h> @@ -154,7 +154,7 @@ fifo_open(struct fifo_data *fd, GError **error) if (!fifo_check(fd, error)) return false; - fd->input = open_cloexec(fd->path, O_RDONLY|O_NONBLOCK, 0); + fd->input = open_cloexec(fd->path, O_RDONLY|O_NONBLOCK|O_BINARY, 0); if (fd->input < 0) { g_set_error(error, fifo_output_quark(), errno, "Could not open FIFO \"%s\" for reading: %s", @@ -163,7 +163,7 @@ fifo_open(struct fifo_data *fd, GError **error) return false; } - fd->output = open_cloexec(fd->path, O_WRONLY|O_NONBLOCK, 0); + fd->output = open_cloexec(fd->path, O_WRONLY|O_NONBLOCK|O_BINARY, 0); if (fd->output < 0) { g_set_error(error, fifo_output_quark(), errno, "Could not open FIFO \"%s\" for writing: %s", diff --git a/src/output/recorder_output_plugin.c b/src/output/recorder_output_plugin.c index ce69a5116..c01d927c4 100644 --- a/src/output/recorder_output_plugin.c +++ b/src/output/recorder_output_plugin.c @@ -22,11 +22,11 @@ #include "encoder_plugin.h" #include "encoder_list.h" #include "fd_util.h" +#include "open.h" #include <assert.h> #include <sys/types.h> #include <sys/stat.h> -#include <fcntl.h> #include <unistd.h> #include <errno.h> @@ -158,7 +158,8 @@ recorder_output_open(void *data, struct audio_format *audio_format, /* create the output file */ - recorder->fd = open_cloexec(recorder->path, O_CREAT|O_WRONLY|O_TRUNC, + recorder->fd = open_cloexec(recorder->path, + O_CREAT|O_WRONLY|O_TRUNC|O_BINARY, 0666); if (recorder->fd < 0) { g_set_error(error_r, recorder_output_quark(), 0, |