diff mbox series

[LEDE-DEV,1/4] otrx: drop unused otrx_create_parse_options function

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

Commit Message

Rafał Miłecki Nov. 16, 2017, 9:15 a.m. UTC
From: Rafał Miłecki <rafal@milecki.pl>

It was there in case of adding some "create" command options that should
be parsed before actually creating the output image. It seems we don't
need any at this point so let's drop this function for now.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 package/utils/otrx/src/otrx.c | 6 ------
 1 file changed, 6 deletions(-)

Comments

Rosen Penev Nov. 16, 2017, 10:28 a.m. UTC | #1
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)
>
Rosen Penev Nov. 16, 2017, 10:31 a.m. UTC | #2
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 mbox series

Patch

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);