-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.c
More file actions
62 lines (56 loc) · 1.33 KB
/
Copy patherror.c
File metadata and controls
62 lines (56 loc) · 1.33 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
#include "shell.h"
/**
* print_error - uses write system call to print error message when cmd is not
* found
* @name: name of the shell program
* @cmd_count: number of command
* @command: command
* @error_msg: error message to be printed out
*/
void print_error(const char *name, int cmd_count, const char *command,
const char *error_msg)
{
char command_num[2];
char newl = '\n';
print_string(STDERR_FILENO, name);
print_string(STDERR_FILENO, ": ");
convert_string(cmd_count, command_num);
print_string(STDERR_FILENO, command_num);
print_string(STDERR_FILENO, ": ");
print_string(STDERR_FILENO, command);
print_string(STDERR_FILENO, ": ");
print_string(STDERR_FILENO, error_msg);
write(STDERR_FILENO, &newl, 1);
}
/**
* print_string - prints a string to a specified file stream using write
* @descriptor: stream
* @string: string
*/
void print_string(int descriptor, const char *string)
{
write(descriptor, string, strlen(string));
}
/**
* convert_string - converts a string to an integer
* @num: number
* @string: string to be converted
* Return: converted string
*/
void convert_string(int num, char *string)
{
int h = 0;
int length = 0;
int fornow = num;
while (fornow > 0)
{
fornow /= 10;
length++;
}
for (h = length - 1; h >= 0; h--)
{
string[h] = '0' + (num % 10);
num /= 10;
}
string[length] = '\0';
}