lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9d7c4f95d6ab5ac9eed77026ab0abcc420587f91.1755436239.git.akhilesh@ee.iitb.ac.in>
Date: Sun, 17 Aug 2025 18:54:18 +0530
From: Akhilesh Patil <akhilesh@...iitb.ac.in>
To: skhan@...uxfoundation.org, gregkh@...uxfoundation.org,
	akpm@...ux-foundation.org, sj@...nel.org, dakr@...nel.org,
	mic@...ikod.net, masahiroy@...nel.org, corbet@....net,
	clemens@...isch.de
Cc: linux-kernel@...r.kernel.org, akhileshpatilvnit@...il.com
Subject: [PATCH 1/2] samples: timers: hpet_example: Improve argument parsing

Improve user experience by adding helper text while argument parsing.
Print format of the command line arguments for the program along
with example invocation and supported commands.
Define and use ARRAY_SIZE() macro to iterate over command array to
improve readability of the code.

Print as below upon incorrect invocation:
$ ./hpet_example

-hpet: requires command
Format: hpet_example <command> </dev/device_name>
Supported commands:
        open-close
        info
        poll
        fasync

Example: $ ./hpet_example info /dev/hpet

Signed-off-by: Akhilesh Patil <akhilesh@...iitb.ac.in>
---
 samples/timers/hpet_example.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/samples/timers/hpet_example.c b/samples/timers/hpet_example.c
index f1cb622f6ec0..59474c7be576 100644
--- a/samples/timers/hpet_example.c
+++ b/samples/timers/hpet_example.c
@@ -25,6 +25,8 @@ extern void hpet_read(int, const char **);
 #include <sys/poll.h>
 #include <sys/ioctl.h>
 
+#define ARRAY_SIZE(x)	(sizeof(x) / sizeof(x[0]))
+
 struct hpet_command {
 	char		*command;
 	void		(*func)(int argc, const char ** argv);
@@ -56,12 +58,17 @@ main(int argc, const char ** argv)
 	argv++;
 
 	if (!argc) {
-		fprintf(stderr, "-hpet: requires command\n");
+		fprintf(stderr, "-hpet: requires command\n"
+			"Format: hpet_example <command> </dev/device_name>\n");
+		fprintf(stderr, "Supported commands:\n");
+		for (i = 0; i < ARRAY_SIZE(hpet_command); i++)
+			fprintf(stderr, "\t%s\n", hpet_command[i].command);
+		fprintf(stderr, "\nExample: $ ./hpet_example info /dev/hpet\n");
 		return -1;
 	}
 
 
-	for (i = 0; i < (sizeof (hpet_command) / sizeof (hpet_command[0])); i++)
+	for (i = 0; i < ARRAY_SIZE(hpet_command); i++)
 		if (!strcmp(argv[0], hpet_command[i].command)) {
 			argc--;
 			argv++;
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ