From e8b7d78be313bec1d4bf218699470d3bb95db573 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Fri, 8 Jun 2012 22:11:39 +0200 Subject: [PATCH] spark: add (and use) proc_put() to audio.cpp Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/8ea51a9dfb61b5df1f22415a95c08f733c29f967 Author: Stefan Seyfried Date: 2012-06-08 (Fri, 08 Jun 2012) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- libspark/audio.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/libspark/audio.cpp b/libspark/audio.cpp index 5256c38..57a1236 100644 --- a/libspark/audio.cpp +++ b/libspark/audio.cpp @@ -17,6 +17,19 @@ cAudio * audioDecoder = NULL; +static int proc_put(const char *path, const char *value, const int len) +{ + int ret, ret2; + int pfd = open(path, O_WRONLY); + if (pfd < 0) + return pfd; + ret = write(pfd, value, len); + ret2 = close(pfd); + if (ret2 < 0) + return ret2; + return ret; +} + cAudio::cAudio(void *, void *, void *) { fd = -1; @@ -66,20 +79,15 @@ int cAudio::do_mute(bool enable, bool remember) Muted = enable; sprintf(str, "%d", Muted); - - int f = open("/proc/stb/audio/j1_mute", O_RDWR); - write(f, str, strlen(str)); - close(f); + proc_put("/proc/stb/audio/j1_mute", str, strlen(str)); if (!enable) { - f = open("/proc/stb/avs/0/volume", O_RDWR); + int f = open("/proc/stb/avs/0/volume", O_RDWR); read(f, str, 4); close(f); str[3] = '\0'; - f = open("/proc/stb/avs/0/volume", O_RDWR); - write(f, str, strlen(str)); - close(f); + proc_put("/proc/stb/avs/0/volume", str, strlen(str)); } return 0; } @@ -120,9 +128,7 @@ int cAudio::setVolume(unsigned int left, unsigned int right) char str[4]; sprintf(str, "%d", v); - int f = open("/proc/stb/avs/0/volume", O_RDWR); - write(f, str, strlen(str)); - close(f); + proc_put("/proc/stb/avs/0/volume", str, strlen(str)); return 0; }