input/file, output/{fifo,recorder}: add O_BINARY to open() flags
Windows compatibility.
This commit is contained in:
parent
57b4013306
commit
c727e86980
@ -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,
|
||||
|
41
src/open.h
Normal file
41
src/open.h
Normal file
@ -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
|
@ -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",
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user