2011-05-22 21:36:34 -04:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2011-05-24 07:56:38 -04:00
|
|
|
#include <libgen.h>
|
2011-05-22 21:36:34 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2013-03-05 15:35:55 -05:00
|
|
|
|
2011-05-22 21:36:34 -04:00
|
|
|
#include "util.h"
|
|
|
|
|
2012-05-15 08:32:56 -04:00
|
|
|
static void usage(void);
|
2012-04-23 09:50:47 -04:00
|
|
|
|
2013-03-05 15:35:55 -05:00
|
|
|
void
|
|
|
|
usage(void)
|
|
|
|
{
|
2015-02-01 13:26:49 -05:00
|
|
|
eprintf("usage: %s path [suffix]\n", argv0);
|
2013-03-05 15:35:55 -05:00
|
|
|
}
|
|
|
|
|
2011-05-22 21:36:34 -04:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2014-12-08 07:14:13 -05:00
|
|
|
char *p;
|
|
|
|
size_t off;
|
2012-04-23 09:50:47 -04:00
|
|
|
|
|
|
|
ARGBEGIN {
|
|
|
|
default:
|
2012-05-15 08:32:56 -04:00
|
|
|
usage();
|
2012-04-23 09:50:47 -04:00
|
|
|
} ARGEND;
|
|
|
|
|
2014-11-13 12:29:30 -05:00
|
|
|
if (argc < 1)
|
2012-05-15 08:32:56 -04:00
|
|
|
usage();
|
2012-04-23 09:50:47 -04:00
|
|
|
|
2014-12-08 07:14:13 -05:00
|
|
|
p = strlen(argv[0]) ? basename(argv[0]) : ".";
|
|
|
|
if (argc == 2 && *p != '/') {
|
|
|
|
if (strlen(argv[1]) < strlen(p)) {
|
|
|
|
off = strlen(p) - strlen(argv[1]);
|
|
|
|
if (strcmp(&p[off], argv[1]) == 0)
|
|
|
|
p[off] = '\0';
|
2014-12-03 18:37:34 -05:00
|
|
|
}
|
2011-05-22 21:36:34 -04:00
|
|
|
}
|
2014-12-08 07:14:13 -05:00
|
|
|
puts(p);
|
2014-10-02 18:46:04 -04:00
|
|
|
return 0;
|
2011-05-22 21:36:34 -04:00
|
|
|
}
|