-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_2.c
More file actions
85 lines (78 loc) · 1.37 KB
/
Copy pathutils_2.c
File metadata and controls
85 lines (78 loc) · 1.37 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
#include "main.h"
/**
* _strdup - Creates a duplicate of a given string
* @str: String to duplicate
* Return: Duplicate of @str
*/
char *_strdup(char *str)
{
size_t len;
char *dup;
if (!str)
return (NULL);
len = _strlen(str);
dup = malloc(len + 1);
if (!dup)
return (NULL);
return (_strcpy(dup, str));
}
/**
* _strcat - concatenates two strings
* @dest: string to append to
* @src: string to append to dest
* Return: dest
*/
char *_strcat(char *dest, char *src)
{
char *str;
str = dest;
while (*dest)
dest++;
while (*src)
*dest++ = *src++;
*dest = '\0';
return (str);
}
/**
* _isdigit - Checks if argument is a digit
*
* @c: character to use for comparison
*
* Return: returns 1 if c is a digit, 0 if not
*/
int _isdigit(int c)
{
c = (unsigned char)c;
return (c >= '0' && c <= '9' ? 1 : 0);
}
/**
* _atoi - converts string into an integer
* @s: string to convert
* Return: integer format of string
*/
int _atoi(const char *s)
{
int sign;
int nb;
nb = 0;
sign = 1;
while (*s && (*s < '0' || *s > '9'))
{
if (*s == '-')
sign *= -1;
s++;
}
while (*s >= '0' && *s <= '9')
{
if ((nb == -214748364 && *s == '9') || nb < -2141748364)
break;
if ((nb == 214748364 && *s >= '8') || nb > 2141748364)
break;
if (sign == 1)
nb = nb * 10 + (*s - '0');
else if (sign == -1)
nb = nb * 10 - (*s - '0');
s++;
}
return (nb);
}