diff --git a/codes/builtins/builtin_exit.c b/codes/builtins/builtin_exit.c index c4e30a2..851111e 100644 --- a/codes/builtins/builtin_exit.c +++ b/codes/builtins/builtin_exit.c @@ -6,7 +6,7 @@ /* By: kyungjle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ @@ -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++; @@ -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 diff --git a/codes/libft/headers/ft_printf.h b/codes/libft/headers/ft_printf.h index 77c8bc7..db2dad6 100644 --- a/codes/libft/headers/ft_printf.h +++ b/codes/libft/headers/ft_printf.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_printf.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: nicknamemohaji +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ @@ -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); diff --git a/codes/libft/headers/libft.h b/codes/libft/headers/libft.h index b1a856b..a232f02 100644 --- a/codes/libft/headers/libft.h +++ b/codes/libft/headers/libft.h @@ -6,7 +6,7 @@ /* By: kyungjle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ @@ -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 diff --git a/codes/libft/srcs/ft_printf/ft_printf.c b/codes/libft/srcs/ft_printf/ft_printf.c index 666d7bf..c47be42 100644 --- a/codes/libft/srcs/ft_printf/ft_printf.c +++ b/codes/libft/srcs/ft_printf/ft_printf.c @@ -6,13 +6,14 @@ /* By: kyungjle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); @@ -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; diff --git a/codes/utils/ld_errno_file.c b/codes/utils/ld_errno_file.c index 407d517..13fa7ac 100644 --- a/codes/utils/ld_errno_file.c +++ b/codes/utils/ld_errno_file.c @@ -6,7 +6,7 @@ /* By: kyungjle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ @@ -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); diff --git a/codes/utils/ld_map_functions2.c b/codes/utils/ld_map_functions2.c index 1207b6e..de66cee 100644 --- a/codes/utils/ld_map_functions2.c +++ b/codes/utils/ld_map_functions2.c @@ -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);