[alsa-devel] [PATCH 2/3] alsabat: fix fopen and messages

han.lu at intel.com han.lu at intel.com
Mon Mar 21 12:05:48 CET 2016


From: "Lu, Han" <han.lu at intel.com>

All files should be opened in either "rb" or "wb" in current
usage.
Remove incorrect and unneccesary prints.

Signed-off-by: Lu, Han <han.lu at intel.com>

diff --git a/bat/alsa.c b/bat/alsa.c
index 638012a..2540ab8 100644
--- a/bat/alsa.c
+++ b/bat/alsa.c
@@ -303,8 +303,8 @@ static int write_to_pcm_loop(struct pcm_container *sndpcm, struct bat *bat)
 		fp = fopen(bat->debugplay, "wb");
 		err = -errno;
 		if (fp == NULL) {
-			fprintf(bat->err, _("Cannot open file for capture: "));
-			fprintf(bat->err, _("%s %d\n"), bat->debugplay, err);
+			fprintf(bat->err, _("Cannot open file: %s %d\n"),
+					bat->debugplay, err);
 			return err;
 		}
 		/* leave space for wav header */
@@ -404,8 +404,7 @@ void *playback_alsa(struct bat *bat)
 		bat->fp = fopen(bat->playback.file, "rb");
 		err = -errno;
 		if (bat->fp == NULL) {
-			fprintf(bat->err, _("Cannot open file for capture: "));
-			fprintf(bat->err, _("%s %d\n"),
+			fprintf(bat->err, _("Cannot open file: %s %d\n"),
 					bat->playback.file, err);
 			retval_play = 1;
 			goto exit3;
@@ -545,10 +544,10 @@ void *record_alsa(struct bat *bat)
 	}
 
 	remove(bat->capture.file);
-	fp = fopen(bat->capture.file, "w+");
+	fp = fopen(bat->capture.file, "wb");
 	err = -errno;
 	if (fp == NULL) {
-		fprintf(bat->err, _("Cannot open file for capture: %s %d\n"),
+		fprintf(bat->err, _("Cannot open file: %s %d\n"),
 				bat->capture.file, err);
 		retval_record = 1;
 		goto exit3;
diff --git a/bat/analyze.c b/bat/analyze.c
index 63481fb..58781d6 100644
--- a/bat/analyze.c
+++ b/bat/analyze.c
@@ -296,7 +296,7 @@ int analyze_capture(struct bat *bat)
 	bat->fp = fopen(bat->capture.file, "rb");
 	err = -errno;
 	if (bat->fp == NULL) {
-		fprintf(bat->err, _("Cannot open file for capture: %s %d\n"),
+		fprintf(bat->err, _("Cannot open file: %s %d\n"),
 				bat->capture.file, err);
 		goto exit1;
 	}
diff --git a/bat/bat.c b/bat/bat.c
index 4821532..85a7282 100644
--- a/bat/bat.c
+++ b/bat/bat.c
@@ -469,8 +469,8 @@ static int bat_init(struct bat *bat)
 		bat->log = fopen(bat->logarg, "wb");
 		err = -errno;
 		if (bat->log == NULL) {
-			fprintf(bat->err, _("Cannot open file for capture:"));
-			fprintf(bat->err, _(" %s %d\n"), bat->logarg, err);
+			fprintf(bat->err, _("Cannot open file: %s %d\n"),
+					bat->logarg, err);
 			return err;
 		}
 		bat->err = bat->log;
@@ -533,8 +533,7 @@ static int bat_init(struct bat *bat)
 		bat->fp = fopen(bat->playback.file, "rb");
 		err = -errno;
 		if (bat->fp == NULL) {
-			fprintf(bat->err, _("Cannot open file for playback:"));
-			fprintf(bat->err, _(" %s %d\n"),
+			fprintf(bat->err, _("Cannot open file: %s %d\n"),
 					bat->playback.file, err);
 			return err;
 		}
-- 
2.5.0



More information about the Alsa-devel mailing list