-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_handling.c
More file actions
81 lines (65 loc) · 1.5 KB
/
Copy patherror_handling.c
File metadata and controls
81 lines (65 loc) · 1.5 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "main.h"
/**
*getCmdArgs - gets command and argument
*@data: relevent data
*@path: path to executable command
*/
void getCmdArgs(shell_data *data, char *path)
{
char *command = _strdup(_strtok(path, " "));
data->cmd = (char *)malloc(_strlen(command) + 1);
_strcpy(data->cmd, command);
data->args[0] = (char *)malloc(_strlen(command) + 1);
_strcpy(data->args[0], command);
free(command);
}
/**
*errorMaker - makes error messege
*@data: shell data
*@str1: part of messege
*@str2: part of messege
*Return: pointer to error messege
*/
char *errorMaker(shell_data *data, char *str1, char *str2)
{
char *errorMsg = NULL;
errorMsg = malloc(sizeof(char) * 64);
if (errorMsg == NULL)
return (NULL);
_strcpy(errorMsg, str1);
_strcat(errorMsg, " : ");
_strcat(errorMsg, data->input);
_strcat(errorMsg, str2);
return (errorMsg);
}
/**
*isPath - handles path
*Return: pointer to path
*/
char *isPath(void)
{
char *path_copy;
char *path = _getenv("PATH");
if (!path)
path_copy = strdup("/usr/local/bin:/usr/bin:/bin");
else if ((_strcmp(path, "") == 0))
path_copy = _strdup("");
else
path_copy = _strdup(path);
return (path_copy);
}
/**
*printError - prints error
*@data: shell data
*@str1: part of messege
*@str2: part of messege
*@status: shell status
*/
void printError(shell_data *data, char *str1, char *str2, int status)
{
char *errormsg;
errormsg = errorMaker(data, str1, str2);
write(STDERR_FILENO, errormsg, _strlen(errormsg));
free(errormsg);
data->status = status;
}