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 08:45:43 -05:00
/* Updated: 2023/02/21 14:34:50 by erey-bet ### ########.fr */
2023-02-17 10:54:58 -05:00
/* */
/* ************************************************************************** */
2023-02-17 11:46:12 -05:00
#include "../minishell.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)
ft_putstr_fd(path, fd);
else
{
ft_putstr_fd("Error getcwd", fd);
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
{
ft_putstr_fd("Error getcwd", fd);
return (NULL);
}
}