-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_f.c
More file actions
71 lines (62 loc) · 1.1 KB
/
Copy pathmemory_f.c
File metadata and controls
71 lines (62 loc) · 1.1 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
#include "shell.h"
/**
* _memcpy - Copy from memory string of buffer
* @dest: pointer to the destination string
* @src: pointer to the source
* @n: number of bytes to copy
* Return: Pointer to the memory area (src)
*/
char *_memcpy(char *dest, const char *src, unsigned int n)
{
unsigned int i;
for (i = 0; n--; i++)
dest[i] = src[i];
return (dest);
}
/**
* _memset - Fill a string with some characters
* @s: pointer to the string
* @c: character to use
* @n: number of times
* Return: Pointer to the memory area (s)
*/
char *_memset(char *s, char c, unsigned int n)
{
unsigned int i = 0;
if (!s)
return (NULL);
while (i < n)
{
s[i] = c;
i++;
}
return (s);
}
/**
* free_ptr - free pointers and set their address to NULL
* @p: address of the pointer to be freed
* Return: 1 on success, 0 otherwise.
*/
int free_ptr(void **p)
{
if (p && *p)
{
free(*p);
*p = NULL;
return (1);
}
return (0);
}
/**
* free_str - free a string
* @arr: pointer to pointer of string
*/
void free_str(char **arr)
{
int i = 0;
if (!arr)
return;
while (arr[i])
free(arr[i++]);
free(arr);
}