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-03-09 14:13:38 -05:00
|
|
|
/* Updated: 2023/03/09 20:00:19 by erey-bet ### ########.fr */
|
2023-02-17 10:54:58 -05:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
2023-03-10 06:32:39 -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];
|
|
|
|
|
2023-03-09 14:13:38 -05:00
|
|
|
if (getcwd(path, sizeof(path)) != NULL)
|
2023-02-21 09:12:26 -05:00
|
|
|
ft_putendl_fd(path, fd);
|
2023-03-09 14:13:38 -05:00
|
|
|
else
|
2023-02-21 08:45:43 -05:00
|
|
|
{
|
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 *));
|
2023-03-09 14:13:38 -05:00
|
|
|
if (getcwd(str, PATH_MAX) != NULL)
|
2023-02-21 08:45:43 -05:00
|
|
|
return (str);
|
2023-03-09 14:13:38 -05:00
|
|
|
else
|
2023-02-21 08:45:43 -05:00
|
|
|
{
|
2023-02-21 09:12:26 -05:00
|
|
|
ft_putendl_fd("Error getcwd", fd);
|
2023-02-21 08:45:43 -05:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
}
|