Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Minishell-42
Path: blob/main/execution/my_mess/pwd.c
1407 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* pwd.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: ssabbaji <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/09/13 14:15:23 by ssabbaji #+# #+# */
9
/* Updated: 2022/10/07 12:53:26 by ssabbaji ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "../../minishell.h"
14
15
int my_pwd(t_data *data, t_cmd *lst_cmd)
16
{
17
char *cwd;
18
19
(void)data;
20
if (lst_cmd->cmd[0])
21
{
22
cwd = getcwd(NULL, 256);
23
if (cwd == NULL)
24
{
25
cwd = custom_getenv("PWD", data->lst_env);
26
if (!cwd)
27
cwd = getenv("PWD");
28
printf("%s\n", cwd);
29
}
30
else
31
{
32
printf("%s\n", cwd);
33
free(cwd);
34
}
35
}
36
return (0);
37
}
38
39