~emersion/mrsh

ref: f4f0d8228a4e3bd11a4728b96dfa53e13f6f5296 mrsh/builtin/pwd.c -rw-r--r-- 444 bytes
f4f0d822 — delthas Implement pwd builtin 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
#include <mrsh/shell.h>
#include "builtin.h"

// usage: pwd [-L|-P]

int builtin_pwd(struct mrsh_state *state, int argc, char *argv[]) {
	// TODO `-P` and `-L`
	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 EXIT_FAILURE;
	}
	puts(pwd);
	return EXIT_SUCCESS;
}