-
Notifications
You must be signed in to change notification settings - Fork 0
/
err_msgs2.c
78 lines (66 loc) · 1.43 KB
/
err_msgs2.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
/*
* File: err_msgs2.c
* Auth: Alex Yu
* Brennan D Baraban
*/
#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, *hist_str;
int len;
hist_str = _itoa(hist);
if (!hist_str)
return (NULL);
len = _strlen(name) + _strlen(hist_str) + _strlen(args[0]) + 24;
error = malloc(sizeof(char) * (len + 1));
if (!error)
{
free(hist_str);
return (NULL);
}
_strcpy(error, name);
_strcat(error, ": ");
_strcat(error, hist_str);
_strcat(error, ": ");
_strcat(error, args[0]);
_strcat(error, ": Permission denied\n");
free(hist_str);
return (error);
}
/**
* 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, *hist_str;
int len;
hist_str = _itoa(hist);
if (!hist_str)
return (NULL);
len = _strlen(name) + _strlen(hist_str) + _strlen(args[0]) + 16;
error = malloc(sizeof(char) * (len + 1));
if (!error)
{
free(hist_str);
return (NULL);
}
_strcpy(error, name);
_strcat(error, ": ");
_strcat(error, hist_str);
_strcat(error, ": ");
_strcat(error, args[0]);
_strcat(error, ": not found\n");
free(hist_str);
return (error);
}