Discussion:
[TINYCOMPRESS][PATCH] crec: Fix error with opening file using O_CREAT
Richard Fitzgerald
2014-08-18 08:41:58 UTC
Permalink
From: Ammar Zahid Ali Syed <***@googlemail.com>

The code was not compiling when mode was not passed to open()
while using O_CREAT offset. Passed mode to the open() alongwith
O_CREAT to specify the attributes of file and fix compile issue.

Signed-off-by: Ammar Zahid Ali Syed <***@googlemail.com>
---
crec.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/crec.c b/crec.c
index 31703c5..e3f189f 100644
--- a/crec.c
+++ b/crec.c
@@ -66,6 +66,8 @@
#include <stdbool.h>
#include <getopt.h>
#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#define __force
#define __bitwise
#define __user
@@ -256,7 +258,7 @@ void capture_samples(char *name, unsigned int card, unsigned int device,
if (verbose)
printf("%s: entry, reading %u bytes\n", __func__, length);

- file = open(name, O_RDWR | O_CREAT);
+ file = open(name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
if (file == -1) {
fprintf(stderr, "Unable to open file '%s'\n", name);
exit(EXIT_FAILURE);
--
1.7.2.5
Vinod Koul
2014-10-17 09:23:34 UTC
Permalink
Post by Richard Fitzgerald
The code was not compiling when mode was not passed to open()
while using O_CREAT offset. Passed mode to the open() alongwith
O_CREAT to specify the attributes of file and fix compile issue.
Sorry this slipped thru earlier.

Applied, now

Thanks
--
~Vinod
Post by Richard Fitzgerald
---
crec.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/crec.c b/crec.c
index 31703c5..e3f189f 100644
--- a/crec.c
+++ b/crec.c
@@ -66,6 +66,8 @@
#include <stdbool.h>
#include <getopt.h>
#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#define __force
#define __bitwise
#define __user
@@ -256,7 +258,7 @@ void capture_samples(char *name, unsigned int card, unsigned int device,
if (verbose)
printf("%s: entry, reading %u bytes\n", __func__, length);
- file = open(name, O_RDWR | O_CREAT);
+ file = open(name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
if (file == -1) {
fprintf(stderr, "Unable to open file '%s'\n", name);
exit(EXIT_FAILURE);
--
1.7.2.5
--
Loading...