~emersion/mrsh-dev

pwd: implement -L and -P v2 PROPOSED

Pushed with a minor edit to remove unneeded headers:

To git.sr.ht:~emersion/mrsh
   c86e6d08f435..7c20ded166ac  master -> master

Thanks!
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/~emersion/mrsh-dev/%3C20190907161013.18401-1-sir%40cmpwn.com%3E/mbox | git am -3
Learn more about email & git

[PATCH v2] pwd: implement -L and -P Export this patch

Note that this is mostly a placation, because mrsh manages the PWD
variable and ensures that none of the conditions -P or -L are meant to
address will occur.
---
 builtin/pwd.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/builtin/pwd.c b/builtin/pwd.c
index 370cf91..a12c6a6 100644
--- a/builtin/pwd.c
@@ -1,8 +1,12 @@
-#define _POSIX_C_SOURCE 200809L
+#define _XOPEN_SOURCE 500
+#include <assert.h>
+#include <limits.h>
 #include <mrsh/getopt.h>
 #include <mrsh/shell.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <strings.h>
 #include "builtin.h"
 
 static const char pwd_usage[] = "usage: pwd [-L|-P]\n";
@@ -14,25 +18,23 @@ int builtin_pwd(struct mrsh_state *state, int argc, char *argv[]) {
 		switch (opt) {
 		case 'L':
 		case 'P':
-			// TODO implement `-L` and `-P`
-			fprintf(stderr, "pwd: `-L` and `-P` not yet implemented\n");
-			return 1;
+			/* This space deliberately left blank */
+			break;
 		default:
 			fprintf(stderr, "pwd: unknown option -- %c\n", mrsh_optopt);
 			fprintf(stderr, pwd_usage);
 			return 1;
 		}
 	}
+
 	if (mrsh_optind < argc) {
 		fprintf(stderr, pwd_usage);
 		return 1;
 	}
 
 	const char *pwd = mrsh_env_get(state, "PWD", NULL);
-	if (pwd == NULL) {
-		fprintf(stderr, "pwd: Cannot return current directory as PWD was unset\n");
-		return 1;
-	}
+	assert(pwd != NULL);
 	puts(pwd);
+
 	return 0;
 }
-- 
2.23.0
Pushed with a minor edit to remove unneeded headers:

To git.sr.ht:~emersion/mrsh
   c86e6d08f435..7c20ded166ac  master -> master

Thanks!
View this thread in the archives