]> git.alsa-project.org Git - alsa-oss.git/commitdiff
oss-redir: Cleanup open/close code
authorTakashi Iwai <tiwai@suse.de>
Wed, 9 Sep 2026 10:08:36 +0000 (12:08 +0200)
committerTakashi Iwai <tiwai@suse.de>
Wed, 9 Sep 2026 15:09:37 +0000 (17:09 +0200)
Use unified open/close helpers for each hook.

Merely a code cleanup, and no functional changes.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
oss-redir/oss-redir.c

index 915af5d82e5d4af372576127efa329beeeff7245..1ec7532c94392e110dbf01207966aa737272da5f 100644 (file)
@@ -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)