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

Commit

Permalink
fix redirection error
Browse files Browse the repository at this point in the history
  • Loading branch information
nicknamemohaji committed Apr 22, 2024
1 parent f1b2ba2 commit 7c72ca9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 20 deletions.
12 changes: 3 additions & 9 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/17 23:09:25 by kyungjle ### ########.fr */
/* Updated: 2024/04/22 14:50:55 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -54,18 +54,13 @@ 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))
{
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);
ft_dprintf(2, "exit: %s: numeric argument required\n", ptr);
return (FALSE);
}
c++;
Expand Down Expand Up @@ -94,8 +89,7 @@ t_bool builtin_check_argument_count(const char *args[], int limit, char *cmd)
}
if (count > limit)
{
write(2, cmd, ft_strlen(cmd));
write(2, ": too many arguments\n", 21);
ft_dprintf(2, "%s: too many arguments\n", cmd);
return (FALSE);
}
else
Expand Down
5 changes: 3 additions & 2 deletions codes/libft/headers/ft_printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* ft_printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nicknamemohaji <nicknamemohaji@student. +#+ +:+ +#+ */
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/15 14:49:46 by kyungjle #+# #+# */
/* Updated: 2024/03/27 05:18:02 by nicknamemoh ### ########.fr */
/* Updated: 2024/04/22 14:49:41 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -28,6 +28,7 @@ typedef struct s_buf
int ft_printf(const char *s, ...);
int ft_sprintf_va(const char *s, char **buf, va_list va);
int ft_sprintf(char *ret, const char *s, ...);
int ft_dprintf(int fd, const char *s, ...);

// fp_conversion_charater.c
char *fp_char(char c);
Expand Down
3 changes: 2 additions & 1 deletion codes/libft/headers/libft.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/05 00:59:19 by kyungjle #+# #+# */
/* Updated: 2024/04/04 18:35:51 by kyungjle ### ########.fr */
/* Updated: 2024/04/22 14:49:43 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -65,6 +65,7 @@ void ft_putnbr_fd(int n, int fd);

// ft_printf
int ft_printf(const char *s, ...);
int ft_dprintf(int fd, const char *s, ...);
int ft_sprintf(char *ret, const char *s, ...);

// get_next_line
Expand Down
22 changes: 21 additions & 1 deletion codes/libft/srcs/ft_printf/ft_printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
/* By: kyungjle <kyungjle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/17 16:08:32 by kyungjle #+# #+# */
/* Updated: 2024/01/03 19:45:51 by kyungjle ### ########.fr */
/* Updated: 2024/04/22 14:49:17 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_printf.h"

int ft_printf(const char *s, ...);
int ft_dpintf(int fd, const char *s, ...);
int ft_sprintf(char *ret, const char *s, ...);
int ft_sprintf_va(const char *s, char **buf, va_list va);

Expand All @@ -35,6 +36,25 @@ int ft_printf(const char *s, ...)
return (ret);
}

int ft_dprintf(int fd, const char *s, ...)
{
int ret;
char *buf;
va_list va;

if (*s == 0)
return (0);
buf = NULL;
va_start(va, s);
ret = ft_sprintf_va(s, &buf, va);
va_end(va);
if (ret < 0)
return (ret);
write(fd, buf, ret);
free(buf);
return (ret);
}

int ft_sprintf(char *ret, const char *s, ...)
{
int len;
Expand Down
12 changes: 6 additions & 6 deletions codes/utils/ld_errno_file.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/14 01:33:48 by nicknamemoh #+# #+# */
/* Updated: 2024/04/09 20:33:56 by kyungjle ### ########.fr */
/* Updated: 2024/04/22 14:47:49 by kyungjle ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -28,15 +28,15 @@ exits if error is unrecovable (ex. EIO, EFAULT)
t_bool ld_errno_file(const char *trace, char *path)
{
if (errno == ENOENT)
printf("%s: %s: No such file or directory\n", trace, path);
ft_dprintf(2, "%s: %s: No such file or directory\n", trace, path);
else if (errno == ENOTDIR)
printf("%s: %s: Not a directory\n", trace, path);
ft_dprintf(2, "%s: %s: Not a directory\n", trace, path);
else if (errno == EISDIR)
printf("%s: %s: Is a directory\n", trace, path);
ft_dprintf(2, "%s: %s: Is a directory\n", trace, path);
else if (errno == EACCES)
printf("%s: %s: Permission denied\n", trace, path);
ft_dprintf(2, "%s: %s: Permission denied\n", trace, path);
else if (errno == ENAMETOOLONG)
printf("%s: %s: Name too long\n", trace, path);
ft_dprintf(2, "%s: %s: Name too long\n", trace, path);
else
do_exit(trace);
return (FALSE);
Expand Down
2 changes: 1 addition & 1 deletion codes/utils/ld_map_functions2.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ char *ldpre_env_fetch(char *key, t_ld_map_env *map)

if (!ldpre_env_validate_key(key))
{
printf("syntax error: [%s]\n", key);
printf("export: syntax error: [%s]\n", key);
return (NULL);
}
node = ldpre_env_searchkey_f(key, map);
Expand Down

0 comments on commit 7c72ca9

Please sign in to comment.