summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher N. Hesse <raymanfx@gmail.com>2017-04-02 14:06:24 +0200
committerChristopher N. Hesse <raymanfx@gmail.com>2017-04-02 14:14:46 +0200
commitd483dd7898a67ab30a424f20eb17e0f748cac12d (patch)
tree38265d47039b05c128188c227af1dcce73973c5e
parent658f447ad3e23cbcc754e31601888468d86470fc (diff)
downloadandroid_hardware_samsung-d483dd7898a67ab30a424f20eb17e0f748cac12d.tar.gz
android_hardware_samsung-d483dd7898a67ab30a424f20eb17e0f748cac12d.tar.bz2
android_hardware_samsung-d483dd7898a67ab30a424f20eb17e0f748cac12d.zip
audience: Cleanup write_int()
Change-Id: Idfec2093c63a864d5f9d37353adbf6f8fc5d4fcd
-rw-r--r--audio/audience.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/audio/audience.c b/audio/audience.c
index 9b961be..61ed5d0 100644
--- a/audio/audience.c
+++ b/audio/audience.c
@@ -31,25 +31,32 @@
*
* @param path The absolute path string.
* @param value The Integer value to be written.
- * @return 0 on success, -1 or errno on error.
+ * @return 0 on success, errno on error.
*/
static int write_int(char const *path, const int value)
{
- int fd;
+ int fd, len, num_bytes;
+ int ret = 0;
+ char buffer[20];
- ALOGV("write_int: path %s, value %d", path, value);
fd = open(path, O_WRONLY);
+ if (fd < 0) {
+ ret = errno;
+ ALOGE("%s: failed to open %s (%s)", __func__, path, strerror(errno));
+ goto exit;
+ }
- if (fd >= 0) {
- char buffer[20];
- int bytes = sprintf(buffer, "%d\n", value);
- int amt = write(fd, buffer, bytes);
- close(fd);
- return amt == -1 ? -errno : 0;
- } else {
- ALOGE("write_int failed to open %s\n", path);
- return -errno;
+ num_bytes = sprintf(buffer, "%d", value);
+ len = write(fd, buffer, num_bytes);
+ if (len < 0) {
+ ret = errno;
+ ALOGE("%s: failed to write to %s (%s)", __func__, path, strerror(errno));
+ goto exit;
}
+
+exit:
+ close(fd);
+ return ret;
}
/*