-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings2.c
More file actions
38 lines (34 loc) · 901 Bytes
/
Copy pathstrings2.c
File metadata and controls
38 lines (34 loc) · 901 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
#include "main.h"
#include <stdlib.h>
/**
* _strdup - duplicate of a string to a newly alloacted memory
* @str: pointer to a string
* Return: pointer to duplicated string
*/
char *_strdup(char *str)
{
char *destination = NULL;
unsigned int ln = 0;
if (str == NULL)
return (NULL);
ln = _strlen(str) + 1;
destination = malloc(sizeof(char) * ln);
if (destination == NULL)
return (NULL);
destination = _memcpy(destination, str, ln);
return (destination);
}
/**
* _memcpy - copies n characters from existing memory src to memory destination
* @dest: pointer to the destination memory area where content is to be copied
* @src: pointer to the source of memory to be copied
* @n: the num bytes to be copied
* Return: Pointer to destination
*/
char *_memcpy(char *dest, char *src, unsigned int n)
{
unsigned int c = 0;
for (c = 0; c < n; c++)
dest[c] = src[c];
return (dest);
}