-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_write.c
52 lines (48 loc) · 819 Bytes
/
_write.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
#include "shell.h"
/**
* _write - write to field descriptor
* @fd: field descriptor
* @inp: string to write
* @len: number of chars in string
*
* Return: -100 when no queue, 100 when sucessfully write to
*/
int _write(int fd, char *inp, int len)
{
static char writeque[BUFFER_t];
static int nque;
int i;
if (fd < 0)
{
nque = 0;
return (-100);
}
if (inp)
{
if ((len + nque) >= BUFFER_t)
{
if (write(fd, writeque, BUFFER_t) == -1)
{
print_error(NULL, NULL, "problem writing");
exit(-1);
}
nque = 0;
}
i = 0;
while (i < len)
{
writeque[nque + i] = inp[i];
i++;
}
writeque[nque + i] = '\0';
nque += len;
return (100);
}
if (!inp)
if (write(fd, writeque, nque) == -1)
{
print_error(NULL, NULL, "problem writing");
exit(-1);
}
return (0);
}