-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuiltin_pwd.c
38 lines (35 loc) · 1.24 KB
/
builtin_pwd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtin_pwd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marlean <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/05 10:53:59 by hcolumbu #+# #+# */
/* Updated: 2022/06/17 13:51:32 by marlean ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int builtin_pwd(t_envp *envp_list)
{
char *pwd;
if (!envp_list)
return (1);
pwd = get_value_from_envp(envp_list, "PWD");
if (!pwd)
{
pwd = getcwd(NULL, 0);
if (!pwd)
{
if (chdir("..") == -1)
{
perror("Myshell 🐚: pwd: ");
return (1);
}
pwd = getcwd(NULL, 0);
}
}
ft_putendl_fd(pwd, 1);
free(pwd);
return (0);
}