void *handle;
struct snd_ctl_hw_info info;
+ if (!string)
+ return -EINVAL;
bitmask = snd_cards_mask();
if (!bitmask)
return -ENODEV;
- if (!string)
- return -EINVAL;
if ((isdigit(*string) && *(string + 1) == 0) ||
(isdigit(*string) && isdigit(*(string + 1)) && *(string + 2) == 0)) {
sscanf(string, "%i", &card);
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !info)
return -EINVAL;
if (ioctl(ctl->fd, SND_CTL_IOCTL_HW_INFO, info) < 0)
return -errno;
int idx, switches, err;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !switch_id)
return -EINVAL;
/* bellow implementation isn't optimized for speed */
/* info about switches should be cached in the snd_ctl_t structure */
return -EINVAL;
}
-int snd_ctl_switch_read(void *handle, int switchn, struct snd_ctl_switch *data)
+int snd_ctl_switch_read(void *handle, int switchn, snd_ctl_switch_t *data)
{
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !data || switchn < 0)
return -EINVAL;
+ bzero(data, sizeof(snd_ctl_switch_t));
data->switchn = switchn;
if (ioctl(ctl->fd, SND_CTL_IOCTL_SWITCH_READ, data) < 0)
return -errno;
return 0;
}
-int snd_ctl_switch_write(void *handle, int switchn, struct snd_ctl_switch *data)
+int snd_ctl_switch_write(void *handle, int switchn, snd_ctl_switch_t *data)
{
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !data || switchn < 0)
return -EINVAL;
data->switchn = switchn;
if (ioctl(ctl->fd, SND_CTL_IOCTL_SWITCH_WRITE, data) < 0)
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !info || dev < 0)
return -EINVAL;
if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
return -errno;
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !info || dev < 0)
return -EINVAL;
if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
return -errno;
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !info || dev < 0)
return -EINVAL;
if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
return -errno;
int result;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || dev < 0)
return -EINVAL;
if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
return -errno;
int idx, switches, err;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !switch_id || dev < 0)
return -EINVAL;
/* bellow implementation isn't optimized for speed */
/* info about switches should be cached in the snd_ctl_t structure */
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !data || dev < 0 || switchn < 0)
return -EINVAL;
+ bzero(data, sizeof(snd_pcm_switch_t));
data->switchn = switchn;
if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
return -errno;
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !data || dev < 0 || switchn < 0)
return -EINVAL;
data->switchn = switchn;
if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
int result;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || dev < 0)
return -EINVAL;
if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
return -errno;
int idx, switches, err;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !switch_id || dev < 0)
return -EINVAL;
/* bellow implementation isn't optimized for speed */
/* info about switches should be cached in the snd_ctl_t structure */
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !data || dev < 0 || switchn < 0)
return -EINVAL;
+ bzero(data, sizeof(snd_pcm_switch_t));
data->switchn = switchn;
if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
return -errno;
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !data || dev < 0 || switchn < 0)
return -EINVAL;
data->switchn = switchn;
if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !info || dev < 0)
return -EINVAL;
if (ioctl(ctl->fd, SND_CTL_IOCTL_MIXER_DEVICE, &dev) < 0)
return -errno;
int result;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || dev < 0)
return -EINVAL;
if (ioctl(ctl->fd, SND_CTL_IOCTL_MIXER_DEVICE, &dev) < 0)
return -errno;
int idx, switches, err;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !switch_id || dev < 0)
return -EINVAL;
/* bellow implementation isn't optimized for speed */
/* info about switches should be cached in the snd_ctl_t structure */
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !data || dev < 0 || switchn < 0)
return -EINVAL;
+ bzero(data, sizeof(snd_mixer_switch_t));
data->switchn = switchn;
if (ioctl(ctl->fd, SND_CTL_IOCTL_MIXER_DEVICE, &dev) < 0)
return -errno;
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !data || dev < 0 || switchn < 0)
return -EINVAL;
data->switchn = switchn;
if (ioctl(ctl->fd, SND_CTL_IOCTL_MIXER_DEVICE, &dev) < 0)
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !info)
return -EINVAL;
if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
return -errno;
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !info || dev < 0)
return -EINVAL;
if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
return -errno;
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !info || dev < 0)
return -EINVAL;
if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
return -errno;
int result;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || dev < 0)
return -EINVAL;
if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
return -errno;
int idx, switches, err;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !switch_id || dev < 0)
return -EINVAL;
/* bellow implementation isn't optimized for speed */
/* info about switches should be cached in the snd_ctl_t structure */
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !data || dev < 0 || switchn < 0)
return -EINVAL;
+ bzero(data, sizeof(snd_rawmidi_switch_t));
data->switchn = switchn;
if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
return -errno;
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !data || dev < 0 || switchn < 0)
return -EINVAL;
data->switchn = switchn;
if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
int result;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || dev < 0)
return -EINVAL;
if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
return -errno;
int idx, switches, err;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !switch_id || dev < 0)
return -EINVAL;
/* bellow implementation isn't optimized for speed */
/* info about switches should be cached in the snd_ctl_t structure */
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !data || dev < 0 || switchn < 0)
return -EINVAL;
+ bzero(data, sizeof(snd_rawmidi_switch_t));
data->switchn = switchn;
if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
return -errno;
snd_ctl_t *ctl;
ctl = (snd_ctl_t *) handle;
- if (!ctl)
+ if (!ctl || !data || dev < 0 || switchn < 0)
return -EINVAL;
data->switchn = switchn;
if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
snd_mixer_t *mixer;
mixer = (snd_mixer_t *) handle;
- if (!mixer)
+ if (!mixer || !info)
return -EINVAL;
if (ioctl(mixer->fd, SND_MIXER_IOCTL_INFO, info) < 0)
return -errno;
int idx, channels, err;
mixer = (snd_mixer_t *) handle;
- if (!mixer)
+ if (!mixer || !channel_id)
return -EINVAL;
/* bellow implementation isn't optimized for speed */
/* info about channels should be cached in the snd_mixer_t structure */
snd_mixer_t *mixer;
mixer = (snd_mixer_t *) handle;
- if (!mixer)
+ if (!mixer || !info || channel < 0)
return -EINVAL;
info->channel = channel;
if (ioctl(mixer->fd, SND_MIXER_IOCTL_CHANNEL_INFO, info) < 0)
snd_mixer_t *mixer;
mixer = (snd_mixer_t *) handle;
- if (!mixer)
+ if (!mixer || !data || channel < 0)
return -EINVAL;
+ bzero(data, sizeof(snd_mixer_channel_t));
data->channel = channel;
if (ioctl(mixer->fd, SND_MIXER_IOCTL_CHANNEL_READ, data) < 0)
return -errno;
snd_mixer_t *mixer;
mixer = (snd_mixer_t *) handle;
- if (!mixer)
+ if (!mixer || !data)
return -EINVAL;
data->channel = channel;
if (ioctl(mixer->fd, SND_MIXER_IOCTL_CHANNEL_WRITE, data) < 0)
snd_mixer_t *mixer;
mixer = (snd_mixer_t *) handle;
- if (!mixer)
+ if (!mixer || !data || channel < 0)
return -EINVAL;
+ bzero(data, sizeof(snd_mixer_channel_t));
data->channel = channel;
if (ioctl(mixer->fd, SND_MIXER_IOCTL_CHANNEL_RREAD, data) < 0)
return -errno;
snd_mixer_t *mixer;
mixer = (snd_mixer_t *) handle;
- if (!mixer)
+ if (!mixer || !data || channel < 0)
return -EINVAL;
data->channel = channel;
if (ioctl(mixer->fd, SND_MIXER_IOCTL_CHANNEL_RWRITE, data) < 0)
int idx, switches, err;
mixer = (snd_mixer_t *) handle;
- if (!mixer)
+ if (!mixer || !switch_id)
return -EINVAL;
/* bellow implementation isn't optimized for speed */
/* info about switches should be cached in the snd_mixer_t structure */
snd_mixer_t *mixer;
mixer = (snd_mixer_t *) handle;
- if (!mixer)
+ if (!mixer || !data || switchn < 0)
return -EINVAL;
+ bzero(data, sizeof(snd_mixer_switch_t));
data->switchn = switchn;
if (ioctl(mixer->fd, SND_MIXER_IOCTL_SWITCH_READ, data) < 0)
return -errno;
snd_mixer_t *mixer;
mixer = (snd_mixer_t *) handle;
- if (!mixer)
+ if (!mixer || !data || switchn < 0)
return -EINVAL;
data->switchn = switchn;
if (ioctl(mixer->fd, SND_MIXER_IOCTL_SWITCH_WRITE, data) < 0)
snd_pcm_t *pcm;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || !info)
return -EINVAL;
if (ioctl(pcm->fd, SND_PCM_IOCTL_INFO, info) < 0)
return -errno;
snd_pcm_t *pcm;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || !info)
return -EINVAL;
if (ioctl(pcm->fd, SND_PCM_IOCTL_PLAYBACK_INFO, info) < 0)
return -errno;
snd_pcm_t *pcm;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || !info)
return -EINVAL;
if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_INFO, info) < 0)
return -errno;
int idx, switches, err;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || !switch_id)
return -EINVAL;
/* bellow implementation isn't optimized for speed */
/* info about switches should be cached in the snd_mixer_t structure */
snd_pcm_t *pcm;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || !data || switchn < 0)
return -EINVAL;
+ bzero(data, sizeof(snd_pcm_switch_t));
data->switchn = switchn;
if (ioctl(pcm->fd, SND_PCM_IOCTL_PSWITCH_READ, data) < 0)
return -errno;
snd_pcm_t *pcm;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || !data || switchn < 0)
return -EINVAL;
data->switchn = switchn;
if (ioctl(pcm->fd, SND_PCM_IOCTL_PSWITCH_WRITE, data) < 0)
int idx, switches, err;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || !switch_id)
return -EINVAL;
/* bellow implementation isn't optimized for speed */
/* info about switches should be cached in the snd_mixer_t structure */
snd_pcm_t *pcm;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || !data || switchn < 0)
return -EINVAL;
+ bzero(data, sizeof(snd_pcm_switch_t));
data->switchn = switchn;
if (ioctl(pcm->fd, SND_PCM_IOCTL_RSWITCH_READ, data) < 0)
return -errno;
snd_pcm_t *pcm;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || !data || switchn < 0)
return -EINVAL;
data->switchn = switchn;
if (ioctl(pcm->fd, SND_PCM_IOCTL_RSWITCH_WRITE, data) < 0)
snd_pcm_t *pcm;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || !format)
return -EINVAL;
if (ioctl(pcm->fd, SND_PCM_IOCTL_PLAYBACK_FORMAT, format) < 0)
return -errno;
snd_pcm_t *pcm;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || !format)
return -EINVAL;
if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_FORMAT, format) < 0)
return -errno;
snd_pcm_t *pcm;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || !params)
return -EINVAL;
if (ioctl(pcm->fd, SND_PCM_IOCTL_PLAYBACK_PARAMS, params) < 0)
return -errno;
snd_pcm_t *pcm;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || !params)
return -EINVAL;
if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_PARAMS, params) < 0)
return -errno;
snd_pcm_t *pcm;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || !status)
return -EINVAL;
if (ioctl(pcm->fd, SND_PCM_IOCTL_PLAYBACK_STATUS, status) < 0)
return -errno;
snd_pcm_t *pcm;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || !status)
return -EINVAL;
if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_STATUS, status) < 0)
return -errno;
ssize_t result;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || (!buffer && size > 0) || size < 0)
return -EINVAL;
result = write(pcm->fd, buffer, size);
if (result < 0)
ssize_t result;
pcm = (snd_pcm_t *) handle;
- if (!pcm)
+ if (!pcm || (!buffer && size > 0) || size < 0)
return -EINVAL;
result = read(pcm->fd, buffer, size);
if (result < 0)
#include "asoundlib.h"
#define SND_FILE_RAWMIDI "/dev/snd/midi%i%i"
-#define SND_PCM_VERSION_MAX SND_PROTOCOL_VERSION( 1, 0, 0 )
+#define SND_RAWMIDI_VERSION_MAX SND_PROTOCOL_VERSION( 1, 0, 0 )
typedef struct {
int card;
close(fd);
return -errno;
}
- if (SND_PROTOCOL_UNCOMPATIBLE(ver, SND_PCM_VERSION_MAX)) {
+ if (SND_PROTOCOL_UNCOMPATIBLE(ver, SND_RAWMIDI_VERSION_MAX)) {
close(fd);
return -SND_ERROR_UNCOMPATIBLE_VERSION;
}
snd_rawmidi_t *rmidi;
rmidi = (snd_rawmidi_t *) handle;
- if (!rmidi)
+ if (!rmidi || !info)
return -EINVAL;
if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_INFO, info) < 0)
return -errno;
int idx, switches, err;
rmidi = (snd_rawmidi_t *) handle;
- if (!rmidi)
+ if (!rmidi || !switch_id)
return -EINVAL;
/* bellow implementation isn't optimized for speed */
/* info about switches should be cached in the snd_mixer_t structure */
snd_rawmidi_t *rmidi;
rmidi = (snd_rawmidi_t *) handle;
- if (!rmidi)
+ if (!rmidi || !data || switchn < 0)
return -EINVAL;
+ bzero(data, sizeof(snd_rawmidi_switch_t));
data->switchn = switchn;
if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_OSWITCH_READ, data) < 0)
return -errno;
snd_rawmidi_t *rmidi;
rmidi = (snd_rawmidi_t *) handle;
- if (!rmidi)
+ if (!rmidi || !data || switchn < 0)
return -EINVAL;
data->switchn = switchn;
if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_OSWITCH_WRITE, data) < 0)
int idx, switches, err;
rmidi = (snd_rawmidi_t *) handle;
- if (!rmidi)
+ if (!rmidi || !switch_id)
return -EINVAL;
/* bellow implementation isn't optimized for speed */
/* info about switches should be cached in the snd_mixer_t structure */
snd_rawmidi_t *rmidi;
rmidi = (snd_rawmidi_t *) handle;
- if (!rmidi)
+ if (!rmidi || !data || switchn < 0)
return -EINVAL;
+ bzero(data, sizeof(snd_rawmidi_switch_t));
data->switchn = switchn;
if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_ISWITCH_READ, data) < 0)
return -errno;
snd_rawmidi_t *rmidi;
rmidi = (snd_rawmidi_t *) handle;
- if (!rmidi)
+ if (!rmidi || !data || switchn < 0)
return -EINVAL;
data->switchn = switchn;
if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_ISWITCH_WRITE, data) < 0)
snd_rawmidi_t *rmidi;
rmidi = (snd_rawmidi_t *) handle;
- if (!rmidi)
+ if (!rmidi || !params)
return -EINVAL;
if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_OUTPUT_PARAMS, params) < 0)
return -errno;
snd_rawmidi_t *rmidi;
rmidi = (snd_rawmidi_t *) handle;
- if (!rmidi)
+ if (!rmidi || !params)
return -EINVAL;
if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_INPUT_PARAMS, params) < 0)
return -errno;
snd_rawmidi_t *rmidi;
rmidi = (snd_rawmidi_t *) handle;
- if (!rmidi)
+ if (!rmidi || !status)
return -EINVAL;
if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_OUTPUT_STATUS, status) < 0)
return -errno;
snd_rawmidi_t *rmidi;
rmidi = (snd_rawmidi_t *) handle;
- if (!rmidi)
+ if (!rmidi || !status)
return -EINVAL;
if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_INPUT_STATUS, status) < 0)
return -errno;
ssize_t result;
rmidi = (snd_rawmidi_t *) handle;
- if (!rmidi)
+ if (!rmidi || (!buffer && size > 0) || size < 0)
return -EINVAL;
result = write(rmidi->fd, buffer, size);
if (result < 0)
ssize_t result;
rmidi = (snd_rawmidi_t *) handle;
- if (!rmidi)
+ if (!rmidi || (!buffer && size > 0) || size < 0)
return -EINVAL;
result = read(rmidi->fd, buffer, size);
if (result < 0)