realpath(3) should use PATH_MAX instead of MAXPATHLEN according to POSIX.
This also reverts the PATH_MAX -> MAXPATHLEN part of rev 1.3 of src/bin/realpath/realpath.c Requested by: imp Reviewed by: imp, bde
This commit is contained in:
parent
9bc01124e7
commit
de216a83c2
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=109331
@ -46,7 +46,7 @@ static void usage(void) __dead2;
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char buf[MAXPATHLEN];
|
char buf[PATH_MAX];
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
.In sys/param.h
|
.In sys/param.h
|
||||||
.In stdlib.h
|
.In stdlib.h
|
||||||
.Ft "char *"
|
.Ft "char *"
|
||||||
.Fn realpath "const char *pathname" "char resolved_path[MAXPATHLEN]"
|
.Fn realpath "const char *pathname" "char resolved_path[PATH_MAX]"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Fn realpath
|
.Fn realpath
|
||||||
@ -67,7 +67,7 @@ The
|
|||||||
argument
|
argument
|
||||||
.Em must
|
.Em must
|
||||||
refer to a buffer capable of storing at least
|
refer to a buffer capable of storing at least
|
||||||
.Dv MAXPATHLEN
|
.Dv PATH_MAX
|
||||||
characters.
|
characters.
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
|
@ -52,7 +52,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include "un-namespace.h"
|
#include "un-namespace.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* char *realpath(const char *path, char resolved_path[MAXPATHLEN]);
|
* char *realpath(const char *path, char resolved_path[PATH_MAX]);
|
||||||
*
|
*
|
||||||
* Find the real name of path, by removing all ".", ".." and symlink
|
* Find the real name of path, by removing all ".", ".." and symlink
|
||||||
* components. Returns (resolved) on success, or (NULL) on failure,
|
* components. Returns (resolved) on success, or (NULL) on failure,
|
||||||
@ -65,7 +65,7 @@ realpath(path, resolved)
|
|||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
int fd, n, rootd, serrno;
|
int fd, n, rootd, serrno;
|
||||||
char *p, *q, wbuf[MAXPATHLEN];
|
char *p, *q, wbuf[PATH_MAX];
|
||||||
int symlinks = 0;
|
int symlinks = 0;
|
||||||
|
|
||||||
/* Save the starting point. */
|
/* Save the starting point. */
|
||||||
@ -82,8 +82,8 @@ realpath(path, resolved)
|
|||||||
* if it is a directory, then change to that directory.
|
* if it is a directory, then change to that directory.
|
||||||
* get the current directory name and append the basename.
|
* get the current directory name and append the basename.
|
||||||
*/
|
*/
|
||||||
(void)strncpy(resolved, path, MAXPATHLEN - 1);
|
(void)strncpy(resolved, path, PATH_MAX - 1);
|
||||||
resolved[MAXPATHLEN - 1] = '\0';
|
resolved[PATH_MAX - 1] = '\0';
|
||||||
loop:
|
loop:
|
||||||
q = strrchr(resolved, '/');
|
q = strrchr(resolved, '/');
|
||||||
if (q != NULL) {
|
if (q != NULL) {
|
||||||
@ -109,7 +109,7 @@ realpath(path, resolved)
|
|||||||
errno = ELOOP;
|
errno = ELOOP;
|
||||||
goto err1;
|
goto err1;
|
||||||
}
|
}
|
||||||
n = readlink(p, resolved, MAXPATHLEN - 1);
|
n = readlink(p, resolved, PATH_MAX - 1);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
goto err1;
|
goto err1;
|
||||||
resolved[n] = '\0';
|
resolved[n] = '\0';
|
||||||
@ -127,7 +127,7 @@ realpath(path, resolved)
|
|||||||
* the current directory.
|
* the current directory.
|
||||||
*/
|
*/
|
||||||
(void)strcpy(wbuf, p);
|
(void)strcpy(wbuf, p);
|
||||||
if (getcwd(resolved, MAXPATHLEN) == 0)
|
if (getcwd(resolved, PATH_MAX) == 0)
|
||||||
goto err1;
|
goto err1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -140,7 +140,7 @@ realpath(path, resolved)
|
|||||||
rootd = 0;
|
rootd = 0;
|
||||||
|
|
||||||
if (*wbuf) {
|
if (*wbuf) {
|
||||||
if (strlen(resolved) + strlen(wbuf) + rootd + 1 > MAXPATHLEN) {
|
if (strlen(resolved) + strlen(wbuf) + rootd + 1 > PATH_MAX) {
|
||||||
errno = ENAMETOOLONG;
|
errno = ENAMETOOLONG;
|
||||||
goto err1;
|
goto err1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user