mirror of
https://github.com/Ladebeze66/minishell.git
synced 2026-11-09 13:47:17 +01:00
minishell
This commit is contained in:
49
utils/utils.c
Executable file
49
utils/utils.c
Executable file
@@ -0,0 +1,49 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/01 17:49:16 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/07 16:00:03 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
int is_only_spaces(const char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
if (*str != ' ' && *str != '\t')
|
||||
return (0);
|
||||
str++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
char *get_env_value(const char *key, char **environ)
|
||||
{
|
||||
int i;
|
||||
char *entry;
|
||||
char *delim;
|
||||
|
||||
if (!key || !environ)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
entry = environ[i];
|
||||
while (entry != NULL)
|
||||
{
|
||||
delim = strchr(entry, '=');
|
||||
if (delim != NULL)
|
||||
{
|
||||
if (ft_strncmp(entry, key, delim - entry)
|
||||
== 0 && ft_strlen(key) == (size_t)(delim - entry))
|
||||
return (delim + 1);
|
||||
}
|
||||
i++;
|
||||
entry = environ[i];
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
Reference in New Issue
Block a user