Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nicknamemohaji committed Apr 10, 2024
1 parent b0de919 commit 58fde55
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
17 changes: 11 additions & 6 deletions codes/builtins/builtin_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 06:04:41 by nicknamemoh #+# #+# */
/* Updated: 2024/04/09 14:59:46 by kyungjle ### ########.fr */
/* Updated: 2024/04/10 16:34:46 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -26,18 +26,18 @@ will return with argument given (0 if no argument given)
*/
int builtin_exit(char *args[], t_ld_map_env *env)
{
printf("exit\n");
if (!builtin_check_argument_count((const char **) args, 2))
return (1);
if (args[1] != NULL)
{
if (!check_digit(args[1]))
exit (255);
free_ld_map(env);
write(2, "exit\n", 5);
exit(ft_atoi(args[1]));
}
else
exit(EXIT_SUCCESS);
write(2, "exit\n", 5);
exit(EXIT_SUCCESS);
}

/*
Expand All @@ -50,13 +50,18 @@ check for string is only digit
static t_bool check_digit(const char *c)
{
const char *ptr;
char *msg;

ptr = c;
while (*c != '\0')
{
if (!ft_isdigit(*c))
{
printf("exit: %s: numeric argument required\n", ptr);
msg = malloc((ft_strlen(ptr) + 36) * sizeof(char));
*msg = '\0';
ft_sprintf(msg, "exit: %s: numeric argument required\n", ptr);
write(2, msg, ft_strlen(msg));
free(msg);
return (FALSE);
}
c++;
Expand Down Expand Up @@ -84,7 +89,7 @@ t_bool builtin_check_argument_count(const char *args[], int limit)
}
if (count > limit)
{
printf("too many arguments\n");
write(2, "exit: too many arguments\n", 25);
return (FALSE);
}
else
Expand Down
6 changes: 3 additions & 3 deletions codes/loader/ldexec_findexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/13 16:47:55 by nicknamemoh #+# #+# */
/* Updated: 2024/04/09 17:48:24 by kyungjle ### ########.fr */
/* Updated: 2024/04/10 16:25:48 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -59,10 +59,10 @@ char *ldexec_exec_find_f(char *cmd, t_bool *need_free, const char *path)
else
return (check_relative_f(cmd));
}
ret = check_cwd_f(cmd);
ret = check_env_path_f(cmd, path);
if (ret != NULL)
return (ret);
ret = check_env_path_f(cmd, path);
ret = check_cwd_f(cmd);
return (ret);
}

Expand Down

0 comments on commit 58fde55

Please sign in to comment.