Audit pwd(1)

Nothing special
1) Update manpage to current style.
2) Reorder functions
3) Logical trickery in getpwd()
This commit is contained in:
FRIGN
2015-03-03 17:24:14 +01:00
parent 5d0abb92aa
commit 7cb966c170
3 changed files with 16 additions and 20 deletions

30
pwd.c
View File

@@ -6,7 +6,19 @@
#include "util.h"
static const char *getpwd(const char *cwd);
static const char *
getpwd(const char *cwd)
{
const char *pwd;
struct stat cst, pst;
if (!(pwd = getenv("PWD")) || pwd[0] != '/' || stat(pwd, &pst) < 0)
return cwd;
if (stat(cwd, &cst) < 0)
eprintf("stat %s:", cwd);
return (pst.st_dev == cst.st_dev && pst.st_ino == cst.st_ino) ? pwd : cwd;
}
static void
usage(void)
@@ -34,19 +46,3 @@ main(int argc, char *argv[])
return 0;
}
static const char *
getpwd(const char *cwd)
{
const char *pwd;
struct stat cst, pst;
if (!(pwd = getenv("PWD")) || pwd[0] != '/' || stat(pwd, &pst) < 0)
return cwd;
if (stat(cwd, &cst) < 0)
eprintf("stat %s:", cwd);
if (pst.st_dev == cst.st_dev && pst.st_ino == cst.st_ino)
return pwd;
else
return cwd;
}