42_minishell/builtins/pwd.c

42 lines
1.3 KiB
C
Raw Normal View History

2023-02-17 10:54:58 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pwd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 16:09:11 by erey-bet #+# #+# */
2023-02-21 09:12:26 -05:00
/* Updated: 2023/02/21 15:11:38 by cchauvet ### ########.fr */
2023-02-17 10:54:58 -05:00
/* */
/* ************************************************************************** */
#include "./builtins_private.h"
2023-02-17 10:54:58 -05:00
2023-02-21 08:45:43 -05:00
int pwd(int fd)
2023-02-17 10:54:58 -05:00
{
2023-02-21 08:45:43 -05:00
char path[PATH_MAX];
if (getcwd(path, sizeof(path)) != NULL)
2023-02-21 09:12:26 -05:00
ft_putendl_fd(path, fd);
2023-02-21 08:45:43 -05:00
else
{
2023-02-21 09:12:26 -05:00
ft_putendl_fd("Error getcwd", fd);
2023-02-21 08:45:43 -05:00
return (1);
}
2023-02-17 10:54:58 -05:00
return (0);
}
2023-02-21 08:45:43 -05:00
char *get_pwd(int fd)
{
char *str;
str = ft_calloc(PATH_MAX, sizeof(char *));
if (getcwd(str, PATH_MAX) != NULL)
return (str);
else
{
2023-02-21 09:12:26 -05:00
ft_putendl_fd("Error getcwd", fd);
2023-02-21 08:45:43 -05:00
return (NULL);
}
}