aboutsummaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorTakashi Yano <takashi.yano@nifty.ne.jp>2024-06-28 13:42:03 +0900
committerTakashi Yano <takashi.yano@nifty.ne.jp>2024-06-28 19:54:19 +0900
commiteaa606c0b7c1ce3aeda2594eb4a1ad0341cc4b06 (patch)
tree93df77ecd1b254c08e4d6664f98f887e1abd6886 /winsup
parent36e398b04e91668403bac94b4c28f4822997b535 (diff)
downloadnewlib-eaa606c0b7c1ce3aeda2594eb4a1ad0341cc4b06.zip
newlib-eaa606c0b7c1ce3aeda2594eb4a1ad0341cc4b06.tar.gz
newlib-eaa606c0b7c1ce3aeda2594eb4a1ad0341cc4b06.tar.bz2
Cygwin: dsp: Fix incorrect openflags when opening multiple /dev/dsp
Previously, the following steps failed with error: 1) Open /dev/dsp with O_RDONLY 2) Open /dev/dsp with O_WRONLY 3) Issue SNDCTL_DSP_GETOSPACE ioctl() for 2) This is because IS_WRITE() returns false for 2) due to incorrect openflags handling in archetype instance. This patch fixes the issue by adding open_setup() to fhandler_dev_dsp to set openflags correctly for each instance. Fixes: 92ddb7429065 ("* fhandler_dsp.cc (fhandler_dev_dsp::open): Remove archetype handling.") Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/fhandler/dsp.cc26
-rw-r--r--winsup/cygwin/local_includes/fhandler.h7
2 files changed, 20 insertions, 13 deletions
diff --git a/winsup/cygwin/fhandler/dsp.cc b/winsup/cygwin/fhandler/dsp.cc
index 59c11ac..605a048 100644
--- a/winsup/cygwin/fhandler/dsp.cc
+++ b/winsup/cygwin/fhandler/dsp.cc
@@ -1026,19 +1026,19 @@ fhandler_dev_dsp::fhandler_dev_dsp ():
ssize_t
fhandler_dev_dsp::write (const void *ptr, size_t len)
{
- return base ()->_write (ptr, len);
+ return base ()->_write (ptr, len, this);
}
void
fhandler_dev_dsp::read (void *ptr, size_t& len)
{
- base ()->_read (ptr, len);
+ base ()->_read (ptr, len, this);
}
int
fhandler_dev_dsp::ioctl (unsigned int cmd, void *buf)
{
- return base ()->_ioctl (cmd, buf);
+ return base ()->_ioctl (cmd, buf, this);
}
int
@@ -1065,7 +1065,6 @@ fhandler_dev_dsp::open (int flags, mode_t mode)
{
int ret = -1, err = 0;
UINT num_in = 0, num_out = 0;
- set_flags ((flags & ~O_TEXT) | O_BINARY);
// Work out initial sample format & frequency, /dev/dsp defaults
audioformat_ = AFMT_U8;
audiofreq_ = 8000;
@@ -1105,11 +1104,11 @@ fhandler_dev_dsp::open (int flags, mode_t mode)
return ret;
}
-#define IS_WRITE() ((get_flags() & O_ACCMODE) != O_RDONLY)
-#define IS_READ() ((get_flags() & O_ACCMODE) != O_WRONLY)
+#define IS_WRITE() ((fh->get_flags() & O_ACCMODE) != O_RDONLY)
+#define IS_READ() ((fh->get_flags() & O_ACCMODE) != O_WRONLY)
ssize_t
-fhandler_dev_dsp::_write (const void *ptr, size_t len)
+fhandler_dev_dsp::_write (const void *ptr, size_t len, fhandler_dev_dsp *fh)
{
debug_printf ("ptr=%p len=%ld", ptr, len);
int len_s = len;
@@ -1168,7 +1167,7 @@ fhandler_dev_dsp::_write (const void *ptr, size_t len)
}
void
-fhandler_dev_dsp::_read (void *ptr, size_t& len)
+fhandler_dev_dsp::_read (void *ptr, size_t& len, fhandler_dev_dsp *fh)
{
debug_printf ("ptr=%p len=%ld", ptr, len);
@@ -1244,7 +1243,7 @@ fhandler_dev_dsp::close ()
}
int
-fhandler_dev_dsp::_ioctl (unsigned int cmd, void *buf)
+fhandler_dev_dsp::_ioctl (unsigned int cmd, void *buf, fhandler_dev_dsp *fh)
{
debug_printf ("audio_in=%p audio_out=%p", audio_in_, audio_out_);
int *intbuf = (int *) buf;
@@ -1349,7 +1348,7 @@ fhandler_dev_dsp::_ioctl (unsigned int cmd, void *buf)
CASE (SNDCTL_DSP_STEREO)
{
int nChannels = *intbuf + 1;
- int res = _ioctl (SNDCTL_DSP_CHANNELS, &nChannels);
+ int res = _ioctl (SNDCTL_DSP_CHANNELS, &nChannels, fh);
*intbuf = nChannels - 1;
return res;
}
@@ -1547,3 +1546,10 @@ fhandler_dev_dsp::read_ready ()
{
return base ()->_read_ready ();
}
+
+bool
+fhandler_dev_dsp::open_setup (int flags)
+{
+ set_flags ((flags & ~O_TEXT) | O_BINARY);
+ return fhandler_base::open_setup (flags);
+}
diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_includes/fhandler.h
index 978d3e5..fa61595 100644
--- a/winsup/cygwin/local_includes/fhandler.h
+++ b/winsup/cygwin/local_includes/fhandler.h
@@ -2881,11 +2881,12 @@ class fhandler_dev_dsp: public fhandler_base
int close ();
void fixup_after_fork (HANDLE);
void fixup_after_exec ();
+ bool open_setup (int);
private:
- ssize_t _write (const void *, size_t);
- void _read (void *, size_t&);
- int _ioctl (unsigned int, void *);
+ ssize_t _write (const void *, size_t, fhandler_dev_dsp *);
+ void _read (void *, size_t&, fhandler_dev_dsp *);
+ int _ioctl (unsigned int, void *, fhandler_dev_dsp *);
int _fcntl (int cmd, intptr_t);
void _fixup_after_fork (HANDLE);
void _fixup_after_exec ();