diff mbox series

[3/7] mmc-utils: lsmmc: Pass program name to usage function

Message ID 20250310055231.304728-4-avri.altman@sandisk.com
State New
Headers show
Series mmc-utils: lsmmc: Registers value as an argument | expand

Commit Message

Avri Altman March 10, 2025, 5:52 a.m. UTC
This commit updates the usage function to accept the program name as an
argument, allowing the usage message to display the correct program name
dynamically. This change improves the clarity and accuracy of the usage
message. This enhancement ensures that the usage message accurately
reflects the name of the register: cid, csd or scr, being read.

Signed-off-by: Avri Altman <avri.altman@sandisk.com>
---
 lsmmc.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/lsmmc.c b/lsmmc.c
index 468a533..ae30799 100644
--- a/lsmmc.c
+++ b/lsmmc.c
@@ -232,9 +232,9 @@  static struct ids_database mmc_database[] = {
 };
 
 /* Command line parsing functions */
-static void usage(void)
+static void usage(char *progname)
 {
-	printf("Usage: print mmc [-h] [-v] <device path ...>\n");
+	printf("Usage: %s [-h] [-v] <device path ...>\n", progname);
 	printf("\n");
 	printf("Options:\n");
 	printf("\t-h\tShow this help.\n");
@@ -248,7 +248,7 @@  static int parse_opts(int argc, char **argv, struct config *config)
 	while ((c = getopt(argc, argv, "hv")) != -1) {
 		switch (c) {
 		case 'h':
-			usage();
+			usage(argv[0]);
 			return -1;
 		case 'v':
 			config->verbose = true;
@@ -256,12 +256,12 @@  static int parse_opts(int argc, char **argv, struct config *config)
 		case '?':
 			fprintf(stderr,
 				"Unknown option '%c' encountered.\n\n", c);
-			usage();
+			usage(argv[0]);
 			return -1;
 		case ':':
 			fprintf(stderr,
 				"Argument for option '%c' missing.\n\n", c);
-			usage();
+			usage(argv[0]);
 			return -1;
 		default:
 			fprintf(stderr,
@@ -272,11 +272,12 @@  static int parse_opts(int argc, char **argv, struct config *config)
 
 	if (optind >= argc) {
 		fprintf(stderr, "Expected mmc directory arguments.\n\n");
-		usage();
+		usage(argv[0]);
 		return -1;
 	}
 
 	config->dir = strdup(argv[optind]);
+
 	return 0;
 }