diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2019-07-16 17:48:57 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2019-07-16 17:48:57 +0000 |
commit | 8798e1837dc91a0fa852b1d9196efc191a94eff4 (patch) | |
tree | 7af83ee896b97ebedefac6214ffae80c51a77c69 /regress | |
parent | 716390e11ca954de06a17e8487826770e28a5f61 (diff) |
Call stat(2) only once in realpath(3) userland reference implementation.
Diffstat (limited to 'regress')
-rw-r--r-- | regress/sys/kern/realpath/realpath3.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/regress/sys/kern/realpath/realpath3.c b/regress/sys/kern/realpath/realpath3.c index bd3728ee2ea..b4dea35b893 100644 --- a/regress/sys/kern/realpath/realpath3.c +++ b/regress/sys/kern/realpath/realpath3.c @@ -1,4 +1,4 @@ -/* $OpenBSD: realpath3.c,v 1.3 2019/07/15 16:05:04 bluhm Exp $ */ +/* $OpenBSD: realpath3.c,v 1.4 2019/07/16 17:48:56 bluhm Exp $ */ /* * Copyright (c) 2003 Constantin S. Svintsoff <kostik@iclub.nsu.ru> * @@ -77,6 +77,15 @@ realpath3(const char *path, char *resolved) if (stat(path, &sb) == -1) return (NULL); + /* + * POSIX demands ENOTDIR for non directories ending in a "/". + */ + if (!S_ISDIR(sb.st_mode) && strchr(path, '/') != NULL && + path[strlen(path) - 1] == '/') { + errno = ENOTDIR; + return (NULL); + } + serrno = errno; if (resolved == NULL) { @@ -233,16 +242,6 @@ realpath3(const char *path, char *resolved) } /* - * POSIX demands ENOTDIR for non directories ending in a "/". - */ - if (strchr(path, '/') != NULL && path[strlen(path) - 1] == '/') { - if (stat(resolved, &sb) != -1 && !S_ISDIR(sb.st_mode)) { - errno = ENOTDIR; - goto err; - } - } - - /* * Remove trailing slash except when the resolved pathname * is a single "/". */ |