aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile11
-rw-r--r--include/tinyalsa/asoundlib.h3
-rw-r--r--mixer.c9
-rw-r--r--pcm.c5
4 files changed, 28 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 758f736..d895384 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,9 @@ OBJECTS = mixer.o pcm.o
LIB = libtinyalsa.a
SHLIB = libtinyalsa.so
CROSS_COMPILE =
+PREFIX = /usr/local
+.PHONY: all
all: $(LIB) $(SHLIB) tinyplay tinycap tinymix tinypcminfo
tinyplay: $(SHLIB) tinyplay.o
@@ -29,6 +31,15 @@ $(LIB): $(OBJECTS)
%.o: %.c
$(CROSS_COMPILE)$(CC) $(CFLAGS) -fPIC -c $^ -I$(INC) -o $@
+.PHONY: clean
clean:
-rm $(LIB) $(SHLIB) $(OBJECTS) tinyplay.o tinyplay tinycap.o tinycap \
tinymix.o tinymix tinypcminfo.o tinypcminfo
+
+.PHONY: install
+install: $(LIB) $(SHLIB)
+ cp -u $(SHLIB) $(PREFIX)/lib/$(SHLIB)
+ cp -u $(LIB) $(PREFIX)/lib/$(LIB)
+ mkdir -p $(PREFIX)/include/tinyalsa
+ cp -u $(INC)/tinyalsa/asoundlib.h $(PREFIX)/include/tinyalsa/asoundlib.h
+
diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h
index 8fb7c95..d87e357 100644
--- a/include/tinyalsa/asoundlib.h
+++ b/include/tinyalsa/asoundlib.h
@@ -153,6 +153,9 @@ unsigned int pcm_params_get_min(struct pcm_params *pcm_params,
unsigned int pcm_params_get_max(struct pcm_params *pcm_params,
enum pcm_param param);
+/* Returns the file descriptor associated with the pcm */
+int pcm_get_file_descriptor(struct pcm *pcm);
+
/* Returns a human readable reason for the last error */
const char *pcm_get_error(struct pcm *pcm);
diff --git a/mixer.c b/mixer.c
index 9dd6e68..d6f3fcd 100644
--- a/mixer.c
+++ b/mixer.c
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
@@ -367,7 +368,11 @@ int mixer_ctl_get_array(struct mixer_ctl *ctl, void *array, size_t count)
struct snd_ctl_tlv *tlv;
int ret;
+ if (count > SIZE_MAX - sizeof(*tlv))
+ return -EINVAL;
tlv = calloc(1, sizeof(*tlv) + count);
+ if (!tlv)
+ return -ENOMEM;
tlv->numid = ctl->info.id.numid;
tlv->length = count;
ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_TLV_READ, tlv);
@@ -463,7 +468,11 @@ int mixer_ctl_set_array(struct mixer_ctl *ctl, const void *array, size_t count)
if (ctl->info.access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) {
struct snd_ctl_tlv *tlv;
int ret = 0;
+ if (count > SIZE_MAX - sizeof(*tlv))
+ return -EINVAL;
tlv = calloc(1, sizeof(*tlv) + count);
+ if (!tlv)
+ return -ENOMEM;
tlv->numid = ctl->info.id.numid;
tlv->length = count;
memcpy(tlv->tlv, array, count);
diff --git a/pcm.c b/pcm.c
index 20bb7f0..c1f2212 100644
--- a/pcm.c
+++ b/pcm.c
@@ -180,6 +180,11 @@ unsigned int pcm_get_buffer_size(struct pcm *pcm)
return pcm->buffer_size;
}
+int pcm_get_file_descriptor(struct pcm *pcm)
+{
+ return pcm->fd;
+}
+
const char* pcm_get_error(struct pcm *pcm)
{
return pcm->error;