-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.c
86 lines (77 loc) · 1.34 KB
/
errors.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
#include "shell.h"
/**
* _eputs - function that prints an input string
* @str: the string to be printed
*
* Return: Nothing
*/
void _eputs(char *str)
{
int j = 0;
if (!str)
return;
while (str[j] != '\0')
{
_eputchar(str[j]);
j++;
}
}
/**
* _eputchar - writes the character c to stderr
* @c: The character to print
*
* Return: On success 1.
* On error, -1 is returned, and errno is set appropriately.
*/
int _eputchar(char c)
{
static int j;
static char buf[WRITE_BUF_SIZE];
if (c == BUF_FLUSH || j >= WRITE_BUF_SIZE)
{
write(2, buf, j);
j = 0;
}
if (c != BUF_FLUSH)
buf[j++] = c;
return (1);
}
/**
* _putfdsc - writes the character c to given fd
* @c: The character to print
* @fdsc: The filedescriptor to write to
*
* Return: On success 1.
* On error, -1 is returned, and errno is set appropriately.
*/
int _putfdsc(char c, int fdsc)
{
static int j;
static char buf[WRITE_BUF_SIZE];
if (c == BUF_FLUSH || j >= WRITE_BUF_SIZE)
{
write(fdsc, buf, j);
j = 0;
}
if (c != BUF_FLUSH)
buf[j++] = c;
return (1);
}
/**
* _putsfdsc - prints an input string
* @str: the string to be printed
* @fdsc: the filedescriptor to write to
*
* Return: the number of chars put
*/
int _putsfdsc(char *str, int fdsc)
{
int j = 0;
if (!str)
return (0);
while (*str)
{
j += _putfdsc(*str++, fdsc);
}
return (j);
}