-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell_errMsgs2.c
executable file
·77 lines (65 loc) · 1.53 KB
/
shell_errMsgs2.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
/*
* File: shell_errMsgs2.c
* Auth: lUCY OUMA
* PESSY KAPERE
*/
#include "shell.h"
char *error_126(char **args);
char *error_127(char **args);
/**
* error_126 - Creates an error message for permission denied failures.
* @args: An array of arguments passed to the command.
*
* Return: The error string.
*/
char *error_126(char **args)
{
char *error_er, *hist_str_er;
int len;
hist_str_er = _itoa(hist);
if (!hist_str_er)
return (NULL);
len = _strlen(name) + _strlen(hist_str_er) + _strlen(args[0]) + 24;
error_er = malloc(sizeof(char) * (len + 1));
if (!error_er)
{
free(hist_str_er);
return (NULL);
}
_strcpy(error_er, name);
_strcat(error_er, ": ");
_strcat(error_er, hist_str_er);
_strcat(error_er, ": ");
_strcat(error_er, args[0]);
_strcat(error_er, ": Permission denied\n");
free(hist_str_er);
return (error_er);
}
/**
* error_127 - Creates an error message for command not found failures.
* @args: An array of arguments passed to the command.
* Return: The error string.
*/
char *error_127(char **args)
{
char *error_er, *hist_str_er;
int len;
hist_str_er = _itoa(hist);
if (!hist_str_er)
return (NULL);
len = _strlen(name) + _strlen(hist_str_er) + _strlen(args[0]) + 16;
error_er = malloc(sizeof(char) * (len + 1));
if (!error_er)
{
free(hist_str_er);
return (NULL);
}
_strcpy(error_er, name);
_strcat(error_er, ": ");
_strcat(error_er, hist_str_er);
_strcat(error_er, ": ");
_strcat(error_er, args[0]);
_strcat(error_er, ": not found\n");
free(hist_str_er);
return (error_er);
}