Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Minishell-42
Path: blob/main/execution/my_mess/cd_back.c
1407 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* cd_back.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: ssabbaji <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/09/23 16:27:12 by ssabbaji #+# #+# */
9
/* Updated: 2022/09/25 14:48:31 by ssabbaji ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "../../minishell.h"
14
15
int go_back_minus(t_data *data)
16
{
17
int exit_stat;
18
char *oldpwd;
19
20
oldpwd = custom_getenv("OLDPWD", data->lst_env);
21
exit_stat = chdir(oldpwd);
22
if (exit_stat)
23
{
24
free(oldpwd);
25
oldpwd = NULL;
26
return (ft_putstr_fd("OLDPWD not set\n", 2), 1);
27
}
28
printf("%s\n", getenv("OLDPWD"));
29
free(oldpwd);
30
oldpwd = NULL;
31
return (exit_stat);
32
}
33
34
void print_error(void)
35
{
36
printf("cd: error retrieving current directory:");
37
printf("getcwd:cannot access parent directories:");
38
printf(" No such file or directory\n");
39
}
40
41
int go_home(t_data *data, char *cwd)
42
{
43
int exit_stat;
44
char *home;
45
46
home = custom_getenv("HOME", data->lst_env);
47
exit_stat = chdir(home);
48
if (exit_stat)
49
{
50
free(cwd);
51
free(home);
52
cwd = NULL;
53
home = NULL;
54
ft_putstr_fd("HOME not set\n", 2);
55
return (1);
56
}
57
update_pwd(data, cwd);
58
free(cwd);
59
free(home);
60
home = NULL;
61
cwd = NULL;
62
return (exit_stat);
63
}
64
65