-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.c
More file actions
38 lines (33 loc) · 770 Bytes
/
Copy patherrors.c
File metadata and controls
38 lines (33 loc) · 770 Bytes
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
#include "shell.h"
/**
* print_error - A function that prints command not found.
* @hsh: the name of the shell
* @line: the command counter
* @cmd: The pointer to tokenized command
* @msg: the error message
* Return: Nothing.
*/
void print_error(char *hsh, int line, char *cmd, char *msg)
{
char num[20];
int i = 0, n = line;
write(STDERR_FILENO, hsh, _strlen(hsh));
write(STDERR_FILENO, ": ", 2);
if (line >= 0)
{
if (n == 0)
num[i++] = '0';
while (n)
{
num[i++] = (n % 10) + '0';
n /= 10;
}
while (--i >= 0)
write(STDERR_FILENO, &num[i], 1);
write(STDERR_FILENO, ": ", 2);
}
write(STDERR_FILENO, cmd, _strlen(cmd));
write(STDERR_FILENO, ": ", 2);
write(STDERR_FILENO, msg, _strlen(msg));
write(STDERR_FILENO, "\n", 1);
}