-
Notifications
You must be signed in to change notification settings - Fork 3
/
errors1.c
85 lines (77 loc) · 1.37 KB
/
errors1.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
* @string: the string tht is to be printed
*
* Return: Nothing
*/
void _eputs(char *string)
{
int j = 0;
if (!string)
return;
while (string[j] != '\0')
{
_eputchar(string[j]);
j++;
}
}
/**
* _eputchar - function that writes the char d to stderr
* @d: The character to written
*
* Return: On success 1.
* On error, -1 is returned, and errno printed.
*/
int _eputchar(char d)
{
static int j;
static char buf[WRITE_BUF_SIZE];
if (d == BUF_FLUSH || j >= WRITE_BUF_SIZE)
{
write(2, buf, j);
j = 0;
}
if (d != BUF_FLUSH)
buf[j++] = d;
return (1);
}
/**
* _putfd - function tht writes the character d to fd
* @d: character to be printed
* @fd: filedescriptor to write to or modify
*
* Return: On success 1.
* On error, -1 is returned, and errno is returned.
*/
int _putfd(char d, int fd)
{
static int j;
static char buf[WRITE_BUF_SIZE];
if (d == BUF_FLUSH || j >= WRITE_BUF_SIZE)
{
write(fd, buf, j);
j = 0;
}
if (d != BUF_FLUSH)
buf[j++] = d;
return (1);
}
/**
*_putsfd -function tht prints input string
* @string: the string to print
* @fd: filedescriptor to write or modify
*
* Return: the number of chars put
*/
int _putsfd(char *string, int fd)
{
int j = 0;
if (!string)
return (0);
while (*string)
{
j += _putfd(*string++, fd);
}
return (j);
}