Fixed stuff
This commit is contained in:
parent
be1d3ff2d3
commit
f4e8596f3b
15 changed files with 130 additions and 103 deletions
|
|
@ -111,5 +111,9 @@ void insert_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ key,
|
|||
prev->next = entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
hmap->drop(entry->kv);
|
||||
entry->kv.key = key;
|
||||
entry->kv.val = value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,18 +34,9 @@ t_vec_buf_str vec_buf_str_new(t_usize capacity,
|
|||
/// Return true in case of an error
|
||||
t_error vec_buf_str_push(t_vec_buf_str *vec, t_buffer_str element)
|
||||
{
|
||||
size_t new_capacity;
|
||||
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
if (vec->len + 1 > vec->capacity)
|
||||
{
|
||||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (vec->len + 1 > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_buffer_str));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
vec_buf_str_reserve(vec, vec->len + 1);
|
||||
vec->buffer[vec->len] = element;
|
||||
vec->len += 1;
|
||||
return (NO_ERROR);
|
||||
|
|
|
|||
|
|
@ -34,18 +34,9 @@ t_vec_str vec_str_new(t_usize capacity,
|
|||
/// Return true in case of an error
|
||||
t_error vec_str_push(t_vec_str *vec, t_str element)
|
||||
{
|
||||
size_t new_capacity;
|
||||
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
if (vec->len + 1 > vec->capacity)
|
||||
{
|
||||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (vec->len + 1 > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_str));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
vec_str_reserve(vec, vec->len + 1);
|
||||
vec->buffer[vec->len] = element;
|
||||
vec->len += 1;
|
||||
return (NO_ERROR);
|
||||
|
|
|
|||
|
|
@ -34,18 +34,9 @@ t_vec_u8 vec_u8_new(t_usize capacity,
|
|||
/// Return true in case of an error
|
||||
t_error vec_u8_push(t_vec_u8 *vec, t_u8 element)
|
||||
{
|
||||
size_t new_capacity;
|
||||
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
if (vec->len + 1 > vec->capacity)
|
||||
{
|
||||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (vec->len + 1 > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_u8));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
vec_u8_reserve(vec, vec->len + 1);
|
||||
vec->buffer[vec->len] = element;
|
||||
vec->len += 1;
|
||||
return (NO_ERROR);
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/16 17:52:12 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 15:33:43 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/18 18:06:37 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/buffered_str/buf_str.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/string/str_l_cat.h"
|
||||
#include "me/string/str_len.h"
|
||||
|
|
@ -27,11 +28,15 @@ t_error str_reserve(t_buffer_str *buf, t_usize size)
|
|||
return (ERROR);
|
||||
if (buf->capacity >= size)
|
||||
return (NO_ERROR);
|
||||
while (size > buf->capacity)
|
||||
new_capacity = (buf->capacity * 3) / 2 + 1;
|
||||
temp_buffer = mem_realloc_array(buf->buf, new_capacity, sizeof(char));
|
||||
new_capacity = buf->capacity;
|
||||
while (size > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
temp_buffer = mem_alloc_array(new_capacity, sizeof(char));
|
||||
if (temp_buffer == NULL)
|
||||
return (ERROR);
|
||||
mem_set_zero(temp_buffer, new_capacity);
|
||||
mem_copy(temp_buffer, buf->buf, buf->len);
|
||||
mem_free(buf->buf);
|
||||
buf->buf = temp_buffer;
|
||||
buf->capacity = new_capacity;
|
||||
return (NO_ERROR);
|
||||
|
|
@ -46,8 +51,8 @@ t_error push_str_buffer(t_buffer_str *buf, t_const_str to_push)
|
|||
to_push_len = str_len(to_push);
|
||||
if (str_reserve(buf, buf->len + to_push_len + 2))
|
||||
return (ERROR);
|
||||
buf->len += to_push_len;
|
||||
str_l_cat(buf->buf, to_push, buf->capacity);
|
||||
buf->len += to_push_len;
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/14 18:26:27 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/16 16:24:54 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/18 18:48:25 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,6 +26,7 @@ t_allocator *global_allocator(void)
|
|||
{
|
||||
init = true;
|
||||
global_alloc = m_init();
|
||||
// global_alloc = lc_init();
|
||||
}
|
||||
return (&global_alloc);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,16 +6,16 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/03 16:22:41 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 18:42:59 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/18 18:33:53 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/buffered_str/buf_str.h"
|
||||
#include "me/os/pipe.h"
|
||||
#include "me/os/process.h"
|
||||
#include "me/buffered_str/buf_str.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/os/pipe.h"
|
||||
#include "me/string/str_find_chr.h"
|
||||
#include "me/string/str_n_compare.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/string/str_split.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
|
|
@ -23,14 +23,14 @@
|
|||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
bool find_path(const t_str *s);
|
||||
bool find_null(const t_str *s);
|
||||
bool str_start_with(t_const_str s, t_const_str prefix);
|
||||
t_error handle_redirections(t_spawn_info *info, t_process *process);
|
||||
bool find_path(const t_str *s);
|
||||
bool find_null(const t_str *s);
|
||||
bool str_start_with(t_const_str s, t_const_str prefix);
|
||||
t_error handle_redirections(t_spawn_info *info, t_process *process);
|
||||
|
||||
t_error spawn_process_exec(t_spawn_info info, t_process *process)
|
||||
t_error spawn_process_exec(t_spawn_info info, t_process *process)
|
||||
{
|
||||
bool res;
|
||||
bool res;
|
||||
|
||||
if (info.forked_free)
|
||||
info.forked_free(info.forked_free_args);
|
||||
|
|
@ -52,11 +52,11 @@ t_error spawn_process_exec(t_spawn_info info, t_process *process)
|
|||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error in_path(t_spawn_info *info, t_process *process, t_const_str path,
|
||||
t_buffer_str *s)
|
||||
t_error in_path(t_spawn_info *info, t_process *process, t_const_str path,
|
||||
t_buffer_str *s)
|
||||
{
|
||||
t_str *splitted_path;
|
||||
t_usize sp_index;
|
||||
t_str *splitted_path;
|
||||
t_usize sp_index;
|
||||
|
||||
splitted_path = str_split(path + 5, ':');
|
||||
if (splitted_path == NULL)
|
||||
|
|
@ -70,7 +70,7 @@ t_error in_path(t_spawn_info *info, t_process *process, t_const_str path,
|
|||
push_str_buffer(s, info->binary_path);
|
||||
sp_index++;
|
||||
if (access(s->buf, X_OK | R_OK) == 0)
|
||||
break ;
|
||||
break;
|
||||
}
|
||||
sp_index = 0;
|
||||
while (splitted_path[sp_index])
|
||||
|
|
@ -79,22 +79,23 @@ t_error in_path(t_spawn_info *info, t_process *process, t_const_str path,
|
|||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error find_binary(t_spawn_info *info, t_process *process)
|
||||
t_error find_binary(t_spawn_info *info, t_process *process)
|
||||
{
|
||||
t_usize p_idx;
|
||||
t_buffer_str s;
|
||||
t_usize p_idx;
|
||||
t_buffer_str s;
|
||||
|
||||
(void)(process);
|
||||
if (info->binary_path == NULL)
|
||||
return (ERROR);
|
||||
s = alloc_new_buffer(256);
|
||||
if (str_start_with(info->binary_path, "/")
|
||||
|| str_find_chr(info->binary_path, '/') != NULL)
|
||||
if (str_start_with(info->binary_path, "/") ||
|
||||
str_find_chr(info->binary_path, '/') != NULL)
|
||||
push_str_buffer(&s, info->binary_path);
|
||||
else
|
||||
{
|
||||
if (vec_str_find(&info->environement, find_path, &p_idx))
|
||||
return (str_free(s), ERROR);
|
||||
printf("finding in path\n");
|
||||
if (in_path(info, process, info->environement.buffer[p_idx], &s))
|
||||
return (ERROR);
|
||||
}
|
||||
|
|
@ -107,7 +108,7 @@ t_error find_binary(t_spawn_info *info, t_process *process)
|
|||
return (str_free(s), ERROR);
|
||||
}
|
||||
|
||||
static void cleanup(t_spawn_info info, t_process *process, bool cleanup_process)
|
||||
static void cleanup(t_spawn_info info, t_process *process, bool cleanup_process)
|
||||
{
|
||||
if (cleanup_process && process->stdin.tag != INVALID)
|
||||
close(process->stdin.vals.ro.fd);
|
||||
|
|
@ -123,7 +124,7 @@ static void cleanup(t_spawn_info info, t_process *process, bool cleanup_process)
|
|||
mem_free(info.binary_path);
|
||||
}
|
||||
|
||||
t_error spawn_process(t_spawn_info info, t_process *process)
|
||||
t_error spawn_process(t_spawn_info info, t_process *process)
|
||||
{
|
||||
if (handle_redirections(&info, process))
|
||||
return (cleanup(info, process, true), ERROR);
|
||||
|
|
|
|||
|
|
@ -6,19 +6,20 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/04 22:25:44 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/09 16:57:24 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/05/18 18:38:01 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
bool find_null(const t_str *s)
|
||||
bool find_null(const t_str *s)
|
||||
{
|
||||
return (s == NULL);
|
||||
}
|
||||
|
||||
bool str_start_with(t_const_str s, t_const_str prefix)
|
||||
bool str_start_with(t_const_str s, t_const_str prefix)
|
||||
{
|
||||
while (*prefix && *s)
|
||||
{
|
||||
|
|
@ -28,9 +29,14 @@ bool str_start_with(t_const_str s, t_const_str prefix)
|
|||
return (*prefix == '\0');
|
||||
}
|
||||
|
||||
bool find_path(const t_str *s)
|
||||
bool find_path(const t_str *s)
|
||||
{
|
||||
t_str ss;
|
||||
|
||||
if (*s == NULL)
|
||||
return (false);
|
||||
return (str_start_with(*s, "PATH="));
|
||||
ss = *s;
|
||||
printf("%s\n", ss);
|
||||
return (ss[0] == 'P' && ss[1] == 'A' && ss[2] == 'T' && ss[3] == 'H' &&
|
||||
ss[4] == '=');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue