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 <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#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];
|
|
|
|
bool nflag = false;
|
|
|
|
bool fflag = false;
|
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':
|
|
|
|
fflag = true;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
nflag = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
|
|
|
if (argc != 1)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
if (strlen(argv[0]) > PATH_MAX - 1)
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
if (fflag) {
|
|
|
|
if (realpath(argv[0], buf) == NULL)
|
|
|
|
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');
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|