mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 11:26:51 +01:00
「🔨」 fix(Issue : prompt/historique #3): Fixed and normed
This commit is contained in:
@ -6,30 +6,18 @@
|
|||||||
/* 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/17 13:53:43 by adjoly ### ########.fr */
|
/* Updated: 2024/05/21 20:55:19 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fcntl.h"
|
#include "fcntl.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
char *get_hostname(void)
|
char *get_fullhostname(char *buf)
|
||||||
{
|
{
|
||||||
char *hostname;
|
char *hostname;
|
||||||
char *buf;
|
|
||||||
int host_file;
|
|
||||||
char *delimiter;
|
char *delimiter;
|
||||||
|
|
||||||
buf = ft_calloc(254, sizeof(char));
|
|
||||||
if (!buf)
|
|
||||||
return (ft_strdup("nixos"));
|
|
||||||
host_file = open("/etc/hostname", O_RDONLY);
|
|
||||||
if (host_file <= -1)
|
|
||||||
return (ft_strdup("nixos"));
|
|
||||||
read(host_file, buf, 254);
|
|
||||||
delimiter = ft_strchr(buf, '.');
|
|
||||||
if (!delimiter)
|
|
||||||
{
|
|
||||||
hostname = ft_strdup(buf);
|
hostname = ft_strdup(buf);
|
||||||
free(buf);
|
free(buf);
|
||||||
delimiter = ft_strchr(hostname, '\n');
|
delimiter = ft_strchr(hostname, '\n');
|
||||||
@ -37,9 +25,42 @@ char *get_hostname(void)
|
|||||||
hostname[delimiter - hostname] = '\0';
|
hostname[delimiter - hostname] = '\0';
|
||||||
return (hostname);
|
return (hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *__get_host_str(void)
|
||||||
|
{
|
||||||
|
int host_file;
|
||||||
|
char *buf;
|
||||||
|
|
||||||
|
buf = ft_calloc(254, sizeof(char));
|
||||||
|
if (!buf)
|
||||||
|
return (ft_strdup("nixos"));
|
||||||
|
host_file = open("/etc/hostname", O_RDONLY);
|
||||||
|
if (host_file <= -1)
|
||||||
|
{
|
||||||
|
free(buf);
|
||||||
|
return (ft_strdup("nixos"));
|
||||||
|
}
|
||||||
|
read(host_file, buf, 254);
|
||||||
|
close(host_file);
|
||||||
|
return (buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *get_hostname(void)
|
||||||
|
{
|
||||||
|
char *hostname;
|
||||||
|
char *buf;
|
||||||
|
char *delimiter;
|
||||||
|
|
||||||
|
buf = __get_host_str();
|
||||||
|
delimiter = ft_strchr(buf, '.');
|
||||||
|
if (!delimiter)
|
||||||
|
return (get_fullhostname(buf));
|
||||||
hostname = ft_calloc(delimiter - buf + 1, sizeof(char));
|
hostname = ft_calloc(delimiter - buf + 1, sizeof(char));
|
||||||
if (!hostname)
|
if (!hostname)
|
||||||
|
{
|
||||||
|
free(buf);
|
||||||
return (ft_strdup("nixos"));
|
return (ft_strdup("nixos"));
|
||||||
|
}
|
||||||
ft_strlcpy(hostname, buf, delimiter - buf + 1);
|
ft_strlcpy(hostname, buf, delimiter - buf + 1);
|
||||||
free(buf);
|
free(buf);
|
||||||
return (hostname);
|
return (hostname);
|
||||||
|
@ -6,12 +6,12 @@
|
|||||||
/* 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/17 14:25:57 by adjoly ### ########.fr */
|
/* Updated: 2024/05/21 20:48:02 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
#include "minishell.h"
|
#include "prompt.h"
|
||||||
|
|
||||||
char *get_prompt(void)
|
char *get_prompt(void)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user