~sircmpwn/ctools

Implemented pwd v5 PROPOSED

Pedro L. Ramos: 1
 Implemented pwd

 8 files changed, 105 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/ctools/patches/9025/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH v5] Implemented pwd Export this patch

---
I hope it is ok now.

 STATUS           |  2 +-
 doc/ctools.7.scd |  2 ++
 doc/meson.build  |  1 +
 doc/pwd.1.scd    | 35 +++++++++++++++++++++++++++++++++++
 meson.build      |  1 +
 src/pwd.c        | 40 ++++++++++++++++++++++++++++++++++++++++
 test/meson.build |  1 +
 test/pwd         | 24 ++++++++++++++++++++++++
 8 files changed, 105 insertions(+), 1 deletion(-)
 create mode 100644 doc/pwd.1.scd
 create mode 100644 src/pwd.c
 create mode 100644 test/pwd

diff --git a/STATUS b/STATUS
index d574963..b4cf480 100644
--- a/STATUS
+++ b/STATUS
@@ -101,7 +101,7 @@ T       pathchk
T       printf
    W   prs
T       ps
T       pwd
 D      pwd
    W   qalter
    W   qdel
    W   qhold
diff --git a/doc/ctools.7.scd b/doc/ctools.7.scd
index 13caa8c..f98cc8f 100644
--- a/doc/ctools.7.scd
+++ b/doc/ctools.7.scd
@@ -53,6 +53,8 @@ shell environment. These tools are used for tasks such as:
:  Invoke a command that ignores hangups
|  *nice*(1)
:  Run a process with an altered niceness value
|  *pwd*(1)
:  Prints current working directory
|  *rmdir*(1)
:  Remove directories
|  *sleep*(1)
diff --git a/doc/meson.build b/doc/meson.build
index 56bc8e1..17f3cc2 100644
--- a/doc/meson.build
+++ b/doc/meson.build
@@ -21,6 +21,7 @@ man_files = [
	'logname.1',
	'nice.1',
	'nohup.1',
	'pwd.1',
	'rmdir.1',
	'sleep.1',
	'tee.1',
diff --git a/doc/pwd.1.scd b/doc/pwd.1.scd
new file mode 100644
index 0000000..47d9034
--- /dev/null
+++ b/doc/pwd.1.scd
@@ -0,0 +1,35 @@
pwd(1) "ctools"

# NAME

pwd - prints current working directory.

# SYNOPSIS

*pwd* [ -L | -P ] 

# DESCRIPTION

Prints current working directory to stdout. 

# OPTIONS

*-L*
	This flag is implemented for POSIX compatibility and has no effect.	

*-P*
	This flag is implemented for POSIX compatibility and has no effect.	

# UNSPECIFIED BEHAVIOR

The POSIX standard specifies the -L and -P flags as having an effect on
the resolution of symlinks in preparing the pathname to print. However,
the ctools implementation of pwd always simply prints the value returned
from *getcwd*(3), regardless of any flags specified.

# DISCLAIMER

This command is part of ctools and is compatible with POSIX-1.2018, and may
optionally support XSI extensions. This man page is not intended to be a
complete reference, and where it disagrees with the specification, the
specification takes precedence.
diff --git a/meson.build b/meson.build
index 7724a2a..41c64f2 100644
--- a/meson.build
+++ b/meson.build
@@ -27,6 +27,7 @@ oneshots = [
	'logname',
	'nice', # Included in base but only effective under XSI
	'nohup',
	'pwd',
	'rmdir',
	'sleep',
	'tee',
diff --git a/src/pwd.c b/src/pwd.c
new file mode 100644
index 0000000..34d8071
--- /dev/null
+++ b/src/pwd.c
@@ -0,0 +1,40 @@
#include <getopt.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

static void
usage(void)
{
	fprintf(stderr, "usage: pwd [-L|-P]");
}

int
main(int argc, char *argv[])
{
	char *pwd = NULL;

	char opt;
	while ((opt = getopt(argc, argv, "LP")) != -1) {
		switch (opt) {
		case 'P':
			break;
		case 'L':
			break;
		default:
			usage();
			return 1;
		}
	}
	
	pwd = getcwd(pwd, 0);
	
	if (pwd == NULL) {
		return 1;
	}

	printf("%s\n", pwd);
	
	return 0;
}
diff --git a/test/meson.build b/test/meson.build
index d8d900a..271687b 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -16,6 +16,7 @@ test_files = [
	'logname',
	'nice',
	'nohup',
	'pwd',
	'rmdir',
	'sleep',
	'tee',
diff --git a/test/pwd b/test/pwd
new file mode 100644
index 0000000..de2f5c4
--- /dev/null
+++ b/test/pwd
@@ -0,0 +1,24 @@
#!/bin/sh
tool="pwd"
. "$HARNESS"

mkdir "$TMPDIR"/dir-f
ln -s "$TMPDIR"/dir-f "$TMPDIR"/dir-s

should_work() (
    cd "$TMPDIR/dir-f"
    ct="$(pwd)"
    [ "$ct" = "$TMPDIR/dir-f" ]
)

should_handle_symlink() (
    cd "$TMPDIR/dir-f"
    ct="$(pwd -L)"
    [ "$ct" = "$TMPDIR/dir-f" ]
)

should_resolve_symlink() (
    cd "$TMPDIR/dir-f"
    ct="$(pwd -P)"
    [ "$ct" = "$TMPDIR/dir-f" ]
)
-- 
2.23.0
Looks great, thanks!

To git.sr.ht:~sircmpwn/ctools
   cc69324..10cfd2d  master -> master