Fixing zero-bye append in readlink. Thanks, Willem van de Krol
This commit is contained in:
parent
18712b2032
commit
7adf4f380a
@ -20,6 +20,7 @@ main(int argc, char *argv[])
|
|||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
bool nflag = false;
|
bool nflag = false;
|
||||||
bool fflag = false;
|
bool fflag = false;
|
||||||
|
ssize_t n;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'f':
|
case 'f':
|
||||||
@ -42,8 +43,9 @@ main(int argc, char *argv[])
|
|||||||
if (realpath(argv[0], buf) == NULL)
|
if (realpath(argv[0], buf) == NULL)
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
if (readlink(argv[0], buf, sizeof(buf)) < 0)
|
if ((n = readlink(argv[0], buf, sizeof(buf) - 1)) < 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
buf[n] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s", buf);
|
printf("%s", buf);
|
||||||
|
Loading…
Reference in New Issue
Block a user