On Thu, 2017-11-16 at 10:15 +0100, Rafał Miłecki wrote:
> From: Rafał Miłecki <ra...@milecki.pl>
> 
> Signed-off-by: Rafał Miłecki <ra...@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)
>  

_______________________________________________
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev

Reply via email to