Audit pwd(1)
Nothing special 1) Update manpage to current style. 2) Reorder functions 3) Logical trickery in getpwd()
This commit is contained in:
parent
5d0abb92aa
commit
7cb966c170
2
README
2
README
|
@ -54,7 +54,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
|
||||||
#* paste yes none
|
#* paste yes none
|
||||||
=*| printenv non-posix none
|
=*| printenv non-posix none
|
||||||
#* printf yes none
|
#* printf yes none
|
||||||
=* pwd yes none
|
=*| pwd yes none
|
||||||
= readlink non-posix none
|
= readlink non-posix none
|
||||||
=* renice yes none
|
=* renice yes none
|
||||||
=*| rm yes none (-i)
|
=*| rm yes none (-i)
|
||||||
|
|
4
pwd.1
4
pwd.1
|
@ -1,4 +1,4 @@
|
||||||
.Dd November 23, 2014
|
.Dd March 3, 2015
|
||||||
.Dt PWD 1
|
.Dt PWD 1
|
||||||
.Os sbase
|
.Os sbase
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
@ -13,7 +13,7 @@ prints the path of the current working directory.
|
||||||
.Sh OPTIONS
|
.Sh OPTIONS
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Fl L
|
.It Fl L
|
||||||
Logical path, uses $PWD (default).
|
Logical path, uses $PWD. This is the default.
|
||||||
.It Fl P
|
.It Fl P
|
||||||
Physical path, avoids all symlinks.
|
Physical path, avoids all symlinks.
|
||||||
.El
|
.El
|
||||||
|
|
30
pwd.c
30
pwd.c
|
@ -6,7 +6,19 @@
|
||||||
|
|
||||||
#include "util.h"
|
#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
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
|
@ -34,19 +46,3 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
return 0;
|
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;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user