-
Notifications
You must be signed in to change notification settings - Fork 3
/
errores_env.c
117 lines (109 loc) · 2.09 KB
/
errores_env.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
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
116
117
#include "holberton.h"
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <dirent.h>
#define MAX 500
/**
* imprimir_error_env - print errors env builtin.
* @h: the list of elements
*
* Return: direction of the new node
*/
void imprimir_error_env(command_t *h)
{
int l1 = 0;
char *sp = ": ";
char *com = NULL;
char *filename = NULL;
char *msg = ": No such file or directory";
char sl = '\n';
int a = 127;
com = h->args[0];
filename = h->args[1];
l1 = _strlen(com);
write(1, com, l1);
write(1, sp, 2);
l1 = _strlen(filename);
write(1, filename, l1);
l1 = _strlen(msg);
write(1, msg, l1);
write(1, &sl, 1);
setstatus(&a);
}
/**
* search_file_env - search file name.
* @h: the list of elements
*
* Return: o or -1 if it fails
*/
int search_file_env(command_t *h)
{
char **filename = NULL;
int n = 0;
struct stat buf;
filename = h->args;
n = stat(filename[1], &buf);
printf("%d", n);
if (n == -1)
imprimir_error_env(h);
return (0);
}
/**
* imprimir_error_setenv - print error setenv
* @h: the list of elements
*
* Return: no return
*/
void imprimir_error_setenv(command_t *h)
{
int l1 = 0;
char *sp = ": ";
char *com = NULL;
char *variable = NULL;
char *msg = ": Variable not found";
char sl = '\n';
int a = 1;
com = h->args[0];
variable = h->args[1];
l1 = _strlen(com);
write(1, com, l1);
write(1, sp, 2);
l1 = _strlen(variable);
write(1, variable, l1);
l1 = _strlen(msg);
write(1, msg, l1);
write(1, &sl, 1);
setstatus(&a);
}
/**
* imprimir_error_unsetenv - print unsetenv errors
* @h: pointer ti the head of the linked list
*
* Return: no return
*/
void imprimir_error_unsetenv(command_t *h)
{
int l1 = 0;
char *sp = ": ";
char *com = NULL;
char *variable = NULL;
char *msg = ": Variable not found";
char sl = '\n';
int a = 1;
com = h->args[0];
variable = h->args[1];
l1 = _strlen(com);
write(1, com, l1);
write(1, sp, 2);
l1 = _strlen(variable);
write(1, variable, l1);
l1 = _strlen(msg);
write(1, msg, l1);
write(1, &sl, 1);
setstatus(&a);
}