-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprint_errors.c
85 lines (77 loc) · 1.77 KB
/
print_errors.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
#include "shell.h"
#include <stdio.h>
#include <stdlib.h>
/**
* print_no_file_error - prints the no file error message to STDOUT
* @exec_name: name of executable (shell that is running)
*
* Return: always void.
*/
void print_no_file_error(char *exec_name)
{
char *buff = NULL;
char *msg = ": No such file or directory\n";
int exec_len = 0, msg_len = 0, i = 0, e_i = 0, m_i = 0;
exec_len = _strlen(exec_name);
msg_len = _strlen(msg);
buff = malloc(sizeof(char) * (exec_len + msg_len));
if (!buff)
return;
/* fill buffer with error message */
while (i < exec_len + msg_len)
{
if (i < exec_len)
buff[i] = exec_name[e_i++];
else
buff[i] = msg[m_i++];
i++;
}
write(STDOUT_FILENO, buff, exec_len + msg_len);
free(buff);
}
/**
* print_perm_denied - prints the permission denied message to STDOUT
* @exec_name: name of executable (shell that is running)
*
* Return: always void.
*/
void print_perm_denied(char *exec_name)
{
char *buff = NULL;
char *msg = ": Permission denied\n";
int exec_len = 0, msg_len = 0, i = 0, e_i = 0, m_i = 0;
exec_len = _strlen(exec_name);
msg_len = _strlen(msg);
buff = malloc(sizeof(char) * (exec_len + msg_len));
if (!buff)
return;
/* fill buffer with error message */
while (i < exec_len + msg_len)
{
if (i < exec_len)
buff[i] = exec_name[e_i++];
else
buff[i] = msg[m_i++];
i++;
}
write(STDOUT_FILENO, buff, exec_len + msg_len);
free(buff);
}
/**
* print_signal_reg_error - prints the sig registry error message to STDOUT
*
* Return: always void.
*/
void print_signal_reg_error(void)
{
write(STDOUT_FILENO, "Failed to register signals in kernal\n", 37);
}
/**
* print_newline - prints a newline character to stdout
*
* Return: always void.
*/
void print_newline(void)
{
write(STDOUT_FILENO, "\n", 1);
}