Cub3D
Loading...
Searching...
No Matches
put_error_msg.c
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* put_error_msg.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: hnagasak <hnagasak@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/11/15 00:42:41 by kamitsui #+# #+# */
9/* Updated: 2024/12/29 18:18:03 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "cub3d.h"
14
15static bool is_entry_char(const char c)
16{
17 return (c != ' ' && c != '\0' && c != '\n');
18}
19
20void put_error_msg(const char *entry, const char *msg)
21{
22 size_t len;
23 ssize_t result;
24
25 ft_eprintf("%s", ERR_PROMPT);
26 len = 0;
27 while (is_entry_char(entry[len]) == true)
28 len++;
29 result = write(STDERR_FILENO, entry, len);
30 if (result == -1)
31 {
32 perror("write failed");
33 exit(EXIT_FAILURE);
34 }
35 else if ((size_t)result != len)
36 {
37 ft_eprintf("Partial write. Only %lu bytes out of %lu were written.\n",
38 (size_t)result, len);
39 exit(EXIT_FAILURE);
40 }
41 ft_eprintf(": %s\n", msg);
42}