[hackers] [sbase] Audit pwd(1) || FRIGN

From: <git_AT_suckless.org>
Date: Wed, 4 Mar 2015 19:52:49 +0100 (CET)

commit 750974fa669bb22b893afe963a791bc03806351d
Author: FRIGN <dev_AT_frign.de>
Date: Tue Mar 3 17:24:14 2015 +0100

    Audit pwd(1)
    
    Nothing special
    1) Update manpage to current style.
    2) Reorder functions
    3) Logical trickery in getpwd()

diff --git a/README b/README
index a88478b..b1d55a3 100644
--- a/README
+++ b/README
_AT_@ -54,7 +54,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
 #* paste yes none
 =*| printenv non-posix none
 #* printf yes none
-=* pwd yes none
+=*| pwd yes none
 = readlink non-posix none
 =* renice yes none
 =*| rm yes none (-i)
diff --git a/pwd.1 b/pwd.1
index aa0f3f0..a7116c6 100644
--- a/pwd.1
+++ b/pwd.1
_AT_@ -1,4 +1,4 @@
-.Dd November 23, 2014
+.Dd March 3, 2015
 .Dt PWD 1
 .Os sbase
 .Sh NAME
_AT_@ -13,7 +13,7 @@ prints the path of the current working directory.
 .Sh OPTIONS
 .Bl -tag -width Ds
 .It Fl L
-Logical path, uses $PWD (default).
+Logical path, uses $PWD. This is the default.
 .It Fl P
 Physical path, avoids all symlinks.
 .El
diff --git a/pwd.c b/pwd.c
index d721cde..d31eec1 100644
--- a/pwd.c
+++ b/pwd.c
_AT_@ -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)
_AT_@ -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;
-}
Received on Wed Mar 04 2015 - 19:52:49 CET

This archive was generated by hypermail 2.3.0 : Wed Mar 04 2015 - 20:00:17 CET