7c20ded166acb7a4fd9e1ced0a62da79d742c219 — Drew DeVault 15 days ago c86e6d0
builtin/pwd: implement -L and -P

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.
1 files changed, 6 insertions(+), 7 deletions(-)

M builtin/pwd.c
M builtin/pwd.c => builtin/pwd.c +6 -7
@@ 1,4 1,5 @@ #define _POSIX_C_SOURCE 200809L
+ #include <assert.h>
  #include <mrsh/getopt.h>
  #include <mrsh/shell.h>
  #include <stdio.h>


@@ 14,25 15,23 @@ 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;
  }