🔨」 fix: correct if hostname does not have .

This commit is contained in:
2024-05-15 16:34:04 +02:00
parent 21b7c765ac
commit 0dc8d035d3
2 changed files with 7 additions and 3 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 10:36:31 by adjoly #+# #+# */ /* Created: 2024/05/02 10:36:31 by adjoly #+# #+# */
/* Updated: 2024/05/03 10:32:07 by adjoly ### ########.fr */ /* Updated: 2024/05/15 16:29:19 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,8 +26,12 @@ char *get_hostname(void)
delimiter = ft_strchr(buf, '.'); delimiter = ft_strchr(buf, '.');
if (!delimiter) if (!delimiter)
{ {
hostname = ft_strdup(buf);
free(buf); free(buf);
return (buf); delimiter = ft_strchr(hostname, '\n');
if (delimiter)
hostname[delimiter - hostname] = '\0';
return (hostname);
} }
hostname = ft_calloc(delimiter - buf + 1, sizeof(char)); hostname = ft_calloc(delimiter - buf + 1, sizeof(char));
ft_strlcpy(hostname, buf, delimiter - buf + 1); ft_strlcpy(hostname, buf, delimiter - buf + 1);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/30 13:25:42 by adjoly #+# #+# */ /* Created: 2024/04/30 13:25:42 by adjoly #+# #+# */
/* Updated: 2024/05/02 15:50:14 by adjoly ### ########.fr */ /* Updated: 2024/05/15 16:21:25 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */