-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell_error_00.c
88 lines (70 loc) · 1.15 KB
/
shell_error_00.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
#include "shell.h"
/* rayesyounes - spoutnikrs */
/**
* putin_str - prints input string
* @str: string printed
* Return: void
*/
void putin_str(char *str)
{
int i = 0;
if (!str)
return;
while (str[i] != '\0')
{
putchar_stdr(str[i]);
i++;
}
}
/**
* putchar_stdr - write char c to stderr
* @c: char to print
* Return: 1 (Success), -1 (Fail)
*/
int putchar_stdr(char c)
{
static int i;
static char buffer[WRITE_BUF_SIZE];
if (c == BUF_FLUSH || i >= WRITE_BUF_SIZE)
{
write(2, buffer, i);
i = 0;
}
if (c != BUF_FLUSH)
buffer[i++] = c;
return (1);
}
/**
* put_fd - write char c to a given fd
* @c: char to print
* @fd: fd to write
* Return: 1 (Success), -1 (Fail)
*/
int put_fd(char c, int fd)
{
static int i;
static char buffer[WRITE_BUF_SIZE];
if (c == BUF_FLUSH || i >= WRITE_BUF_SIZE)
{
write(fd, buffer, i);
i = 0;
}
if (c != BUF_FLUSH)
buffer[i++] = c;
return (1);
}
/**
* putin_sfd - print input string
* @str: string to print
* @fd: fd to write
* Return: number of char
*/
int putin_sfd(char *str, int fd)
{
int i = 0;
if (!str)
return (0);
while (*str)
i += put_fd(*str++, fd);
return (i);
}