diff --git a/alsactl/alsactl.c b/alsactl/alsactl.c index ae73715..2851441 100644 --- a/alsactl/alsactl.c +++ b/alsactl/alsactl.c @@ -30,6 +30,7 @@ #include #include #include "alsactl.h" +#include "os_compat.h" #ifndef SYS_ASOUND_DIR #define SYS_ASOUND_DIR "/var/lib/alsa" diff --git a/alsaloop/alsaloop.c b/alsaloop/alsaloop.c index f5f2e37..e0f8642 100644 --- a/alsaloop/alsaloop.c +++ b/alsaloop/alsaloop.c @@ -33,6 +33,7 @@ #include #include #include "alsaloop.h" +#include "os_compat.h" struct loopback_thread { int threaded; diff --git a/alsaloop/control.c b/alsaloop/control.c index cf5693b..ba891fd 100644 --- a/alsaloop/control.c +++ b/alsaloop/control.c @@ -24,7 +24,9 @@ #include #include #include +#include #include "alsaloop.h" +#include "os_compat.h" static char *id_str(snd_ctl_elem_id_t *id) { diff --git a/alsaloop/pcmjob.c b/alsaloop/pcmjob.c index ef0c3dd..2df7bbd 100644 --- a/alsaloop/pcmjob.c +++ b/alsaloop/pcmjob.c @@ -33,6 +33,7 @@ #include #include #include "alsaloop.h" +#include "os_compat.h" #define XRUN_PROFILE_UNKNOWN (-10000000) diff --git a/amidi/amidi.c b/amidi/amidi.c index b7eebdf..ae2143c 100644 --- a/amidi/amidi.c +++ b/amidi/amidi.c @@ -85,7 +85,9 @@ static void usage(void) "-T, --timestamp=... adds a timestamp in front of each dumped message\n" " realtime\n" " monotonic\n" +#ifdef CLOCK_MONOTONIC_RAW " raw\n" +#endif "-t, --timeout=seconds exits when no data has been received\n" " for the specified duration\n" "-a, --active-sensing include active sensing bytes\n" @@ -534,8 +536,10 @@ int main(int argc, char *argv[]) cid = CLOCK_REALTIME; else if (strcasecmp(optarg, "monotonic") == 0) cid = CLOCK_MONOTONIC; +#ifdef CLOCK_MONOTONIC_RAW else if (strcasecmp(optarg, "raw") == 0) cid = CLOCK_MONOTONIC_RAW; +#endif else error("Clock type not known"); break; diff --git a/aplay/aplay.c b/aplay/aplay.c index 6c4c67b..d6b2e80 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -29,7 +29,9 @@ #define _GNU_SOURCE #include "aconfig.h" #include +#if HAVE_MALLOC_H #include +#endif #include #include #include @@ -53,6 +55,7 @@ #include "gettext.h" #include "formats.h" #include "version.h" +#include "os_compat.h" #define ABS(a) (a) < 0 ? -(a) : (a) diff --git a/aplay/formats.h b/aplay/formats.h index ac0a2b0..093ab80 100644 --- a/aplay/formats.h +++ b/aplay/formats.h @@ -1,8 +1,7 @@ #ifndef FORMATS_H #define FORMATS_H 1 -#include -#include +#include "bswap.h" /* Definitions for .VOC files */ diff --git a/axfer/container.h b/axfer/container.h index f6ce689..8f7ab2a 100644 --- a/axfer/container.h +++ b/axfer/container.h @@ -17,6 +17,8 @@ #include +#include "os_compat.h" + enum container_type { CONTAINER_TYPE_PARSER = 0, CONTAINER_TYPE_BUILDER, diff --git a/bat/alsa.c b/bat/alsa.c index 0d0af0d..f0adbc3 100644 --- a/bat/alsa.c +++ b/bat/alsa.c @@ -28,6 +28,7 @@ #include "common.h" #include "alsa.h" #include "latencytest.h" +#include "os_compat.h" struct pcm_container { snd_pcm_t *handle; diff --git a/configure.ac b/configure.ac index de51b78..d3cd904 100644 --- a/configure.ac +++ b/configure.ac @@ -28,7 +28,7 @@ AC_CHECK_FUNC([snd_ctl_elem_add_enumerated], fi -AC_CHECK_HEADERS([dlfcn.h]) +AC_CHECK_HEADERS([dlfcn.h malloc.h]) dnl Check components AC_CHECK_HEADERS([alsa/pcm.h], [have_pcm="yes"], [have_pcm="no"], diff --git a/include/bswap.h b/include/bswap.h new file mode 100644 index 0000000..e590124 --- /dev/null +++ b/include/bswap.h @@ -0,0 +1,44 @@ +/* + * ALSA lib - compatibility header for providing byte swapping macros + * Copyright (c) 2016 by Thomas Klausner + * + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __BSWAP_H +#define __BSWAP_H + +#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) +#include +#define bswap_16 bswap16 +#define bswap_32 bswap32 +#define bswap_64 bswap64 +#elif defined(__OpenBSD__) +#include +#define bswap_16 swap16 +#define bswap_32 swap32 +#define bswap_64 swap64 +#elif defined (__sun) +#include +#define bswap_16 BSWAP_16 +#define bswap_32 BSWAP_32 +#define bswap_64 BSWAP_64 +#else +#include +#endif + +#endif diff --git a/include/os_compat.h b/include/os_compat.h new file mode 100644 index 0000000..8d4f041 --- /dev/null +++ b/include/os_compat.h @@ -0,0 +1,43 @@ +/* + * ALSA lib - compatibility header for supporting various OSes + * Copyright (C) 2022 by Takayoshi SASANO + * + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __OS_COMPAT_H +#define __OS_COMPAT_H + +#ifndef ESTRPIPE +#define ESTRPIPE ESPIPE +#endif + +#ifndef ERESTART +#define ERESTART EINTR +#endif + +#ifndef SCHED_IDLE +#define SCHED_IDLE SCHED_OTHER +#endif + +#if defined(__OpenBSD__) +/* these functions in are not implemented */ +#define sched_getparam(pid, param) (-1) +#define sched_setscheduler(pid, policy, param) (-1) +#endif + +#endif diff --git a/speaker-test/speaker-test.c b/speaker-test/speaker-test.c index fd13d88..d08893a 100644 --- a/speaker-test/speaker-test.c +++ b/speaker-test/speaker-test.c @@ -44,7 +44,7 @@ #include #include #include -#include +#include "bswap.h" #include #define ALSA_PCM_NEW_HW_PARAMS_API @@ -56,6 +56,7 @@ #include "aconfig.h" #include "gettext.h" #include "version.h" +#include "os_compat.h" #ifdef ENABLE_NLS #include