From 8125e4306594944867d8c4b5848896288b889d46 Mon Sep 17 00:00:00 2001 From: LuckyLaszlo Date: Wed, 8 Dec 2021 04:02:00 +0100 Subject: [PATCH] init_prompt() correct error return --- srcs/init.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/srcs/init.c b/srcs/init.c index e332c64..a93c524 100644 --- a/srcs/init.c +++ b/srcs/init.c @@ -50,7 +50,7 @@ char **retrieve_path(void) return (path_split); } -static char *init_prompt_base(void) // WIP, error return TODO +static char *init_prompt_base(void) { char *prompt_base; char *tmp; @@ -61,21 +61,33 @@ static char *init_prompt_base(void) // WIP, error return TODO if (!tmp) tmp = U_DEFAULT_USER; prompt_base = ft_strjoin(TERM_LIGHT_GREEN, tmp); + if (!prompt_base) + return (NULL); prompt_base = ft_strjoinfree_s1(prompt_base, "@"); + if (!prompt_base) + return (NULL); tmp = getenv("NAME"); if (!tmp) tmp = U_DEFAULT_NAME; prompt_base = ft_strjoinfree_s1(prompt_base, tmp); + if (!prompt_base) + return (NULL); prompt_base = ft_strjoinfree_s1(prompt_base, TERM_RESET":"TERM_LIGHT_BLUE); + if (!prompt_base) + return (NULL); return (prompt_base); } -char *init_prompt(char *prompt_base) // WIP, error return TODO +char *init_prompt(char *prompt_base) { char *prompt; prompt = ft_strjoinfree_s2(prompt_base, getcwd(NULL, 0)); + if (!prompt) + return (NULL); prompt = ft_strjoinfree_s1(prompt, TERM_RESET U_PROMPT_END); + if (!prompt) + return (NULL); return (prompt); }