-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printerrors.c
More file actions
59 lines (55 loc) · 865 Bytes
/
_printerrors.c
File metadata and controls
59 lines (55 loc) · 865 Bytes
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
#include "main.h"
/**
*_errputs - prints an input string
* @s: print s to stderr
*
* Return: Nothing
*/
void _errputs(char *s)
{
int i = 0;
if (!s)
return;
while (s[i] != '\0')
{
_errputchar(s[i]);
i++;
}
}
/**
* _errputchar - 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 _errputchar(char c)
{
return (write(2, &c, 1));
}
/**
* _errtoi - converts a string to integer
* @s: string
*
* Return: 0 if no found numbers in string, converted number otherwise
*/
int _errtoi(char *s)
{
int i = 0;
unsigned long int res = 0;
if (*s == '+')
s++;
for (i = 0; s[i] != '\0'; i++)
{
if (s[i] >= '0' && s[i] <= '9')
{
res *= 10;
res += (s[i] - '0');
if (res > INT_MAX)
return (-1);
}
else
return (-1);
}
return (res);
}