-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_errors.c
91 lines (79 loc) · 1.62 KB
/
string_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
86
87
88
89
90
91
#include "shell.h"
/**
* put_fd - writes c to the file_descriptor given
* @c: The charcter to be printe
* @file_descriptor: the file to write to
*
* Return: 1 on success, -1 on failure
*/
int put_fd(char c, int file_descriptor)
{
static int i;
static char buffer[MAX_BUFFER_SIZE];
if (c == BUFFER_FLUSH_CONDITION || MAX_BUFFER_SIZE <= i)
{
write(file_descriptor, buffer, i);
i = 0;
}
if (c != BUFFER_FLUSH_CONDITION)
{
buffer[i++] = c;
}
return (1);
}
/**
* _puts_fd - like _puts it uses put_fd to write to the file
* @string: The string
* @file_descriptor: The file to write to
*
* Return: The number of characters
*/
int _puts_fd(char *string, int file_descriptor)
{
int i = 0;
if (string == NULL)
return (0);
while (*string != '\0')
{
i = i + put_fd(*string, file_descriptor);
string = string + 1;
}
return (i);
}
/**
* _errorputchar - A function to print errors
* to the standard error
* @myChar: The char to be printed to the standard error
*
* Return: The number of the chars that was printed
*/
int _errorputchar(char myChar)
{
static int i;
static char buffer[MAX_BUFFER_SIZE];
if (myChar == BUFFER_FLUSH_CONDITION || MAX_BUFFER_SIZE <= i)
{
write(STDERR_FILENO, buffer, i); /*STDERR_FILENO*/
i = 0;
}
if (myChar != BUFFER_FLUSH_CONDITION)
{
buffer[i++] = myChar;
}
return (1);
}
/**
* _errorputschar - A function to put a string on the
* standard error
* @myString: A pointer to the string that will be
* printed to the standard error
*
* Return: Nothing (void)
*/
void _errorputschar(char *myString)
{
if (!myString)
return;
while (*myString)
_errorputchar(*myString++);
}