-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrealloc.c
More file actions
94 lines (88 loc) · 1.49 KB
/
realloc.c
File metadata and controls
94 lines (88 loc) · 1.49 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
86
87
88
89
90
91
92
93
#include "shell.h"
/**
* check_cmd - check cmd
* @f: struct
* @p: file path
* Return: zero or one
*/
int check_cmd(type_info *f, char *p)
{
struct stat s;
(void)f;
if (!p || stat(p, &s))
return (0);
if (s.st_mode & S_IFREG)
{
return (1);
}
return (0);
}
/**
* chDuplicate - used in duplicating
* @stringPath: path
* @st: index of start
* @sp: index of stop
* Return: address
*/
char *chDuplicate(char *stringPath, int st, int sp)
{
int m = 0, n = 0;
static char BF[1024];
for (n = 0, m = st; m < sp; m++)
if (stringPath[m] != ':')
BF[n++] = stringPath[m];
BF[n] = 0;
return (BF);
}
/**
* our_Memset - like memset function
* @am: area of memory
* @fb: filled byte
* @nb: bytes number
* Return: address
*/
char *our_Memset(char *am, char fb, unsigned int nb)
{
unsigned int index;
for (index = 0; index < nb; index++)
am[index] = fb;
return (am);
}
/**
* ourFreeF - delete strings
* @str: string
*/
void ourFreeF(char **str)
{
char **p = str;
if (!str)
return;
while (*str)
free(*str++);
free(p);
}
/**
* our_Realloc - like realloc function
* @ppp: the pointer
* @os: old size
* @ns: new size
* Return: address
*/
void *our_Realloc(void *ppp, unsigned int os, unsigned int ns)
{
char *pointer;
if (!ppp)
return (malloc(ns));
if (!ns)
return (free(ppp), NULL);
if (ns == os)
return (ppp);
pointer = malloc(ns);
if (!pointer)
return (NULL);
os = os < ns ? os : ns;
while (os--)
pointer[os] = ((char *)ppp)[os];
free(ppp);
return (pointer);
}