-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_addfct.c
More file actions
executable file
·92 lines (82 loc) · 2.08 KB
/
ft_addfct.c
File metadata and controls
executable file
·92 lines (82 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_addfct.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khsadira <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/19 12:29:31 by khsadira #+# #+# */
/* Updated: 2018/10/10 09:36:30 by khsadira ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_minishell.h"
char *ft_creat_path(char *path, char *cmd)
{
char *ret;
ret = NULL;
ret = ft_strjoin(path, "/");
ret = ft_strfjoin(&ret, cmd);
return (ret);
}
int ft_acces(char *cmd, char *path)
{
if (!ft_strequ(cmd, ".") &&
!ft_strequ(cmd, "..") &&
access(path, R_OK || X_OK) == 0)
return (1);
return (0);
}
int ft_is_term(void)
{
struct stat stbuf;
if (fstat(STDIN_FILENO, &stbuf) < 0)
return (0);
else
return (S_ISCHR(stbuf.st_mode));
}
void ft_aff_prompt(void)
{
char *cwd;
char buff[4096 + 1];
int i;
int len;
char *tmp;
tmp = NULL;
if ((cwd = getcwd(buff, 4096)))
{
len = ft_strlen(cwd);
i = len;
while (i > 0 && cwd[i] != '/')
i--;
if (cwd[i] == '/' && ft_strlen(cwd) != 1)
i++;
tmp = ft_strsub(cwd, i, len - i);
}
ft_putstr("\033[0;31m");
ft_putstr("<");
if (tmp)
ft_putstr(tmp);
ft_putstr("> ");
ft_putstr("\033[0m");
ft_strdel(&tmp);
}
int ft_regnl(char **str)
{
int ret;
char buff[2];
int i;
int count;
buff[0] = 0;
buff[1] = 0;
count = 1;
*str = NULL;
i = 0;
while ((ret = read(0, buff, 1)) && !ft_strequ(buff, "\n"))
{
buff[ret] = '\0';
*str = ft_strfjoin(&(*str), buff);
}
if (!*str)
*str = ft_strdup("");
return (ret);
}