Normed most of the stdme

This commit is contained in:
Maieul BOYER 2024-07-10 18:06:10 +02:00
parent 882d5cb5bb
commit ac5458d42c
No known key found for this signature in database
31 changed files with 149 additions and 617 deletions

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 15:29:38 by maiboyer #+# #+# */
/* Updated: 2024/01/06 18:19:11 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:43:58 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,7 +16,7 @@
t_error me_open(t_const_str path, bool read, bool write, int *file_out)
{
int out;
int flags;
int flags;
flags = 0;
if (read && write)
@ -35,7 +35,7 @@ t_error me_open(t_const_str path, bool read, bool write, int *file_out)
t_error me_open_truncate(t_const_str path, int *file_out)
{
int out;
int flags;
int flags;
unlink(path);
flags = O_WRONLY | O_CREAT | O_TRUNC;
@ -49,7 +49,7 @@ t_error me_open_truncate(t_const_str path, int *file_out)
t_error me_open_create(t_const_str path, int *file_out)
{
int out;
int flags;
int flags;
flags = O_WRONLY | O_CREAT | O_APPEND;
out = open(path, flags, 0666);

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 18:38:47 by maiboyer #+# #+# */
/* Updated: 2023/12/30 18:15:58 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:44:22 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,7 +21,7 @@ bool read_to_vec(t_const_str path, t_vec_u8 *out)
{
t_u8 temp_buffer[READ_BUFFER_SIZE];
t_isize read_amount;
int f;
int f;
bool eof;
t_usize current_size;

View file

@ -6,7 +6,7 @@
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/23 17:38:21 by maix #+# #+# */
/* Updated: 2024/05/14 18:39:59 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:45:42 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -101,7 +101,7 @@ static bool handle_leftovers(int fd, char *temp_buffer, t_string *buf)
t_string get_next_line(int fd, bool *error)
{
t_string buf;
t_string buf;
char *temp_buffer;
t_copy_flags flags;

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/04 19:17:11 by maiboyer #+# #+# */
/* Updated: 2024/05/04 19:18:26 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:46:17 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
#include "me/str/str.h"
#include "me/types.h"
void hasher_write_str(t_hasher *hasher, t_str s)
void hasher_write_str(t_hasher *hasher, t_str s)
{
hasher_write_bytes(hasher, (t_u8 *)s, str_len(s));
}

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 19:06:05 by maiboyer #+# #+# */
/* Updated: 2024/05/14 18:40:29 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:46:34 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,7 +21,7 @@
t_i32 qoi_write(t_const_str filename, const void *data,
const t_qoi_desc *desc)
{
int f;
int f;
void *encoded;
t_i32 size;

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/14 18:26:27 by maiboyer #+# #+# */
/* Updated: 2024/07/07 19:10:07 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:48:46 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,23 +17,23 @@
#include "me/types.h"
#include <stdio.h>
t_allocator *global_allocator(void)
t_allocator *global_allocator(void)
{
static t_allocator global_alloc = {};
static bool init = false;
static t_allocator global_alloc = {};
static bool init = false;
if (!init)
{
init = true;
global_alloc = m_init();
// global_alloc = lc_init();
}
return (&global_alloc);
}
__attribute__((destructor(200)))
void uninit_global_allocator(void)
void uninit_global_allocator(void)
{
t_allocator *allocator;
t_allocator *allocator;
allocator = global_allocator();
vg_mem_defined(allocator, sizeof(*allocator));

View file

@ -6,16 +6,16 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/06 14:47:49 by maiboyer #+# #+# */
/* Updated: 2024/05/22 15:01:06 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:48:20 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/_allocator.h"
#include "me/mem/mem.h"
void *mem_alloc(t_usize size)
void *mem_alloc(t_usize size)
{
t_allocator *a;
t_allocator *a;
void *ret;
a = global_allocator();
@ -25,9 +25,9 @@ void *mem_alloc(t_usize size)
return (ret);
}
void mem_free(void *ptr)
void mem_free(void *ptr)
{
t_allocator *a;
t_allocator *a;
a = global_allocator();
return (a->free(a, ptr));

View file

@ -6,16 +6,16 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 15:53:21 by maiboyer #+# #+# */
/* Updated: 2024/05/14 18:30:27 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:47:03 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/mem/_allocator.h"
void *mem_alloc_array(t_usize size, t_usize count)
void *mem_alloc_array(t_usize size, t_usize count)
{
t_allocator *a;
t_allocator *a;
a = global_allocator();
return (a->alloc_array(a, size, count));

View file

@ -6,23 +6,23 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/07 12:46:18 by maiboyer #+# #+# */
/* Updated: 2024/05/14 18:32:06 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:47:21 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/_allocator.h"
void *mem_realloc(void *ptr, t_usize size)
void *mem_realloc(void *ptr, t_usize size)
{
t_allocator *a;
t_allocator *a;
a = global_allocator();
return (a->realloc(a, ptr, size));
}
void *mem_realloc_array(void *ptr, t_usize size, t_usize count)
void *mem_realloc_array(void *ptr, t_usize size, t_usize count)
{
t_allocator *a;
t_allocator *a;
a = global_allocator();
return (a->realloc_array(a, ptr, size, count));

View file

@ -6,15 +6,15 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/07 11:04:51 by maiboyer #+# #+# */
/* Updated: 2024/05/07 11:06:22 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:49:05 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/num/usize.h"
t_usize usize_round_up_to(t_usize self, t_usize mul)
t_usize usize_round_up_to(t_usize self, t_usize mul)
{
t_usize mod;
t_usize mod;
if (mul == 0)
return (self);

View file

@ -6,12 +6,11 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/07 11:08:03 by maiboyer #+# #+# */
/* Updated: 2024/05/16 17:26:27 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:54:01 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#define _GNU_SOURCE
#include "./gnu_source.h"
#include "me/fs/putendl_fd.h"
#include "me/fs/putstr_fd.h"
#include "me/types.h"
@ -31,24 +30,24 @@
# define BACKTRACE_DEEP 256
# endif
static size_t convert_to_vma(t_usize addr)
static size_t convert_to_vma(t_usize addr)
{
Dl_info info;
struct link_map *link_map;
Dl_info info;
struct link_map *link_map;
dladdr1((void *)addr, &info, (void **)&link_map, RTLD_DL_LINKMAP);
return (addr - link_map->l_addr);
}
static void print_trace_inner(void **trace, t_str *messages, t_usize i)
static void print_trace_inner(void **trace, t_str *messages, t_usize i)
{
char syscom[1024];
t_i32 p;
char syscom[1024];
t_i32 p;
p = 0;
fprintf(stderr, "[bt] #%-4zu\t", i);
while (messages[i][p] != '(' && messages[i][p] != ' ' &&
messages[i][p] != 0)
messages[i][p] != 0)
++p;
fflush(stderr);
snprintf(
@ -60,12 +59,12 @@ static void print_trace_inner(void **trace, t_str *messages, t_usize i)
fprintf(stderr, "%s\n", messages[i]);
}
void print_trace(void)
void print_trace(void)
{
void *trace[BACKTRACE_DEEP];
t_str *messages;
t_i32 size;
t_i32 i;
void *trace[BACKTRACE_DEEP];
t_str *messages;
t_i32 size;
t_i32 i;
size = backtrace(trace, BACKTRACE_DEEP);
messages = backtrace_symbols(trace, size);
@ -79,20 +78,18 @@ void print_trace(void)
}
#else
void print_trace(void)
void print_trace(void)
{
}
#endif
void me_abort(t_str msg)
void me_abort(t_str msg)
{
if (msg == NULL)
msg = "No message (msg was NULL)";
me_putendl_fd("Memory information:", 2);
me_putstr_fd("Abort: ", 2);
me_putendl_fd(msg, 2);
print_trace();
// me_exit(1);
abort();
me_exit(134);
}

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/07 13:08:52 by maiboyer #+# #+# */
/* Updated: 2024/07/07 19:11:39 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:54:22 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,7 +19,7 @@
// __attribute__((dtor)) to be run at exit for example:
// - close_all_slots
// - uninit global allocator
void me_exit(t_i32 exit_code)
void me_exit(t_i32 exit_code)
{
(get_stdin(), get_stdout(), get_stderr());
exit(exit_code);

18
stdme/src/os/gnu_source.h Normal file
View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* gnu_source.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/10 17:53:46 by maiboyer #+# #+# */
/* Updated: 2024/07/10 17:54:49 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef GNU_SOURCE_H
# define GNU_SOURCE_H
# define _GNU_SOURCE
#endif /* GNU_SOURCE_H */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/03 16:22:41 by maiboyer #+# #+# */
/* Updated: 2024/05/19 14:57:20 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 18:04:36 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,11 +26,11 @@
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 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_error in_path(t_spawn_info *info, t_process *process, t_const_str path,
t_string *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,
string_push(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,16 +79,16 @@ 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_string s;
t_usize p_idx;
t_string s;
(void)(process);
if (info->binary_path == NULL)
return (ERROR);
s = string_new(256);
if (str_start_with(info->binary_path, "/") ||
if (str_start_with(info->binary_path, "/") || \
str_find_chr(info->binary_path, '/') != NULL)
string_push(&s, info->binary_path);
else
@ -107,7 +107,8 @@ t_error find_binary(t_spawn_info *info, t_process *process)
return (string_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);

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/04 22:25:44 by maiboyer #+# #+# */
/* Updated: 2024/05/19 14:51:07 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 18:05:03 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,12 +14,12 @@
#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)
{
@ -29,13 +29,13 @@ 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;
t_str ss;
if (*s == NULL)
return (false);
ss = *s;
return (ss[0] == 'P' && ss[1] == 'A' && ss[2] == 'T' && ss[3] == 'H' &&
return (ss[0] == 'P' && ss[1] == 'A' && ss[2] == 'T' && ss[3] == 'H' && \
ss[4] == '=');
}

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/07 18:01:52 by maiboyer #+# #+# */
/* Updated: 2024/07/07 18:03:28 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:58:04 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,19 +15,20 @@
#include "me/string/string.h"
#include "me/types.h"
void me_printf_append_string(t_const_str to_write, t_usize to_write_len,
void *p_args)
void me_printf_append_string(t_const_str to_write, t_usize to_write_len,
void *p_args)
{
t_sprintf_arg *arg;
t_sprintf_arg *arg;
arg = p_args;
arg->total_print += to_write_len;
string_push(arg->buffer, to_write);
}
void me_printf_write(t_const_str to_write, t_usize to_write_len, void *p_args)
void me_printf_write(t_const_str to_write, \
t_usize to_write_len, void *p_args)
{
t_fprintf_arg *arg;
t_fprintf_arg *arg;
arg = (t_fprintf_arg *)p_args;
write_fd(arg->fd, (t_u8 *)to_write, to_write_len, NULL);

View file

@ -6,15 +6,15 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 21:05:47 by maiboyer #+# #+# */
/* Updated: 2024/07/07 17:40:12 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:58:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/printf/formatter/utils.h"
void handle_weird_precision_stuff(t_printf_arg *data, t_prec_strs strs,
t_usize value)
void handle_weird_precision_stuff(t_printf_arg *data, t_prec_strs strs,
t_usize value)
{
if (!value && data->extra.precision == 0 && (data->flags & PRECISION))
{

View file

@ -6,21 +6,18 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 17:50:56 by maiboyer #+# #+# */
/* Updated: 2024/07/07 18:01:58 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:57:15 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/printf/printf.h"
#include "me/fs/fs.h"
#include "me/fs/write.h"
#include "me/printf/_internal_printf.h"
#include "me/types.h"
#include <stdarg.h>
t_usize me_printf(t_const_str fmt, ...)
t_usize me_printf(t_const_str fmt, ...)
{
va_list args;
t_usize res;
va_list args;
t_usize res;
va_start(args, fmt);
res = me_vprintf(fmt, &args);
@ -28,45 +25,13 @@ t_usize me_printf(t_const_str fmt, ...)
return (res);
}
t_usize me_eprintf(t_const_str fmt, ...)
t_usize me_eprintf(t_const_str fmt, ...)
{
va_list args;
t_usize res;
va_list args;
t_usize res;
va_start(args, fmt);
res = me_veprintf(fmt, &args);
va_end(args);
return (res);
}
/*
t_usize me_printf(t_const_str fmt, ...)
{
va_list args;
t_str str;
t_usize len;
va_start(args, fmt);
str = me_printf_str(fmt, &args);
va_end(args);
len = str_len(str);
write(1, str, len);
mem_free(str);
return (len);
}
t_usize me_eprintf(t_const_str fmt, ...)
{
va_list args;
t_str str;
t_usize len;
va_start(args, fmt);
str = me_printf_str(fmt, &args);
va_end(args);
len = str_len(str);
write(2, str, len);
mem_free(str);
return (len);
}
*/

View file

@ -1,4 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
@ -7,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/05 19:55:09 by maiboyer #+# #+# */
/* Updated: 2024/07/05 19:57:23 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:55:18 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,9 +16,9 @@
#include "me/types.h"
#include <stdarg.h>
t_usize me_vprintf_fd(t_fd *fd, t_const_str fmt, va_list *args)
t_usize me_vprintf_fd(t_fd *fd, t_const_str fmt, va_list *args)
{
t_fprintf_arg passthru;
t_fprintf_arg passthru;
if (fd == NULL || fmt == NULL || args == NULL)
return (0);
@ -29,10 +28,10 @@ t_usize me_vprintf_fd(t_fd *fd, t_const_str fmt, va_list *args)
return (passthru.total_print);
}
t_usize me_printf_fd(t_fd *fd, t_const_str fmt, ...)
t_usize me_printf_fd(t_fd *fd, t_const_str fmt, ...)
{
va_list args;
t_usize res;
va_list args;
t_usize res;
va_start(args, fmt);
res = me_vprintf_fd(fd, fmt, &args);

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/07 17:27:50 by maiboyer #+# #+# */
/* Updated: 2024/07/07 18:03:40 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:57:32 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,9 +17,9 @@
#include "me/types.h"
#include <stdarg.h>
t_usize me_vprintf_str(t_string *buf, t_const_str fmt, va_list *args)
t_usize me_vprintf_str(t_string *buf, t_const_str fmt, va_list *args)
{
t_sprintf_arg passthru;
t_sprintf_arg passthru;
if (buf == NULL || fmt == NULL || args == NULL)
return (0);
@ -29,10 +29,10 @@ t_usize me_vprintf_str(t_string *buf, t_const_str fmt, va_list *args)
return (passthru.total_print);
}
t_usize me_printf_str(t_string *buf, t_const_str fmt, ...)
t_usize me_printf_str(t_string *buf, t_const_str fmt, ...)
{
t_usize res;
va_list args;
t_usize res;
va_list args;
va_start(args, fmt);
res = me_vprintf_str(buf, fmt, &args);

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/09 14:57:28 by maiboyer #+# #+# */
/* Updated: 2024/07/07 18:00:14 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 17:56:24 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,11 +16,12 @@
#include "me/types.h"
#include <stdarg.h>
void me_printf_write(t_const_str to_write, t_usize to_write_len, void *p_args);
void me_printf_write(t_const_str to_write, \
t_usize to_write_len, void *p_args);
t_usize me_vprintf(t_const_str fmt, va_list *args)
t_usize me_vprintf(t_const_str fmt, va_list *args)
{
t_fprintf_arg passthru;
t_fprintf_arg passthru;
if (fmt == NULL || args == NULL)
return (0);
@ -30,9 +31,9 @@ t_usize me_vprintf(t_const_str fmt, va_list *args)
return (passthru.total_print);
}
t_usize me_veprintf(t_const_str fmt, va_list *args)
t_usize me_veprintf(t_const_str fmt, va_list *args)
{
t_fprintf_arg passthru;
t_fprintf_arg passthru;
if (fmt == NULL || args == NULL)
return (0);

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 16:05:48 by maiboyer #+# #+# */
/* Updated: 2024/05/18 16:34:33 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 18:00:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,10 +16,10 @@
#include "me/str/str.h"
#include <stdlib.h>
t_str str_clone(t_const_str source)
t_str str_clone(t_const_str source)
{
t_str res;
t_usize len;
t_usize len;
len = str_len(source) + 1;
res = mem_alloc_array(sizeof(*res), len);

View file

@ -6,16 +6,15 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 18:53:47 by maiboyer #+# #+# */
/* Updated: 2024/05/04 18:37:40 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 18:00:43 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/str/str.h"
// PLEASE FIX THIS FUNCTION IF NEEDED !
bool str_compare(t_const_str lhs, t_const_str rhs)
bool str_compare(t_const_str lhs, t_const_str rhs)
{
t_usize index;
t_usize index;
if (lhs == NULL || rhs == NULL)
return (lhs == rhs);

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 17:52:12 by maiboyer #+# #+# */
/* Updated: 2024/05/18 18:06:37 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 18:02:36 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,10 +19,10 @@
#include "me/types.h"
#include <stdlib.h>
t_error str_reserve(t_string *buf, t_usize size)
t_error str_reserve(t_string *buf, t_usize size)
{
t_str temp_buffer;
t_usize new_capacity;
t_usize new_capacity;
if (buf == NULL)
return (ERROR);
@ -42,9 +42,9 @@ t_error str_reserve(t_string *buf, t_usize size)
return (NO_ERROR);
}
t_error string_push(t_string *buf, t_const_str to_push)
t_error string_push(t_string *buf, t_const_str to_push)
{
t_usize to_push_len;
t_usize to_push_len;
if (buf == NULL || to_push == NULL)
return (ERROR);
@ -56,26 +56,26 @@ t_error string_push(t_string *buf, t_const_str to_push)
return (NO_ERROR);
}
bool string_push_char(t_string *buf, char to_push)
bool string_push_char(t_string *buf, char to_push)
{
char push_str[2];
char push_str[2];
push_str[0] = to_push;
push_str[1] = 0;
return (string_push(buf, push_str));
}
void string_clear(t_string *buf)
void string_clear(t_string *buf)
{
mem_set_zero(buf->buf, buf->capacity);
buf->len = 0;
return;
return ;
}
t_string string_new(t_usize capacity)
t_string string_new(t_usize capacity)
{
t_string out;
t_str buf;
t_string out;
t_str buf;
if (capacity == 0)
capacity = 16;

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 21:32:17 by maiboyer #+# #+# */
/* Updated: 2024/07/08 22:25:52 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 18:01:27 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,9 +15,10 @@
#include "me/string/string.h"
#include "me/types.h"
t_error string_insert(t_string *self, t_usize pos, t_str str)
t_error string_insert(t_string *self, t_usize pos, t_str str)
{
t_usize len;
t_usize len;
if (self == NULL || str == NULL || pos > self->len)
return (ERROR);
if (pos == self->len)
@ -32,9 +33,9 @@ t_error string_insert(t_string *self, t_usize pos, t_str str)
return (NO_ERROR);
}
t_error string_insert_char(t_string *self, t_usize pos, char chr)
t_error string_insert_char(t_string *self, t_usize pos, char chr)
{
char tmp[2];
char tmp[2];
if (chr == '\0')
return (ERROR);

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 21:50:27 by maiboyer #+# #+# */
/* Updated: 2024/07/08 21:54:45 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 18:01:53 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,9 +15,9 @@
#include "me/string/string.h"
#include "me/types.h"
t_error string_remove(t_string *self, t_usize pos, char *out)
t_error string_remove(t_string *self, t_usize pos, char *out)
{
char fake_out;
char fake_out;
if (out == NULL)
out = &fake_out;
@ -30,7 +30,7 @@ t_error string_remove(t_string *self, t_usize pos, char *out)
return (NO_ERROR);
}
t_error string_clear_after(t_string *self, t_usize pos)
t_error string_clear_after(t_string *self, t_usize pos)
{
if (self == NULL || pos >= self->len)
return (ERROR);

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 22:02:49 by maiboyer #+# #+# */
/* Updated: 2024/07/08 22:04:49 by maiboyer ### ########.fr */
/* Updated: 2024/07/10 18:01:40 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
#include "me/string/string.h"
#include "me/types.h"
t_error string_reserve(t_string *self, t_usize capacity)
t_error string_reserve(t_string *self, t_usize capacity)
{
if (self == NULL)
return (ERROR);