[alsa-devel] [PATCH] crecord: truncate file to remove content of existing file

Piotr Maziarz piotrx.maziarz at linux.intel.com
Tue Nov 26 11:18:03 CET 2019


Without O_TRUNC overwriting bigger file by smaller one doesn't wipe the
old file fully.

Signed-off-by: Piotr Maziarz <piotrx.maziarz at linux.intel.com>
Signed-off-by: Cezary Rojewski <cezary.rojewski at intel.com>
---
 src/utils/crecord.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/utils/crecord.c b/src/utils/crecord.c
index 12ad961..abaafea 100644
--- a/src/utils/crecord.c
+++ b/src/utils/crecord.c
@@ -323,7 +323,7 @@ static void capture_samples(char *name, unsigned int card, unsigned int device,
         if (!name) {
                 file = STDOUT_FILENO;
         } else {
-	        file = open(name, O_RDWR | O_CREAT,
+	        file = open(name, O_RDWR | O_CREAT | O_TRUNC,
 			    S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
 	        if (file == -1) {
 		       fprintf(stderr, "Unable to open file '%s'\n", name);
-- 
2.7.4



More information about the Alsa-devel mailing list