summaryrefslogtreecommitdiffstats
path: root/src/s_init_next.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/s_init_next.c')
-rw-r--r--src/s_init_next.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/s_init_next.c b/src/s_init_next.c
index 3cc676d..1271b53 100644
--- a/src/s_init_next.c
+++ b/src/s_init_next.c
@@ -20,6 +20,7 @@
#endif
#include <paths.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include "b_export_next.h"
@@ -118,21 +119,30 @@ void s_set_cwd(char cwd[], t_msh *msh)
char fmt[PATH_MAX];
DIR *dir;
+ return ;
u_get_var_value(cwd, "$PWD", PATH_MAX, msh);
if (cwd[0] == C_NUL)
{
- getcwd(cwd, PATH_MAX);
- ft_sprintf(fmt, "%s=%s", "PWD", cwd);
- b_export_with_equals(fmt, msh);
+ if (getcwd(cwd, PATH_MAX) != NULL)
+ {
+ ft_sprintf(fmt, "%s=%s", "PWD", cwd);
+ b_export_with_equals(fmt, msh);
+ }
+ else
+ ft_dprintf(STDERR_FILENO, "minishell: %s\n", strerror(errno));
return ;
}
if ((dir = opendir(cwd)) != NULL)
closedir(dir);
else if (errno == ENOENT)
{
- getcwd(cwd, PATH_MAX);
- ft_sprintf(fmt, "%s=%s", "PWD", cwd);
- b_export_with_equals(fmt, msh);
+ if (getcwd(cwd, PATH_MAX) != NULL)
+ {
+ ft_sprintf(fmt, "%s=%s", "PWD", cwd);
+ b_export_with_equals(fmt, msh);
+ }
+ else
+ ft_dprintf(STDERR_FILENO, "minishell: %s\n", strerror(errno));
return ;
}
}