-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfree.c
More file actions
46 lines (45 loc) · 885 Bytes
/
free.c
File metadata and controls
46 lines (45 loc) · 885 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
46
#include "hsh.h"
/**
* restore_std_in_out - restores stdin/out after redirect
* @info: the parameter struct
*/
void restore_std_in_out(info_t *info)
{
if (info->dup_stdin)
{
dup2(info->dup_stdin, STDIN_FILENO);
close(info->dup_stdin);
info->dup_stdin = 0;
}
if (info->dup_stderr)
{
dup2(info->dup_stderr, STDERR_FILENO);
close(info->dup_stderr);
info->dup_stderr = 0;
}
if (info->dup_stdout)
{
dup2(info->dup_stdout, STDOUT_FILENO);
close(info->dup_stdout);
info->dup_stdout = 0;
}
info->ident = 0, info->identcomment = 0;
info->read_inPipe = 0;
info->write_inPipe = 0;
info->condition = 1;
}
/**
* free_info - frees info_t struct fields
* @info: struct address
* @all: true if freeing all fields
*/
void free_info(info_t *info, int all)
{
if (all)
{
if (info->readfd > 2)
close(info->readfd);
__getline(-1);
_putchar(BUF_FLUSH);
}
}