fix norm
This commit is contained in:
52
srcs/utils.c
52
srcs/utils.c
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/03 13:20:54 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/09 18:11:39 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/12/10 18:16:13 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -27,64 +27,64 @@ void invalid_pointer(char *fnc)
|
||||
write(2, "(): invalid pointer\n", 21);
|
||||
}
|
||||
|
||||
int log_fd(int closefd)
|
||||
int log_fd(int closefd)
|
||||
{
|
||||
static int fd;
|
||||
|
||||
if(closefd)
|
||||
static int fd;
|
||||
|
||||
if (closefd)
|
||||
{
|
||||
if(fd > 0)
|
||||
if (fd > 0)
|
||||
close(fd);
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
if(fd == 0)
|
||||
if (fd == 0)
|
||||
{
|
||||
fd = open("malloc.log", O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||
if(fd == -1)
|
||||
if (fd == -1)
|
||||
{
|
||||
ft_putnbr_fd(errno, 1);
|
||||
write(2, "malloc(): can't open log file\n", 37);
|
||||
}
|
||||
}
|
||||
return(fd);
|
||||
return (fd);
|
||||
}
|
||||
|
||||
void log_str(char *str, int level, int print_level, int nl)
|
||||
void log_str(char *str, int level, int print_level, int nl)
|
||||
{
|
||||
int fd;
|
||||
int fd;
|
||||
|
||||
if(level > get_settings()->debug_level)
|
||||
if (level > get_settings()->debug_level)
|
||||
return ;
|
||||
fd = log_fd(0);
|
||||
if(fd == -1)
|
||||
if (fd == -1)
|
||||
return ;
|
||||
if(print_level && level == 1)
|
||||
if (print_level && level == 1)
|
||||
ft_putstr_fd("[ERR] ", fd);
|
||||
else if(print_level && level == 2)
|
||||
else if (print_level && level == 2)
|
||||
ft_putstr_fd("[WARN] ", fd);
|
||||
else if(print_level && level == 3)
|
||||
else if (print_level && level == 3)
|
||||
ft_putstr_fd("[INFO] ", fd);
|
||||
ft_putstr_fd(str, fd);
|
||||
if(nl)
|
||||
if (nl)
|
||||
write(fd, "\n", 1);
|
||||
}
|
||||
|
||||
void log_ul(unsigned long nb, int level, int print_level, int nl)
|
||||
void log_ul(unsigned long nb, int level, int print_level, int nl)
|
||||
{
|
||||
int fd;
|
||||
int fd;
|
||||
|
||||
if(level > get_settings()->debug_level)
|
||||
if (level > get_settings()->debug_level)
|
||||
return ;
|
||||
fd = log_fd(0);
|
||||
if(fd == -1)
|
||||
if (fd == -1)
|
||||
return ;
|
||||
if(print_level && level == 1)
|
||||
if (print_level && level == 1)
|
||||
ft_putstr_fd("[ERR] ", fd);
|
||||
else if(print_level && level == 2)
|
||||
else if (print_level && level == 2)
|
||||
ft_putstr_fd("[WARN] ", fd);
|
||||
else if(print_level && level == 3)
|
||||
else if (print_level && level == 3)
|
||||
ft_putstr_fd("[INFO] ", fd);
|
||||
ft_putulnbr_fd(nb, fd);
|
||||
if(nl)
|
||||
if (nl)
|
||||
write(fd, "\n", 1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user