-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmemory.c
56 lines (53 loc) · 797 Bytes
/
memory.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
54
55
56
#include "shell.h"
/**
* _realloc - check the code.
* @ptr: pointer
* @size : variable.
* Return: pointer.
*/
void *_realloc(void *ptr, unsigned int size)
{
char *new_ptr;
unsigned int i, newest;
if (ptr == NULL)
{
ptr = malloc(size);
return (ptr);
}
if (size > sizeof(ptr))
newest = sizeof(ptr);
if (size == 0)
{
free(ptr);
return (NULL);
}
new_ptr = malloc(size);
if (new_ptr == NULL)
{
perror("ERROR");
exit(1);
}
for (i = 0; i < newest; i++)
new_ptr[i] = ((char *)ptr)[i];
free(ptr);
return (new_ptr);
}
/**
* free_2D - check the code.
* @array: a double pointer
* Return: void.
*/
void free_2D(char **array)
{
int i;
i = 0;
if (array == NULL)
return;
while (array[i] != NULL)
{
free(array[i]);
array[i] = NULL;
i++;
}
free(array);
}