invalid free
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/27 11:22:33 by lderidde #+# #+# */
|
/* Created: 2025/01/27 11:22:33 by lderidde #+# #+# */
|
||||||
/* Updated: 2025/02/04 15:34:39 by lderidde ### ########.fr */
|
/* Updated: 2025/02/05 09:09:56 by lderidde ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -47,6 +47,7 @@ void read_input(t_ast_n *node, int j)
|
|||||||
|
|
||||||
r = 0;
|
r = 0;
|
||||||
i = 0;
|
i = 0;
|
||||||
|
ft_fprintf(2, "heredoc> ");
|
||||||
r = read(0, &c, 1);
|
r = read(0, &c, 1);
|
||||||
while (r && c != '\n' && c != '\0')
|
while (r && c != '\n' && c != '\0')
|
||||||
{
|
{
|
||||||
@@ -55,7 +56,7 @@ void read_input(t_ast_n *node, int j)
|
|||||||
r = read(0, &c, 1);
|
r = read(0, &c, 1);
|
||||||
}
|
}
|
||||||
buf[i] = '\0';
|
buf[i] = '\0';
|
||||||
if (ft_strnstr(buf, node->files[j], ft_strlen(node->files[j])) == 0)
|
if (ft_strncmp(buf, node->files[j], ft_strlen(node->files[j])) == 0)
|
||||||
{
|
{
|
||||||
close(node->fds[1]);
|
close(node->fds[1]);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
@@ -103,8 +104,8 @@ void handle_redir(t_ast_n *node)
|
|||||||
handle_file(node, 3, i);
|
handle_file(node, 3, i);
|
||||||
else if (node->redir[i] == _RED_DL)
|
else if (node->redir[i] == _RED_DL)
|
||||||
here_doc(node, i);
|
here_doc(node, i);
|
||||||
if (node->redir[i] != _RED_DL && node->input != NULL)
|
// if (node->redir[i] != _RED_DL)
|
||||||
free_null_ptr(node->input);
|
// free_null_ptr(node->input);
|
||||||
if (node->redir[i] == _RED_L)
|
if (node->redir[i] == _RED_L)
|
||||||
{
|
{
|
||||||
dup2(node->_stdin, STDIN_FILENO);
|
dup2(node->_stdin, STDIN_FILENO);
|
||||||
@@ -220,6 +221,7 @@ char *find_path(char *cmd, char **env)
|
|||||||
void return_error(char *arg, char *msg, int code)
|
void return_error(char *arg, char *msg, int code)
|
||||||
{
|
{
|
||||||
ft_fprintf(2, "%s: %s\n", arg, msg);
|
ft_fprintf(2, "%s: %s\n", arg, msg);
|
||||||
|
free(arg);
|
||||||
exit(code);
|
exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,10 +234,7 @@ int exec(t_ast_n *node)
|
|||||||
if (!path)
|
if (!path)
|
||||||
return_error(node->cmd, "command not found", 127);
|
return_error(node->cmd, "command not found", 127);
|
||||||
if (access(path, X_OK) != 0)
|
if (access(path, X_OK) != 0)
|
||||||
{
|
|
||||||
free(path);
|
|
||||||
return_error(path, "Permission denied", 126);
|
return_error(path, "Permission denied", 126);
|
||||||
}
|
|
||||||
execve(path, node->args, NULL);
|
execve(path, node->args, NULL);
|
||||||
free(path);
|
free(path);
|
||||||
perror("execve");
|
perror("execve");
|
||||||
|
|||||||
36
srcs/main.c
36
srcs/main.c
@@ -6,7 +6,7 @@
|
|||||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/27 14:16:52 by lderidde #+# #+# */
|
/* Created: 2025/01/27 14:16:52 by lderidde #+# #+# */
|
||||||
/* Updated: 2025/02/03 14:19:09 by lderidde ### ########.fr */
|
/* Updated: 2025/02/05 09:09:35 by lderidde ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -14,27 +14,29 @@
|
|||||||
|
|
||||||
char *powerline(void)
|
char *powerline(void)
|
||||||
{
|
{
|
||||||
// char *pwd;
|
char *pwd;
|
||||||
// char *tilt;
|
char *tilt;
|
||||||
char *input;
|
char *input;
|
||||||
//
|
char *prompt;
|
||||||
// pwd = getcwd(NULL, 0);
|
|
||||||
// if (ft_strncmp(pwd, "/home/", 6) == 0)
|
pwd = getcwd(NULL, 0);
|
||||||
// {
|
if (ft_strncmp(pwd, "/home/", 6) == 0)
|
||||||
// pwd = pwd + 6;
|
{
|
||||||
// while (*pwd && (*pwd) != '/')
|
pwd = pwd + 6;
|
||||||
// pwd = pwd + 1;
|
while (*pwd && (*pwd) != '/')
|
||||||
// tilt = " ~";
|
pwd = pwd + 1;
|
||||||
// }
|
tilt = " ~";
|
||||||
// else
|
}
|
||||||
// tilt = " ";
|
else
|
||||||
|
tilt = " ";
|
||||||
// printf("%s----------------------------------------------
|
// printf("%s----------------------------------------------
|
||||||
// ----------------------------------%s", POW5, RESET);
|
// ----------------------------------%s", POW5, RESET);
|
||||||
// printf("\n%s MMOAT %s%s%s%s%s %s%s%s ",
|
prompt = ft_sprintf("\n%s MMOAT %s%s%s%s%s %s%s%s ",
|
||||||
// POW1, POW2, POW3, POW4, tilt, pwd, RESET, POW5, RESET);
|
POW1, POW2, POW3, POW4, tilt, pwd, RESET, POW5, RESET);
|
||||||
input = readline(">> ");
|
input = readline(prompt);
|
||||||
if (ft_strlen(input) > 0)
|
if (ft_strlen(input) > 0)
|
||||||
add_history(input);
|
add_history(input);
|
||||||
|
free(prompt);
|
||||||
return (input);
|
return (input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user