Message ID | 20171116091559.5595-1-zajec5@gmail.com |
---|---|
State | Accepted |
Headers | show |
Series | [LEDE-DEV,1/4] otrx: drop unused otrx_create_parse_options function | expand |
On Thu, 2017-11-16 at 10:15 +0100, Rafał Miłecki wrote: > From: Rafał Miłecki <rafal@milecki.pl> > > Signed-off-by: Rafał Miłecki <rafal@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; > } why not use %m? eg: fprintf(stderr, "Couldn't open %s: %m\n", trx_path) >
On Thu, 2017-11-16 at 10:15 +0100, Rafał Miłecki wrote: > From: Rafał Miłecki <rafal@milecki.pl> > > A "free" call was missing after allocating a buffer. > > Signed-off-by: Rafał Miłecki <rafal@milecki.pl> > --- > package/utils/otrx/src/otrx.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/package/utils/otrx/src/otrx.c > b/package/utils/otrx/src/otrx.c > index 1c3ffd915b..ac39fefc06 100644 > --- a/package/utils/otrx/src/otrx.c > +++ b/package/utils/otrx/src/otrx.c > @@ -266,9 +266,12 @@ static ssize_t otrx_create_append_zeros(FILE > *trx, size_t length) { > > if (fwrite(buf, 1, length, trx) != length) { > fprintf(stderr, "Couldn't write %zu B to %s\n", > length, trx_path); > + free(buf); > return -EIO; > } > > + free(buf); alternatively, could do unsigned int l = fwrite(buf, 1, length, trx); free(buf); if (l != length) { ... no real difference. > + > return length; > } >
diff --git a/package/utils/otrx/src/otrx.c b/package/utils/otrx/src/otrx.c index add111aa61..3b7cf04859 100644 --- a/package/utils/otrx/src/otrx.c +++ b/package/utils/otrx/src/otrx.c @@ -228,9 +228,6 @@ out: * Create **************************************************/ -static void otrx_create_parse_options(int argc, char **argv) { -} - static ssize_t otrx_create_append_file(FILE *trx, const char *in_path) { FILE *in; size_t bytes; @@ -334,9 +331,6 @@ static int otrx_create(int argc, char **argv) { } trx_path = argv[2]; - optind = 3; - otrx_create_parse_options(argc, argv); - trx = fopen(trx_path, "w+"); if (!trx) { fprintf(stderr, "Couldn't open %s\n", trx_path);