Reintroduce functionality and error checks that were boneheadedly removed
in the previous commit. Pass me the pointy hat. PR: bin/21061
This commit is contained in:
parent
6b6821c771
commit
0de750cfc8
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=65508
@ -43,8 +43,10 @@ static const char copyright[] =
|
||||
static const char sccsid[] = "@(#)basename.c 8.4 (Berkeley) 5/4/95";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <err.h>
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void usage __P((void));
|
||||
@ -54,6 +56,7 @@ main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
char *p, *q;
|
||||
int ch;
|
||||
|
||||
while ((ch = getopt(argc, argv, "")) != -1)
|
||||
@ -68,7 +71,11 @@ main(argc, argv)
|
||||
if (argc != 1 && argc != 2)
|
||||
usage();
|
||||
|
||||
(void)printf("%s\n", basename(*argv));
|
||||
if ((p = basename(argv[0])) == NULL)
|
||||
err(1, "%s", argv[0]);
|
||||
if (*++argv && (q = strstr(p, *argv)) && strcmp(q, *argv) == 0)
|
||||
*q = '\0';
|
||||
(void)printf("%s\n", p);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,7 @@ static const char copyright[] =
|
||||
static const char sccsid[] = "@(#)dirname.c 8.4 (Berkeley) 5/4/95";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <err.h>
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@ -54,6 +55,7 @@ main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
char *p;
|
||||
int ch;
|
||||
|
||||
while ((ch = getopt(argc, argv, "")) != -1)
|
||||
@ -68,7 +70,9 @@ main(argc, argv)
|
||||
if (argc != 1)
|
||||
usage();
|
||||
|
||||
(void)printf("%s\n", dirname(*argv));
|
||||
if ((p = dirname(*argv)) == NULL)
|
||||
err(1, "%s", *argv);
|
||||
(void)printf("%s\n", p);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user