From 7c6a36666089da85fe83cf0a93456f23831c891c Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Wed, 9 Sep 2026 12:08:36 +0200 Subject: [PATCH] oss-redir: Cleanup open/close code Use unified open/close helpers for each hook. Merely a code cleanup, and no functional changes. Signed-off-by: Takashi Iwai --- oss-redir/oss-redir.c | 77 +++++++++++-------------------------------- 1 file changed, 19 insertions(+), 58 deletions(-) diff --git a/oss-redir/oss-redir.c b/oss-redir/oss-redir.c index 915af5d..1ec7532 100644 --- a/oss-redir/oss-redir.c +++ b/oss-redir/oss-redir.c @@ -157,14 +157,15 @@ static inline void check_initialized(void) initialize(); } -int oss_pcm_open(const char *pathname, int flags, ...) +static int call_open(const char *pathname, int flags, + int (*__open)(const char *pathname, int flags)) { int result; check_initialized(); if (native_oss) return open(pathname, flags); - result = x_oss_pcm_open(pathname, flags); + result = __open(pathname, flags); if (result >= 0) { open_count++; } else { @@ -176,13 +177,13 @@ int oss_pcm_open(const char *pathname, int flags, ...) return result; } -int oss_pcm_close(int fd) +static int call_close(int fd, int (*__close)(int fd)) { int result; if (native_oss) return close(fd); - result = x_oss_pcm_close(fd); + result = __close(fd); if (--open_count) { dlclose(dl_handle); dl_handle = NULL; @@ -190,74 +191,34 @@ int oss_pcm_close(int fd) return result; } -int oss_mixer_open(const char *pathname, int flags, ...) +int oss_pcm_open(const char *pathname, int flags, ...) { - int result; + return call_open(pathname, flags, x_oss_pcm_open); +} - check_initialized(); - if (native_oss) - return open(pathname, flags); - result = x_oss_mixer_open(pathname, flags); - if (result >= 0) { - open_count++; - } else { - if (open_count == 0) { - dlclose(dl_handle); - dl_handle = NULL; - } - } - return result; +int oss_pcm_close(int fd) +{ + return call_close(fd, x_oss_pcm_close); } -int oss_mixer_close(int fd) +int oss_mixer_open(const char *pathname, int flags, ...) { - int result; + return call_open(pathname, flags, x_oss_mixer_open); +} - if (fd < 0) - return -EINVAL; - if (native_oss) - return close(fd); - result = x_oss_mixer_close(fd); - if (--open_count) { - dlclose(dl_handle); - dl_handle = NULL; - } - return result; +int oss_mixer_close(int fd) +{ + return call_close(fd, x_oss_mixer_close); } int oss_seq_open(const char *pathname, int flags, ...) { - int result; - - check_initialized(); - if (native_oss) - return open(pathname, flags); - result = x_oss_seq_open(pathname, flags); - if (result >= 0) { - open_count++; - } else { - if (open_count == 0) { - dlclose(dl_handle); - dl_handle = NULL; - } - } - return result; + return call_open(pathname, flags, x_oss_seq_open); } int oss_seq_close(int fd) { - int result; - - if (fd < 0) - return -EINVAL; - if (native_oss) - return close(fd); - result = x_oss_seq_close(fd); - if (--open_count) { - dlclose(dl_handle); - dl_handle = NULL; - } - return result; + return call_close(fd, x_oss_seq_close); } static void initialize(void) -- 2.52.0