forked from denistillwaters/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignal.c
More file actions
101 lines (87 loc) · 1.29 KB
/
signal.c
File metadata and controls
101 lines (87 loc) · 1.29 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
93
94
95
96
97
98
99
#include "shell.h"
/**
* handler - handles ctrl + c signal
* @sig: represent signal to handle
*/
void handler(int sig)
{
(void)sig;
write(STDOUT_FILENO, "\n($) ", 5);
fflush(stdout);
}
/**
* removechar - This function removes a char
* @str: str
* @c: char to remove
*/
void removechar(char *str, char c)
{
int len = strlen(str);
int i, j;
for (i = 0, j = 0; i < len; i++)
{
if (str[i] != c)
{
str[j] = str[i];
j++;
}
}
str[j] = '\0';
}
/**
* exxit - function to track exit status
* @buf: buffer
* @args: arguments passed
* @count: count cmd
* @av: argument vector
*/
void exxit(char *buf, char **args, int count, char **av)
{
int status;
if (args[1] == 0)
{
free(buf);
exit(EXIT_SUCCESS);
}
else
{
status = _atoi(args[1]);
if (_isdigit(status) == 1)
{
free(buf);
exit(status);
}
else
exit_errorMessage(args, count, av);
}
}
/**
* _atoi - This function converts a str to number
* @s: string to convert
* Return: int (success)
*/
int _atoi(char *s)
{
int i = 0, convert = 1, j = 0;
unsigned int result = 0;
while (s[i])
{
if (s[i] == '-')
{
convert *= -1;
}
while (s[i] >= '0' && s[i] <= '9')
{
j = 1;
result = (result * 10) + (s[i] - '0');
i++;
}
if (j == 1)
{
break;
}
i++;
}
result *= convert;
return (result);
}