summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rw-r--r--bin/Kbuild1
-rwxr-xr-xbin/clear/clearbin760 -> 0 bytes
-rwxr-xr-xbin/echo/echobin51872 -> 0 bytes
-rwxr-xr-xbin/false/falsebin616 -> 0 bytes
-rwxr-xr-xbin/free/freebin52936 -> 0 bytes
-rw-r--r--bin/pwd/Kbuild3
-rw-r--r--bin/pwd/pwd.c63
-rwxr-xr-xbin/sync/syncbin608 -> 0 bytes
-rwxr-xr-xbin/true/truebin616 -> 0 bytes
9 files changed, 67 insertions, 0 deletions
diff --git a/bin/Kbuild b/bin/Kbuild
index 6e675c38..4a96c667 100644
--- a/bin/Kbuild
+++ b/bin/Kbuild
@@ -3,5 +3,6 @@ obj-y += echo/
obj-y += false/
obj-y += free/
obj-y += gzip/
+obj-y += pwd/
obj-y += sync/
obj-y += true/
diff --git a/bin/clear/clear b/bin/clear/clear
deleted file mode 100755
index 27b775a0..00000000
--- a/bin/clear/clear
+++ /dev/null
Binary files differ
diff --git a/bin/echo/echo b/bin/echo/echo
deleted file mode 100755
index 95ff666c..00000000
--- a/bin/echo/echo
+++ /dev/null
Binary files differ
diff --git a/bin/false/false b/bin/false/false
deleted file mode 100755
index 627a3e2d..00000000
--- a/bin/false/false
+++ /dev/null
Binary files differ
diff --git a/bin/free/free b/bin/free/free
deleted file mode 100755
index 31c93e2f..00000000
--- a/bin/free/free
+++ /dev/null
Binary files differ
diff --git a/bin/pwd/Kbuild b/bin/pwd/Kbuild
new file mode 100644
index 00000000..7abb0973
--- /dev/null
+++ b/bin/pwd/Kbuild
@@ -0,0 +1,3 @@
+bin-y := pwd
+obj-y += pwd.o
+libs-y += $(srctree)/lib/libc/libc.a
diff --git a/bin/pwd/pwd.c b/bin/pwd/pwd.c
new file mode 100644
index 00000000..564b22e7
--- /dev/null
+++ b/bin/pwd/pwd.c
@@ -0,0 +1,63 @@
+#include <err.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/uio.h>
+#include <stdio.h>
+#include <unistd.h>
+
+int main(int argc, char **argv)
+{
+ const char *out = NULL;
+ struct iovec iov[2];
+ char opt, mode = 'L';
+ char cwd[PATH_MAX];
+
+ while ((opt = getopt(argc, argv, "")) != -1) {
+ switch (opt) {
+ case 'L':
+ case 'P':
+ mode = opt;
+ break;
+ default:
+ write(STDERR_FILENO, "usage: pwd [-L|-P]\n", 20);
+ return 1;
+ }
+ }
+
+ if (getcwd(cwd, sizeof(cwd)) == NULL) {
+ perror("pwd: getcwd");
+ return 1;
+ }
+
+ if (mode == 'L') {
+ const char *pwd;
+ struct stat cst, pst;
+
+ if ((pwd = getenv("PWD")) == NULL || *pwd != '/' ||
+ stat(pwd, &pst) < 0) {
+ out = cwd;
+ }
+
+ if (stat(cwd, &cst) < 0) {
+ perror("pwd: stat");
+ }
+
+ out = (pst.st_dev == cst.st_dev && pst.st_ino == cst.st_ino) ?
+ pwd :
+ cwd;
+ }
+
+ iov[0].iov_base = (char *)out;
+ iov[0].iov_len = strlen(out);
+
+ iov[1].iov_base = "\n";
+ iov[1].iov_len = 1;
+
+ if (writev(STDOUT_FILENO, iov, 2) < 0) {
+ err(1, "pwd");
+ }
+
+ return 0;
+}
diff --git a/bin/sync/sync b/bin/sync/sync
deleted file mode 100755
index 95965cdc..00000000
--- a/bin/sync/sync
+++ /dev/null
Binary files differ
diff --git a/bin/true/true b/bin/true/true
deleted file mode 100755
index 8f690cd7..00000000
--- a/bin/true/true
+++ /dev/null
Binary files differ