-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcp_file.c
More file actions
45 lines (44 loc) · 837 Bytes
/
cp_file.c
File metadata and controls
45 lines (44 loc) · 837 Bytes
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
#include "shell.h"
/**
* print_env - prints enviromental variables
* @i: aux
* Return: Always 0.
*/
int print_env(int i)
{
int file_from, j = 0, k = 0, brk = 0;
ssize_t l_read = 1024, l_write, close_file;
char content[1024];
file_from = open("env_file", O_RDONLY);
if (file_from == -1)
return (-1);
while (brk == 0)
{
l_read = read(file_from, content, 1024);
if (l_read == -1)
return (-1);
if (l_read != 1024)
brk = 1;
if (i == 1)
{
for (j = 0, k = 0; content[j]; j++)
{
if (content[j] == '\n')
{
for (k = j; content[j]; j++)
content[j] = content[j + 1];
l_read--;
j = k;
}
}
j = k;
}
l_write = write(STDOUT_FILENO, content, l_read);
if (l_write == -1)
return (-1);
}
close_file = close(file_from);
if (close_file == -1)
return (-1);
return (0);
}