-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper_functions.c
53 lines (49 loc) · 886 Bytes
/
helper_functions.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
#include "shell.h"
#include <stddef.h>
/**
* _memcpy - copy n bytes from memory area src to dest
* @dest: pointer to destination memory area
* @src: pointer to source memory area
* @n: number of bytes to copy
* Return: pointer to destination memory area
*/
void *_memcpy(void *dest, const void *src, size_t n)
{
size_t i;
char *dest_c = (char *)dest;
const char *src_c = (const char *)src;
for (i = 0; i < n; i++)
{
dest_c[i] = src_c[i];
}
return (dest);
}
/**
* _atoi - convert string to int
* @str: pointer to string to convert
* Return: the converted int value
*/
int _atoi(const char *str)
{
int result = 0;
int sign = 1;
if (*str == '-')
{
sign = -1;
str++;
}
else if (*str == '+')
{
str++;
}
while (*str != '\0')
{
if (*str < '0' || *str > '9')
{
break;
}
result = result * 10 + (*str - '0');
str++;
}
return (result * sign);
}