/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   error_msg.c                                        :+:    :+:            */
/*                                                     +:+                    */
/*   By: whaffman <whaffman@student.codam.nl>         +#+                     */
/*                                                   +#+                      */
/*   Created: 2025/02/20 17:03:13 by whaffman      #+#    #+#                 */
/*   Updated: 2025/03/03 21:20:09 by whaffman      ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include "minishell.h"
#define SHELL_NAME "minishell"

void	error_msg(char *func, char *msg)
{
	if (func == NULL && msg == NULL && errno)
	{
		perror(RED BOLD SHELL_NAME RESET);
		errno = 0;
	}
	else
	{
		ft_putstr_fd(RED BOLD SHELL_NAME RESET ": ", STDERR_FILENO);
		if (func != NULL)
		{
			ft_putstr_fd(func, STDERR_FILENO);
			ft_putstr_fd(": ", STDERR_FILENO);
		}
		if (msg != NULL)
			ft_putstr_fd(msg, STDERR_FILENO);
		if (errno)
		{
			ft_putstr_fd(": ", STDERR_FILENO);
			ft_putstr_fd(strerror(errno), STDERR_FILENO);
			errno = 0;
		}
		ft_putstr_fd("\n", STDERR_FILENO);
	}
}
