forked from wendysegura/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_switch.c
57 lines (44 loc) · 913 Bytes
/
error_switch.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
#include "holberton.h"
/**
** errors - writes error depending on the case letter
** @error_msg: error letter that goes with perror message
** Return: void
**/
void errors(char error_msg)
{
/* local variable definition */
switch (error_msg)
{
case 'A':
write(STDERR_FILENO, ERROR_FORK, _strlen(ERROR_FORK));
perror("Error");
break;
case 'B':
perror("Error");
break;
case 'C':
write(STDERR_FILENO, ERROR_MALLOC, _strlen(ERROR_FORK));
break;
case 'D':
write(STDERR_FILENO, ERROR_PATH, _strlen(ERROR_PATH));
break;
default:
return;
}
}
/**
* err_msg - print prepend error msg to stderr
* @se: shell environment struct
**/
void err_msg(shenv_t *se)
{
char alpha_counter[30];
int i;
for (i = 0; i < 30; i++)
alpha_counter[i] = '\0';
_puts_err("hsh: ");
itoa(se->counter, alpha_counter);
_puts_err(alpha_counter);
_puts_err(": ");
_puts_err(se->cmd_tokens[0]);
}