Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Aug 2010 22:24:26 +0000 (UTC)
From:      Edwin Groothuis <edwin@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r212032 - head/usr.bin/ncal
Message-ID:  <201008302224.o7UMOQCi009610@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: edwin
Date: Mon Aug 30 22:24:26 2010
New Revision: 212032
URL: http://svn.freebsd.org/changeset/base/212032

Log:
  Use basename(3) to determine the name of the program.
  
  Submitted by:	Alexander Best <arundel@>

Modified:
  head/usr.bin/ncal/ncal.c

Modified: head/usr.bin/ncal/ncal.c
==============================================================================
--- head/usr.bin/ncal/ncal.c	Mon Aug 30 22:19:41 2010	(r212031)
+++ head/usr.bin/ncal/ncal.c	Mon Aug 30 22:24:26 2010	(r212032)
@@ -33,6 +33,7 @@ static const char rcsid[] =
 #include <ctype.h>
 #include <err.h>
 #include <langinfo.h>
+#include <libgen.h>
 #include <locale.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -245,9 +246,7 @@ main(int argc, char *argv[])
 	 * Get the filename portion of argv[0] and set flag_backward if
 	 * this program is called "cal".
 	 */
-	cp = strrchr(argv[0], '/');
-	cp = (cp == NULL) ? argv[0] : cp + 1;
-	if (strcmp("cal", cp) == 0)
+	if (strncmp(basename(argv[0]), "cal", strlen("cal")) == 0)
 		flag_backward = 1;
 
 	/* Set the switch date to United Kingdom if backwards compatible */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201008302224.o7UMOQCi009610>