[LEDE-DEV] [PATCH 3/4] otrx: print and return errno if fopen fails
Rafał Miłecki
zajec5 at gmail.com
Thu Nov 16 01:15:58 PST 2017
From: Rafał Miłecki <rafal at milecki.pl>
Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
package/utils/otrx/src/otrx.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/package/utils/otrx/src/otrx.c b/package/utils/otrx/src/otrx.c
index 0d99cd39e3..1c3ffd915b 100644
--- a/package/utils/otrx/src/otrx.c
+++ b/package/utils/otrx/src/otrx.c
@@ -170,8 +170,8 @@ static int otrx_check(int argc, char **argv) {
trx = fopen(trx_path, "r");
if (!trx) {
- fprintf(stderr, "Couldn't open %s\n", trx_path);
- err = -EACCES;
+ err = -errno;
+ fprintf(stderr, "Couldn't open %s: %d\n", trx_path, err);
goto out;
}
@@ -233,11 +233,13 @@ static ssize_t otrx_create_append_file(FILE *trx, const char *in_path) {
size_t bytes;
ssize_t length = 0;
uint8_t buf[1024];
+ int err;
in = fopen(in_path, "r");
if (!in) {
- fprintf(stderr, "Couldn't open %s\n", in_path);
- return -EACCES;
+ err = -errno;
+ fprintf(stderr, "Couldn't open %s: %d\n", in_path, err);
+ return err;
}
while ((bytes = fread(buf, 1, sizeof(buf), in)) > 0) {
@@ -333,8 +335,8 @@ static int otrx_create(int argc, char **argv) {
trx = fopen(trx_path, "w+");
if (!trx) {
- fprintf(stderr, "Couldn't open %s\n", trx_path);
- err = -EACCES;
+ err = -errno;
+ fprintf(stderr, "Couldn't open %s: %d\n", trx_path, err);
goto out;
}
fseek(trx, curr_offset, SEEK_SET);
@@ -449,8 +451,8 @@ static int otrx_extract_copy(FILE *trx, size_t offset, size_t length, char *out_
out = fopen(out_path, "w");
if (!out) {
- fprintf(stderr, "Couldn't open %s\n", out_path);
- err = -EACCES;
+ err = -errno;
+ fprintf(stderr, "Couldn't open %s: %d\n", out_path, err);
goto out;
}
@@ -505,8 +507,8 @@ static int otrx_extract(int argc, char **argv) {
trx = fopen(trx_path, "r");
if (!trx) {
- fprintf(stderr, "Couldn't open %s\n", trx_path);
- err = -EACCES;
+ err = -errno;
+ fprintf(stderr, "Couldn't open %s: %d\n", trx_path, err);
goto out;
}
--
2.11.0
More information about the Lede-dev
mailing list