diff options
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | src/b_sqb.c | 11 | ||||
| -rw-r--r-- | src/b_sqb_file.c | 39 | ||||
| -rw-r--r-- | src/b_sqb_file.h | 20 | 
4 files changed, 66 insertions, 5 deletions
| @@ -24,6 +24,7 @@ SRCS_NAME		+= b_export_next  SRCS_NAME		+= b_export_mute  SRCS_NAME		+= b_pwd  SRCS_NAME		+= b_sqb +SRCS_NAME		+= b_sqb_file  SRCS_NAME		+= b_type  SRCS_NAME		+= b_unset  SRCS_NAME		+= e_builtins diff --git a/src/b_sqb.c b/src/b_sqb.c index 90e9b58..438f692 100644 --- a/src/b_sqb.c +++ b/src/b_sqb.c @@ -14,6 +14,7 @@  #include <stdint.h>  #include <unistd.h> +#include "b_sqb_file.h"  #include "d_define.h"  #include "s_struct.h"  #include "u_utils.h" @@ -49,13 +50,12 @@ static uint8_t  }  static uint8_t -	b_eval_sqb(uint64_t argc, -			char *argv[], +	b_eval_sqb(char *argv[],  			t_msh *msh)  {  	uint8_t	id; +	uint8_t	ret; -	(void)argc;  	id = b_get_sqb_id(argv, msh);  	if (id == FT_ID_SQB_COUNT)  	{ @@ -63,9 +63,10 @@ static uint8_t  		return (2);  	}  	/* TODO: check errors */ +	ret = 0;  	if (id < FT_ID_SQB_NT && id != FT_ID_SQB_Z && id != FT_ID_SQB_N) -		ft_printf("%s\n", msh->sqb_ref[id]); -	return (0); +		ret = b_sqb_file_tests(id, argv); +	return (ret);  }  uint8_t diff --git a/src/b_sqb_file.c b/src/b_sqb_file.c new file mode 100644 index 0000000..d6d07e0 --- /dev/null +++ b/src/b_sqb_file.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/*                                                                            */ +/*                                                        :::      ::::::::   */ +/*   b_sqb_file.c                                       :+:      :+:    :+:   */ +/*                                                    +:+ +:+         +:+     */ +/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */ +/*                                                +#+#+#+#+#+   +#+           */ +/*   Created: 2020/02/14 17:19:27 by rbousset          #+#    #+#             */ +/*   Updated: 2020/02/14 17:19:29 by rbousset         ###   ########lyon.fr   */ +/*                                                                            */ +/* ************************************************************************** */ + +#include <sys/stat.h> +#include <stdint.h> + +static uint8_t +	b_file_tests_one(uint8_t id, +					struct stat *st) +{ +	if (id == FT_ID_SQB_B && S_st->st_mode) +	return (0); +} + +uint8_t +	b_sqb_file(uint8_t id, +			char *argv[]) +{ +	struct stat	st; +	int32_t	fd; +	uint8_t	ret; + +	ret = 0; +	if ((fd = open(argv[1])) == -1) +		return (1); +	fstat(fd, &st); +	ret = b_file_tests_one(id, &st); +	close(fd); +	return (ret); +} diff --git a/src/b_sqb_file.h b/src/b_sqb_file.h new file mode 100644 index 0000000..d048fd1 --- /dev/null +++ b/src/b_sqb_file.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/*                                                                            */ +/*                                                        :::      ::::::::   */ +/*   b_sqb_file.h                                       :+:      :+:    :+:   */ +/*                                                    +:+ +:+         +:+     */ +/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */ +/*                                                +#+#+#+#+#+   +#+           */ +/*   Created: 2020/02/14 17:19:27 by rbousset          #+#    #+#             */ +/*   Updated: 2020/02/14 17:19:29 by rbousset         ###   ########lyon.fr   */ +/*                                                                            */ +/* ************************************************************************** */ + +#ifndef B_SQB_FILE_H +#define B_SQB_FILE_H + +#include <stdint.h> + +uint8_t	b_sqb_file(uint8_t id, char *argv[]); + +#endif | 
