diff mbox

[U-Boot,3/4] mkenvimage: Print program basename instead of whole path in usage()

Message ID 1323082526-2125-3-git-send-email-hkronsto@frequentis.com
State Changes Requested
Delegated to: Wolfgang Denk
Headers show

Commit Message

Horst Kronstorfer Dec. 5, 2011, 10:55 a.m. UTC
Signed-off-by: Horst Kronstorfer <hkronsto@frequentis.com>
---
 tools/mkenvimage.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

Comments

Wolfgang Denk Dec. 20, 2011, 10:53 p.m. UTC | #1
Dear Horst Kronstorfer,

In message <1323082526-2125-3-git-send-email-hkronsto@frequentis.com> you wrote:
> Signed-off-by: Horst Kronstorfer <hkronsto@frequentis.com>
> ---
>  tools/mkenvimage.c |   13 +++++++++----
>  1 files changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/mkenvimage.c b/tools/mkenvimage.c
> index 22d1b88..3e7f967 100644
> --- a/tools/mkenvimage.c
> +++ b/tools/mkenvimage.c
> @@ -79,6 +79,11 @@ int main(int argc, char **argv)
>  	struct stat txt_file_stat;
>  
>  	int fp, ep;
> +	const char *prg;
> +
> +	/* Parse program basename */
> +	prg = strrchr(argv[0], '/');
> +	prg = (prg) ? prg + 1 : argv[0];

Any reason for not using basename() here?


Best regards,

Wolfgang Denk
Wolfgang Denk Dec. 21, 2011, 10:49 a.m. UTC | #2
Dear KRONSTORFER Horst,

In message <024FE3275EF7814D9B07390F28C0832C63A240F5@vie196nt.frequentis.frq> you wrote:
>
> > > +	/* Parse program basename */
> > > +	prg = strrchr(argv[0], '/');
> > > +	prg = (prg) ? prg + 1 : argv[0];
> > 
> > Any reason for not using basename() here?
> 
> i'm just used to not using basename() ... do you want an updated patch?

Yes, please.  Using available standard functions is always better than
reinventing the wheel.

Best regards,

Wolfgang Denk
diff mbox

Patch

diff --git a/tools/mkenvimage.c b/tools/mkenvimage.c
index 22d1b88..3e7f967 100644
--- a/tools/mkenvimage.c
+++ b/tools/mkenvimage.c
@@ -79,6 +79,11 @@  int main(int argc, char **argv)
 	struct stat txt_file_stat;
 
 	int fp, ep;
+	const char *prg;
+
+	/* Parse program basename */
+	prg = strrchr(argv[0], '/');
+	prg = (prg) ? prg + 1 : argv[0];
 
 	/* Turn off getopt()'s internal error message */
 	opterr = 0;
@@ -107,16 +112,16 @@  int main(int argc, char **argv)
 			padbyte = strtol(optarg, NULL, 0);
 			break;
 		case 'h':
-			usage(argv[0]);
+			usage(prg);
 			return EXIT_SUCCESS;
 		case ':':
 			fprintf(stderr, "Missing argument for option -%c\n",
 				optopt);
-			usage(argv[0]);
+			usage(prg);
 			return EXIT_FAILURE;
 		default:
 			fprintf(stderr, "Wrong option -%c\n", optopt);
-			usage(argv[0]);
+			usage(prg);
 			return EXIT_FAILURE;
 		}
 	}
@@ -126,7 +131,7 @@  int main(int argc, char **argv)
 		fprintf(stderr,
 			"Please specify the size of the environment "
 			"partition.\n");
-		usage(argv[0]);
+		usage(prg);
 		return EXIT_FAILURE;
 	}