mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 03:16:51 +01:00
「🏗️」 wip(exec/get_path): can get all files in path, only printing for now.
This commit is contained in:
@ -6,13 +6,15 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/29 13:20:22 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/05/06 20:29:58 by mmoussou ### ########.fr */
|
||||
/* Updated: 2024/05/19 04:27:24 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef EXECUTION_H
|
||||
# define EXECUTION_H
|
||||
|
||||
int get_path(char *path);
|
||||
|
||||
typedef struct s_env
|
||||
{
|
||||
char *name;
|
||||
|
@ -18,6 +18,10 @@
|
||||
# include <readline/readline.h>
|
||||
# include <stdlib.h>
|
||||
# include <stdint.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <unistd.h>
|
||||
# include <dirent.h>
|
||||
# include "libft.h"
|
||||
|
||||
# include "parsing.h"
|
||||
|
2
src/env/env_cmd.c
vendored
2
src/env/env_cmd.c
vendored
@ -44,7 +44,6 @@ char **env_get(t_env *env)
|
||||
|
||||
int env_create_first_el(char *env_line, t_env *env)
|
||||
{
|
||||
// t_env *new;
|
||||
char *name;
|
||||
char *content;
|
||||
|
||||
@ -139,7 +138,6 @@ int env_edit(char *name, char *content, t_env *env)
|
||||
|
||||
int env_delete(char *name, t_env *env)
|
||||
{
|
||||
// char *new_content;
|
||||
t_env *tmp;
|
||||
|
||||
while (env && env->next && ft_strcmp(env->next->name, name))
|
||||
|
66
src/exec/get_path.c
Normal file
66
src/exec/get_path.c
Normal file
@ -0,0 +1,66 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_path.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 01:42:17 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/05/19 04:33:52 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int get_path_list(char *path)
|
||||
{
|
||||
DIR *path_dir;
|
||||
struct dirent *dir_entry;
|
||||
char *abs_path;
|
||||
struct stat entry;
|
||||
|
||||
path_dir = opendir(path);
|
||||
if (!path_dir)
|
||||
return (-1);
|
||||
dir_entry = readdir(path_dir);
|
||||
while (dir_entry)
|
||||
{
|
||||
if (!ft_strncmp(dir_entry->d_name, ".", ft_strlen(dir_entry->d_name))
|
||||
|| !ft_strncmp(dir_entry->d_name, "..", ft_strlen(dir_entry->d_name)))
|
||||
{
|
||||
dir_entry = readdir(path_dir);
|
||||
continue ;
|
||||
}
|
||||
abs_path = ft_calloc(sizeof(char), strlen(path) + strlen(dir_entry->d_name) + 1);
|
||||
if (!abs_path)
|
||||
return (-1);
|
||||
strcat(abs_path, path);
|
||||
strcat(abs_path, dir_entry->d_name);
|
||||
stat(abs_path, &entry);
|
||||
if (S_ISREG(entry.st_mode)
|
||||
&& (entry.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
|
||||
printf("%s\n", dir_entry->d_name);
|
||||
free(abs_path);
|
||||
dir_entry = readdir(path_dir);
|
||||
}
|
||||
closedir(path_dir);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int get_path(char *path)
|
||||
{
|
||||
char **path_dir;
|
||||
int i;
|
||||
|
||||
path_dir = ft_split(path, ':');
|
||||
if (!path_dir)
|
||||
return (-1);
|
||||
i = 0;
|
||||
while (path_dir[i])
|
||||
{
|
||||
get_path_list(path_dir[i]);
|
||||
i++;
|
||||
}
|
||||
ft_free("a", &path_dir);
|
||||
return (0);
|
||||
}
|
Reference in New Issue
Block a user