forked from alzheimeer/shell_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunauxiliares2.c
More file actions
43 lines (38 loc) · 815 Bytes
/
funauxiliares2.c
File metadata and controls
43 lines (38 loc) · 815 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
#include "hsh.h"
/**
* _realloc - reallocates a block of memory
* @ptr: pointer to previous malloc'ated block
* @old_size: byte size of previous block
* @new_size: byte size of new block
* Return: pointer to da ol'block nameen.
*/
void *_realloc(void *ptr, unsigned int old_size, unsigned int new_size)
{
char *p;
if (!ptr)
return (malloc(new_size));
if (!new_size)
return (free(ptr), NULL);
if (new_size == old_size)
return (ptr);
p = malloc(new_size);
if (!p)
return (NULL);
old_size = old_size < new_size ? old_size : new_size;
while (old_size--)
p[old_size] = ((char *)ptr)[old_size];
free(ptr);
return (p);
}
/**
* _strtoken - count tokens
* @tokens: tokens
* Return: number of tokens
*/
int _strtoken(char **tokens)
{
int i;
for (i = 0; tokens[i]; i++)
{}
return (i);
}