-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_error1.c
More file actions
87 lines (73 loc) · 1.65 KB
/
Copy path_error1.c
File metadata and controls
87 lines (73 loc) · 1.65 KB
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
#include "shell.h"
/**
* _eputchar - Function writes character c to stderr
* @c: The character to printed
* Return: On success 1, on error, -1 is returned,
* and errno is set appropriately.
*/
int _eputchar(char c)
{
static int buffer_index;
static char buffer[WRITE_BUF_SIZE];
if (c == BUF_FLUSH || buffer_index >= WRITE_BUF_SIZE)
{
write(2, buffer, buffer_index);
buffer_index = 0;
}
if (c != BUF_FLUSH)
buffer[buffer_index++] = c;
return (1);
}
/**
* _eputs - Function prints a string to stderr
* @str: The string to be printed
* Return: Void
*/
void _eputs(char *str)
{
int index = 0;
if (!str)
return;
while (str[index] != '\0')
{
_eputchar(str[index]);
index++;
}
}
/**
* _putFileDescriptor - Function writes the character c to the given fd
* @c: The character to be printed
* @fileDescriptor: The file descriptor to write to
* Return: On success 1, on error, -1 is returned, and errno is set
* appropriately.
*/
int _putFileDescriptor(char c, int fileDescriptor)
{
static int buffer_index;
static char buffer[WRITE_BUF_SIZE];
if (c == BUF_FLUSH || buffer_index >= WRITE_BUF_SIZE)
{
write(fileDescriptor, buffer, buffer_index);
buffer_index = 0;
}
if (c != BUF_FLUSH)
buffer[buffer_index++] = c;
return (1);
}
/**
* _putsFileDescriptor - prints a string to the given file descriptor
* @str: The string to be printed
* @fileDescriptor: The file descriptor to write to
* Return: Return the number of characters put
*/
int _putsFileDescriptor(char *str, int fileDescriptor)
{
int count = 0;
if (!str)
return (0);
while (*str)
{
count += _putFileDescriptor(*str++, fileDescriptor);
}
return (count);
}