mirror of https://github.com/ericonr/sndio.git
add portability bits for OS X
This commit is contained in:
parent
f9f2d8353e
commit
a48a424901
|
@ -21,4 +21,16 @@ size_t strlcpy(char *, const char *, size_t);
|
||||||
long long strtonum(const char *, long long, long long, const char **);
|
long long strtonum(const char *, long long, long long, const char **);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_SOCK_CLOEXEC
|
||||||
|
#define strtonum _sndio_strtonum
|
||||||
|
long long strtonum(const char *, long long, long long, const char **);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_CLOCK_GETTIME
|
||||||
|
#define CLOCK_MONOTONIC 0
|
||||||
|
#define clock_gettime _sndio_clock_gettime
|
||||||
|
struct timespec;
|
||||||
|
int clock_gettime(int, struct timespec *);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* !defined(BSD_COMPAT_H) */
|
#endif /* !defined(BSD_COMPAT_H) */
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2017 Alexandre Ratchov <alex@coua.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include "bsd-compat.h"
|
||||||
|
|
||||||
|
#ifndef HAVE_CLOCK_GETTIME
|
||||||
|
|
||||||
|
int
|
||||||
|
_sndio_clock_gettime(int timer, struct timespec *ts)
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
if (timer != CLOCK_MONOTONIC) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gettimeofday(&tv, NULL) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
ts->tv_sec = tv.tv_sec;
|
||||||
|
ts->tv_nsec = tv.tv_usec * 1000;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -57,33 +57,37 @@ case `uname` in
|
||||||
alsa=yes
|
alsa=yes
|
||||||
ldadd="-lrt"
|
ldadd="-lrt"
|
||||||
user=sndiod
|
user=sndiod
|
||||||
so="$so libsndio.so"
|
so_link="libsndio.so"
|
||||||
defs='-D_GNU_SOURCE -DDEV_RANDOM=\\"/dev/urandom\\"'
|
defs='-D_GNU_SOURCE -DDEV_RANDOM=\\"/dev/urandom\\" \\\
|
||||||
|
-DHAVE_SOCK_CLOEXEC'
|
||||||
;;
|
;;
|
||||||
NetBSD)
|
NetBSD)
|
||||||
sun=no
|
sun=no
|
||||||
rmidi=yes
|
rmidi=yes
|
||||||
user=_sndio
|
user=_sndio
|
||||||
so="$so libsndio.so"
|
so_link="libsndio.so"
|
||||||
defs='-DHAVE_ARC4RANDOM -DHAVE_ISSETUGID \\\
|
defs='-DHAVE_ARC4RANDOM -DHAVE_ISSETUGID \\\
|
||||||
-DHAVE_STRLCAT -DHAVE_STRLCPY'
|
-DHAVE_STRLCAT -DHAVE_STRLCPY -DHAVE_SOCK_CLOEXEC'
|
||||||
;;
|
;;
|
||||||
OpenBSD)
|
OpenBSD)
|
||||||
sun=yes
|
sun=yes
|
||||||
rmidi=yes
|
rmidi=yes
|
||||||
user=_sndio
|
user=_sndio
|
||||||
defs='-DHAVE_ARC4RANDOM -DHAVE_ISSETUGID \\\
|
defs='-DHAVE_ARC4RANDOM -DHAVE_ISSETUGID \\\
|
||||||
-DHAVE_STRLCAT -DHAVE_STRLCPY -DHAVE_STRTONUM'
|
-DHAVE_STRLCAT -DHAVE_STRLCPY -DHAVE_STRTONUM -DHAVE_SOCK_CLOEXEC'
|
||||||
;;
|
;;
|
||||||
DragonFly|FreeBSD)
|
DragonFly|FreeBSD)
|
||||||
umidi=yes
|
umidi=yes
|
||||||
user=_sndio
|
user=_sndio
|
||||||
so="$so libsndio.so"
|
so_link="libsndio.so"
|
||||||
defs='-DHAVE_ARC4RANDOM -DHAVE_ISSETUGID \\\
|
defs='-DHAVE_ARC4RANDOM -DHAVE_ISSETUGID \\\
|
||||||
-DHAVE_STRLCAT -DHAVE_STRLCPY -DHAVE_STRTONUM'
|
-DHAVE_STRLCAT -DHAVE_STRLCPY -DHAVE_STRTONUM -DHAVE_SOCK_CLOEXEC'
|
||||||
oss=yes
|
|
||||||
mandir=${prefix}/man
|
|
||||||
;;
|
;;
|
||||||
|
Darwin)
|
||||||
|
rmidi=no
|
||||||
|
so="libsndio.\${MAJ}.\${MIN}.dylib"
|
||||||
|
defs='-DHAVE_ARC4RANDOM -DHAVE_ISSETUGID \\\
|
||||||
|
-DHAVE_STRLCAT -DHAVE_STRLCPY'
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# shell word separator (none)
|
# shell word separator (none)
|
||||||
|
@ -244,6 +248,7 @@ do
|
||||||
-e "s:@defs@:$defs:" \
|
-e "s:@defs@:$defs:" \
|
||||||
-e "s:@ldadd@:$ldadd:" \
|
-e "s:@ldadd@:$ldadd:" \
|
||||||
-e "s:@so@:$so:" \
|
-e "s:@so@:$so:" \
|
||||||
|
-e "s:@so_link@:$so_link:" \
|
||||||
-e "s:@vars@:${vars}:" \
|
-e "s:@vars@:${vars}:" \
|
||||||
-e "s:@precision@:$precision:" \
|
-e "s:@precision@:$precision:" \
|
||||||
-e "s:@user@:$user:" \
|
-e "s:@user@:$user:" \
|
||||||
|
|
|
@ -14,7 +14,7 @@ LDADD = @ldadd@
|
||||||
SO_CFLAGS = -fPIC
|
SO_CFLAGS = -fPIC
|
||||||
|
|
||||||
# extra compiler flags to produce a shared library with the given name
|
# extra compiler flags to produce a shared library with the given name
|
||||||
SO_LDFLAGS = -shared -Wl,-soname=libsndio.so.${MAJ}.${MIN}
|
SO_LDFLAGS = -shared #-Wl,-soname=libsndio.so.${MAJ}.${MIN}
|
||||||
|
|
||||||
# variables defined on configure script command line (if any)
|
# variables defined on configure script command line (if any)
|
||||||
@vars@
|
@vars@
|
||||||
|
@ -45,6 +45,7 @@ MAN7 = sndio.7
|
||||||
MAJ = 6
|
MAJ = 6
|
||||||
MIN = 1
|
MIN = 1
|
||||||
SO = @so@
|
SO = @so@
|
||||||
|
SO_LINK = @so_link@
|
||||||
|
|
||||||
all: ${SO}
|
all: ${SO}
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ install:
|
||||||
mkdir -p ${DESTDIR}${MAN3_DIR}
|
mkdir -p ${DESTDIR}${MAN3_DIR}
|
||||||
mkdir -p ${DESTDIR}${MAN7_DIR}
|
mkdir -p ${DESTDIR}${MAN7_DIR}
|
||||||
cp sndio.h ${DESTDIR}${INCLUDE_DIR}
|
cp sndio.h ${DESTDIR}${INCLUDE_DIR}
|
||||||
cp -R ${SO} ${DESTDIR}${LIB_DIR}
|
cp -R ${SO} ${SO_LINK} ${DESTDIR}${LIB_DIR}
|
||||||
cp sio_open.3 ${DESTDIR}${MAN3_DIR}
|
cp sio_open.3 ${DESTDIR}${MAN3_DIR}
|
||||||
ln -sf sio_open.3 ${DESTDIR}${MAN3_DIR}/sio_close.3
|
ln -sf sio_open.3 ${DESTDIR}${MAN3_DIR}/sio_close.3
|
||||||
ln -sf sio_open.3 ${DESTDIR}${MAN3_DIR}/sio_setpar.3
|
ln -sf sio_open.3 ${DESTDIR}${MAN3_DIR}/sio_setpar.3
|
||||||
|
@ -84,7 +85,7 @@ install:
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f ${DESTDIR}${INCLUDE_DIR}/sndio.h
|
rm -f ${DESTDIR}${INCLUDE_DIR}/sndio.h
|
||||||
cd ${DESTDIR}${LIB_DIR} && rm -f ${SO}
|
cd ${DESTDIR}${LIB_DIR} && rm -f ${SO} ${SO_LINK}
|
||||||
cd ${DESTDIR}${MAN3_DIR} && rm -f ${MAN3}
|
cd ${DESTDIR}${MAN3_DIR} && rm -f ${MAN3}
|
||||||
cd ${DESTDIR}${MAN7_DIR} && rm -f ${MAN7}
|
cd ${DESTDIR}${MAN7_DIR} && rm -f ${MAN7}
|
||||||
|
|
||||||
|
@ -100,16 +101,16 @@ clean:
|
||||||
OBJS = debug.o aucat.o \
|
OBJS = debug.o aucat.o \
|
||||||
mio.o mio_rmidi.o mio_alsa.o mio_aucat.o \
|
mio.o mio_rmidi.o mio_alsa.o mio_aucat.o \
|
||||||
sio.o sio_alsa.o sio_aucat.o sio_oss.o sio_sun.o \
|
sio.o sio_alsa.o sio_aucat.o sio_oss.o sio_sun.o \
|
||||||
issetugid.o strlcat.o strlcpy.o strtonum.o
|
issetugid.o strlcat.o strlcpy.o strtonum.o clock_gettime.o
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
${CC} ${CFLAGS} ${SO_CFLAGS} -I. ${INCLUDE} ${DEFS} -o $@ -c $<
|
${CC} ${CFLAGS} ${SO_CFLAGS} -I. ${INCLUDE} ${DEFS} -o $@ -c $<
|
||||||
|
|
||||||
libsndio.so.${MAJ}.${MIN}: ${OBJS}
|
${SO}: ${OBJS}
|
||||||
${CC} ${LDFLAGS} ${SO_CFLAGS} ${SO_LDFLAGS} -o libsndio.so.${MAJ}.${MIN} ${OBJS} ${LDADD}
|
${CC} ${LDFLAGS} ${SO_CFLAGS} ${SO_LDFLAGS} -o ${SO} ${OBJS} ${LDADD}
|
||||||
|
|
||||||
libsndio.so:
|
${SO_LINK}:
|
||||||
ln -sf libsndio.so.${MAJ}.${MIN} libsndio.so
|
ln -sf ${SO} ${SO_LINK}
|
||||||
|
|
||||||
issetugid.o: ../bsd-compat/issetugid.c
|
issetugid.o: ../bsd-compat/issetugid.c
|
||||||
${CC} ${CFLAGS} ${SO_CFLAGS} ${INCLUDE} ${DEFS} -c -o issetugid.o ../bsd-compat/issetugid.c
|
${CC} ${CFLAGS} ${SO_CFLAGS} ${INCLUDE} ${DEFS} -c -o issetugid.o ../bsd-compat/issetugid.c
|
||||||
|
@ -123,6 +124,9 @@ strlcpy.o: ../bsd-compat/strlcpy.c
|
||||||
strtonum.o: ../bsd-compat/strtonum.c
|
strtonum.o: ../bsd-compat/strtonum.c
|
||||||
${CC} ${CFLAGS} ${SO_CFLAGS} ${INCLUDE} ${DEFS} -c -o strtonum.o ../bsd-compat/strtonum.c
|
${CC} ${CFLAGS} ${SO_CFLAGS} ${INCLUDE} ${DEFS} -c -o strtonum.o ../bsd-compat/strtonum.c
|
||||||
|
|
||||||
|
clock_gettime.o: ../bsd-compat/clock_gettime.c
|
||||||
|
${CC} ${CFLAGS} ${SO_CFLAGS} ${INCLUDE} ${DEFS} -c -o clock_gettime.o ../bsd-compat/clock_gettime.c
|
||||||
|
|
||||||
aucat.o: aucat.c aucat.h amsg.h debug.h \
|
aucat.o: aucat.c aucat.h amsg.h debug.h \
|
||||||
../bsd-compat/bsd-compat.h
|
../bsd-compat/bsd-compat.h
|
||||||
debug.o: debug.c debug.h ../bsd-compat/bsd-compat.h
|
debug.o: debug.c debug.h ../bsd-compat/bsd-compat.h
|
||||||
|
|
|
@ -342,6 +342,25 @@ done:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
socket_cloexec(int f, int t, int p)
|
||||||
|
{
|
||||||
|
#ifdef SOCK_CLOEXEC
|
||||||
|
return socket(f, t | SOCK_CLOEXEC, p);
|
||||||
|
#else
|
||||||
|
int s;
|
||||||
|
|
||||||
|
s = socket(f, t, p);
|
||||||
|
if (s < 0)
|
||||||
|
return -1;
|
||||||
|
if (fcntl(s, F_SETFL, FD_CLOEXEC) < 0) {
|
||||||
|
close(s);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
aucat_connect_tcp(struct aucat *hdl, char *host, unsigned int unit)
|
aucat_connect_tcp(struct aucat *hdl, char *host, unsigned int unit)
|
||||||
{
|
{
|
||||||
|
@ -360,7 +379,7 @@ aucat_connect_tcp(struct aucat *hdl, char *host, unsigned int unit)
|
||||||
}
|
}
|
||||||
s = -1;
|
s = -1;
|
||||||
for (ai = ailist; ai != NULL; ai = ai->ai_next) {
|
for (ai = ailist; ai != NULL; ai = ai->ai_next) {
|
||||||
s = socket(ai->ai_family, ai->ai_socktype | SOCK_CLOEXEC,
|
s = socket_cloexec(ai->ai_family, ai->ai_socktype,
|
||||||
ai->ai_protocol);
|
ai->ai_protocol);
|
||||||
if (s < 0) {
|
if (s < 0) {
|
||||||
DPERROR("socket");
|
DPERROR("socket");
|
||||||
|
@ -402,7 +421,7 @@ aucat_connect_un(struct aucat *hdl, unsigned int unit)
|
||||||
snprintf(ca.sun_path, sizeof(ca.sun_path),
|
snprintf(ca.sun_path, sizeof(ca.sun_path),
|
||||||
SOCKPATH_DIR "-%u/" SOCKPATH_FILE "%u", uid, unit);
|
SOCKPATH_DIR "-%u/" SOCKPATH_FILE "%u", uid, unit);
|
||||||
ca.sun_family = AF_UNIX;
|
ca.sun_family = AF_UNIX;
|
||||||
s = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
s = socket_cloexec(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (s < 0)
|
if (s < 0)
|
||||||
return 0;
|
return 0;
|
||||||
while (connect(s, (struct sockaddr *)&ca, len) < 0) {
|
while (connect(s, (struct sockaddr *)&ca, len) < 0) {
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include "bsd-compat.h"
|
||||||
|
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
Loading…
Reference in New Issue