-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.c
68 lines (61 loc) · 1.03 KB
/
utils.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
#include "shell.h"
/**
* get_index - Get index of the first occurence of char =
* @s: String to check
* Return: Index
*/
int get_index(char *s)
{
int i = 0;
if (s == NULL)
return (0);
while (s[i])
{
if (s[i] == '=')
return (i);
i++;
}
return (0);
}
/**
* is_number - a function that checks if the command input is a number
* @s: the command to be checked
* Return: 0
*/
int is_number(char *s)
{
while (*s)
{
if (*s < '0' || *s > '9')
return (0);
s++;
}
return (1);
}
/**
* new_free - Free some block of memory
* @data: data where memory is stored
*/
void new_free(data_t *data)
{
free(data->token);
free(data->linearg);
free_list(data->envp);
}
/**
* get_dir_path - returns a path from the env
* @envp: env pointer
* @env: env
* Return: dir path
*/
char *get_dir_path(list_t *envp, char *env)
{
list_t *tmp = envp;
while (tmp)
{
if (_strncmp(tmp->str, env, _strlen(env)) == 0)
return (tmp->str + _strlen(env) + 1);
tmp = tmp->next;
}
return (NULL); /*This should never be evecuted*/
}