2013-06-15 14:17:57 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-11-13 17:29:30 +00:00
|
|
|
|
2013-06-15 14:17:57 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2013-08-15 09:55:21 +00:00
|
|
|
eprintf("usage: %s [-efmn] file\n", argv0);
|
2013-06-15 14:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char buf[PATH_MAX];
|
2014-11-13 20:24:47 +00:00
|
|
|
int nflag = 0;
|
|
|
|
int fflag = 0;
|
2013-07-09 23:40:28 +00:00
|
|
|
ssize_t n;
|
2013-06-15 14:17:57 +00:00
|
|
|
|
|
|
|
ARGBEGIN {
|
2013-08-15 09:55:21 +00:00
|
|
|
case 'e':
|
|
|
|
case 'm':
|
|
|
|
eprintf("not implemented\n");
|
2013-06-15 14:17:57 +00:00
|
|
|
case 'f':
|
2014-11-13 20:24:47 +00:00
|
|
|
fflag = 1;
|
2013-06-15 14:17:57 +00:00
|
|
|
break;
|
|
|
|
case 'n':
|
2014-11-13 20:24:47 +00:00
|
|
|
nflag = 1;
|
2013-06-15 14:17:57 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
|
|
|
if (argc != 1)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
if (strlen(argv[0]) > PATH_MAX - 1)
|
2014-12-04 12:14:20 +00:00
|
|
|
eprintf("path too long\n");
|
2013-06-15 14:17:57 +00:00
|
|
|
|
|
|
|
if (fflag) {
|
2014-11-13 21:16:29 +00:00
|
|
|
if (!realpath(argv[0], buf))
|
2013-06-15 14:17:57 +00:00
|
|
|
exit(1);
|
|
|
|
} else {
|
2013-07-09 23:40:28 +00:00
|
|
|
if ((n = readlink(argv[0], buf, sizeof(buf) - 1)) < 0)
|
2013-06-15 14:17:57 +00:00
|
|
|
exit(1);
|
2013-07-09 23:40:28 +00:00
|
|
|
buf[n] = '\0';
|
2013-06-15 14:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s", buf);
|
|
|
|
if (!nflag)
|
|
|
|
putchar('\n');
|
|
|
|
|
2014-10-02 22:46:04 +00:00
|
|
|
return 0;
|
2013-06-15 14:17:57 +00:00
|
|
|
}
|