-
Notifications
You must be signed in to change notification settings - Fork 1
/
read.c
77 lines (63 loc) · 1.33 KB
/
read.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "main.h"
/**
* _strconcat - Concatenate two strings reserving memory allocation.
* @str_1: fist string to concatenate.
* @str_2: second string to concatenate.
* Return: the string (*copy) concatenated.
*/
char *_strconcat(char *str_1, char *str_2)
{
int size = _strlen(str_1) + _strlen(str_2) + 1;
char *temporal = NULL;
char *copy = malloc(sizeof(char *) * size);
if (!copy)
return (NULL);
temporal = copy;
while (*str_1)
*temporal++ = *str_1++;
while (*str_2)
*temporal++ = *str_2++;
*temporal = '\0';
return (copy);
}
/**
* _strcpy - Copy a string reserving memory allocation.
* @src: string to copy.
* @dest: string copied.
* Return: string (*dest) copied.
*/
char *_strcpy(char *dest, char *src)
{
int size = _strlen(src) + 1;
int counter = 0;
dest = malloc(sizeof(char *) * size);
if (!dest)
return (NULL);
while (src[counter])
{
dest[counter] = src[counter];
counter++;
}
dest[counter] = src[counter];
return (dest);
}
/**
* _getPATH - Find PATH directory of a Unix-OS
* @void: no arguments to pass.
* Return: a string with the PATH directory.
*/
char *_getPATH(void)
{
int counter = 0;
char *path = NULL;
while (environ[counter])
{
if (_strcmp(environ[counter], "PATH=") == 0)
{
path = _strcpy(NULL, environ[counter] + 6);
return (path);
}
counter++;
}
return (NULL);
}