-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfinal.c
More file actions
115 lines (96 loc) · 2 KB
/
Copy pathfinal.c
File metadata and controls
115 lines (96 loc) · 2 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "header.h"
/**
* _error - Funtion to execute program.
*
* @count_w: Command from the user imput.
* @array: arguments for the program to execute.
*
* Return: Always return 0.
*/
void _error(int count_w, char *array[])
{
int i = 0;
char *print_c = NULL;
print_c = _itoa(count_w);
for (i = 0; print_c[i]; i++)
;
write(STDERR_FILENO, "\033[94mminishell$: \033[0m", 17);
write(STDERR_FILENO, print_c, i); /* by Andy.*/
write(STDERR_FILENO, ": ", 2);
for (i = 0; array[0][i]; i++)
;
write(STDERR_FILENO, array[0], i);
write(STDERR_FILENO, ": not found\n", 12);
free(print_c);
}
/**
* _itoa - Funtion to execute program.
*
* @count_w: Command from the user imput.
*
* Return: Always return 0.
*/
char *_itoa(int count_w)
{
char *numstr;
unsigned int tmp, digits;
tmp = count_w;
for (digits = 0; tmp != 0; digits++)
tmp /= 10;
numstr = malloc(sizeof(char) * (digits + 1));
if (numstr == NULL)
{
perror("Fatal Error1");
exit(127);
}
numstr[digits] = '\0';
for (--digits; count_w; --digits)
{
numstr[digits] = (count_w % 10) + '0';
count_w /= 10;
}
return (numstr);
}
/**
* _sfree - Function to free double pointers
* @i_want_to_be_free: double pointer to be free
*/
void _sfree(char **i_want_to_be_free)
{
int ptr_index;
for (ptr_index = 0; i_want_to_be_free[ptr_index] != NULL; ptr_index++)
{
free(i_want_to_be_free[ptr_index]);
}
free(i_want_to_be_free);
}
/**
* _hack_path - Function to set a . at the begining of a string.
*
* @path: string from buffer
*
* Return: string with a . at the begining of a string.
*/
char *_hack_path(char *path)
{
char *path2 = NULL;
char *path_cpy = NULL;
int i = 0;
path_cpy = _strdup(path); /*Duplico el path en otra variable*/
for (; path[i] != '\0'; i++) /*Para saber el length de Path*/
;
path2 = malloc(sizeof(char) * i + 2);
if (!path2)
{
free(path_cpy);
exit(0);
}
path2[0] = '.';
for (i = 0; path_cpy[i] != '\0'; i++)
{
path2[i + 1] = path_cpy[i];
}
path2[i] = '\0';
free(path_cpy);
return (path2);
}