42_minishell/builtins/pwd.c
Etienne Rey-bethbeder 62e887cfbd _
2023-04-18 13:30:17 +02:00

42 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pwd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 16:09:11 by erey-bet #+# #+# */
/* Updated: 2023/04/18 12:59:25 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./builtins_private.h"
int pwd(int fd)
{
char path[PATH_MAX];
if (getcwd(path, sizeof(path)) != NULL)
ft_putendl_fd(path, fd);
else
{
ft_putendl_fd("Error getcwd", 2);
return (1);
}
return (0);
}
char *get_pwd(void)
{
char *str;
str = ft_calloc(PATH_MAX, sizeof(char *));
if (getcwd(str, PATH_MAX) != NULL)
return (str);
else
{
ft_putendl_fd("Error getcwd", 2);
return (NULL);
}
}