-
Notifications
You must be signed in to change notification settings - Fork 0
/
prints.c
89 lines (85 loc) · 1.49 KB
/
prints.c
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
#include "sshell.h"
/**
* handle_builtin - handles execution of builtin functions
* @command: tokenized commands
* @line: input read from stdin
*
* Return: 1 if executed, 0 if not
*/
int handle_builtin(char **command, char *line)
{
struct builtin builtin = {"env", "exit"};
if (_strcmp(*command, builtin.env) == 0)
{
print_env();
return (1);
}
else if (_strcmp(*command, builtin.exit) == 0)
{
exit_cmd(command, line);
return (1);
}
return (0);
}
/**
*handle_signal- it keeps track is interactive mode
*@m: the signal number
*Return: nothing
*/
void handle_signal(int m)
{
(void)m;
write(STDERR_FILENO, "\n", 1);
write(STDERR_FILENO, "$ ", 2);
}
/**
* find_path - finds the path from the global enviroment
* Return: NULL if path is not found or path if path is found.
*/
char *find_path(void)
{
int x;
char **env = environ, *path = NULL;
while (*env)
{
if (_strncmp(*env, "PATH=", 5) == 0)
{
path = *env;
while (*path && x < 5)
{
path++;
x++;
}
return (path);
}
env++;
}
return (NULL);
}
/**
* print_env - prints the environment string to stdout
*
* Return: 0
*/
void print_env(void)
{
int x = 0;
char **env = environ;
while (env[x])
{
write(STDOUT_FILENO, (const void *)env[x], _strlen(env[x]));
write(STDOUT_FILENO, "\n", 1);
x++;
}
}
/**
* _putchar - writes the character c to stdout
* @c: The character to print
*
* Return: On success 1.
* On error, -1 is returned and errno set appropriately
*/
int _putchar(char c)
{
return (write(1, &c, 1));
}