36 lines
1.2 KiB
C
Raw Normal View History

2024-05-02 15:50:58 +02:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_pwd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 14:42:00 by adjoly #+# #+# */
/* Updated: 2024/05/17 14:25:28 by adjoly ### ########.fr */
2024-05-02 15:50:58 +02:00
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
char *get_pwd(void)
{
char *pwd;
char *home;
pwd = getenv("PWD");
if (!pwd)
return (NULL);
2024-05-02 15:50:58 +02:00
home = getenv("HOME");
if (!pwd)
return (NULL);
2024-05-02 15:50:58 +02:00
if (!ft_strncmp(pwd, home, ft_strlen(home)))
{
2024-05-02 15:50:58 +02:00
pwd += ft_strlen(home);
pwd = ft_strjoin("~", pwd);
if (!pwd)
return (NULL);
}
return (ft_strdup(pwd));
2024-05-02 15:50:58 +02:00
}