[patch] rtprio/idprio should use basename(3) instead of acting on its own

Previous thread: [patch] have rtprio check that arguments are numeric; change atoi to strtol by Eitan Adler on Saturday, January 1, 2011 - 11:15 pm. (15 messages)

Next thread: [patch] should crunchgen use basename(3) instead of homebrew code? by Eitan Adler on Sunday, January 2, 2011 - 12:37 am. (3 messages)
From: Eitan Adler
Date: Sunday, January 2, 2011 - 12:18 am

Index: rtprio.c
===================================================================
--- rtprio.c	(revision 216884)
+++ rtprio.c	(working copy)
@@ -41,6 +41,7 @@

 #include <ctype.h>
 #include <err.h>
+#include <libgen.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -57,11 +58,7 @@
 	int     proc = 0;
 	struct rtprio rtp;

-	/* find basename */
-	if ((p = rindex(argv[0], '/')) == NULL)
-		p = argv[0];
-	else
-		++p;
+	p = basename(argv[0]);

 	if (!strcmp(p, "rtprio"))
 		rtp.type = RTP_PRIO_REALTIME;


-- 
Eitan Adler
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
From: Kostik Belousov
Date: Sunday, January 2, 2011 - 3:20 am

basename(3) does much more work that IMO not needed there.
rindex() use is a well-known pattern that is common for almost all
utilities that check the calling name.

I do not think it is worth the churn.
Previous thread: [patch] have rtprio check that arguments are numeric; change atoi to strtol by Eitan Adler on Saturday, January 1, 2011 - 11:15 pm. (15 messages)

Next thread: [patch] should crunchgen use basename(3) instead of homebrew code? by Eitan Adler on Sunday, January 2, 2011 - 12:37 am. (3 messages)