summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-12-12 18:19:38 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-12-12 18:19:38 +0100
commitb1267254008b75f3bfea5a9c47dee525e7da1860 (patch)
tree596db71105ce012b95c56bf61abf07b9df27f4c9
parentComment update (diff)
download42-minishell-b1267254008b75f3bfea5a9c47dee525e7da1860.tar.gz
42-minishell-b1267254008b75f3bfea5a9c47dee525e7da1860.tar.bz2
42-minishell-b1267254008b75f3bfea5a9c47dee525e7da1860.tar.xz
42-minishell-b1267254008b75f3bfea5a9c47dee525e7da1860.tar.zst
42-minishell-b1267254008b75f3bfea5a9c47dee525e7da1860.zip
Good
-rw-r--r--TODO.org1
-rw-r--r--src/m_funptr.c2
-rw-r--r--src/m_funptr.h2
-rw-r--r--src/s_init.c4
-rw-r--r--src/s_init_next.c22
5 files changed, 21 insertions, 10 deletions
diff --git a/TODO.org b/TODO.org
index 6ae8fef..6f2018b 100644
--- a/TODO.org
+++ b/TODO.org
@@ -58,6 +58,7 @@
** DONE macOS compliancy
** DONE No fixed int
CLOSED: [2020-10-28 Wed 01:40]
+** TODO export qwe="'123'"; echo $qwe <--- show squotes like bash
* Stuff to add
** DONE builtins to pipes
diff --git a/src/m_funptr.c b/src/m_funptr.c
index 2ae09f6..bd2e777 100644
--- a/src/m_funptr.c
+++ b/src/m_funptr.c
@@ -19,7 +19,7 @@
#include "m_funptr.h"
#include "s_struct.h"
-void init_buptr(t_msh *msh)
+void m_init_buptr(t_msh *msh)
{
msh->bu_ptr[B_ID_ECHO] = b_echo;
msh->bu_ptr[B_ID_CD] = b_cd;
diff --git a/src/m_funptr.h b/src/m_funptr.h
index f5375b9..a1d5f69 100644
--- a/src/m_funptr.h
+++ b/src/m_funptr.h
@@ -15,6 +15,6 @@
# include "s_struct.h"
-void init_buptr(t_msh *msh);
+void m_init_buptr(t_msh *msh);
#endif
diff --git a/src/s_init.c b/src/s_init.c
index 7e1c4e5..1e86727 100644
--- a/src/s_init.c
+++ b/src/s_init.c
@@ -117,10 +117,10 @@ t_msh *s_init_msh(int argc, char *const argv[], char *const envp[])
msh->argc = argc - 1;
msh->argv = (char**)argv;
msh->ret = 0;
- init_buptr(msh);
+ m_init_buptr(msh);
s_null_some(msh);
s_set_cwd(cwd, msh);
- if ((msh->cwd = ft_strdup(cwd)) == NULL)
+ if (cwd[0] != C_NUL && (msh->cwd = ft_strdup(cwd)) == NULL)
{
ft_delwords(msh->envp);
ft_memdel((void*)&msh);
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 ;
}
}