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> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 15:29:38 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 18:38:47 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */ /* By: maix <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/23 17:38:21 by maix #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/04 19:17:11 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 19:06:05 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/14 18:26:27 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,11 +21,11 @@ t_allocator *global_allocator(void)
{ {
static t_allocator global_alloc = {}; static t_allocator global_alloc = {};
static bool init = false; static bool init = false;
if (!init) if (!init)
{ {
init = true; init = true;
global_alloc = m_init(); global_alloc = m_init();
// global_alloc = lc_init();
} }
return (&global_alloc); return (&global_alloc);
} }

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/06 14:47:49 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 15:53:21 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/07 12:46:18 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/07 11:04:51 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,12 +6,11 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/07 11:08:03 by maiboyer #+# #+# */ /* 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/putendl_fd.h"
#include "me/fs/putstr_fd.h" #include "me/fs/putstr_fd.h"
#include "me/types.h" #include "me/types.h"
@ -89,10 +88,8 @@ void me_abort(t_str msg)
{ {
if (msg == NULL) if (msg == NULL)
msg = "No message (msg was NULL)"; msg = "No message (msg was NULL)";
me_putendl_fd("Memory information:", 2);
me_putstr_fd("Abort: ", 2); me_putstr_fd("Abort: ", 2);
me_putendl_fd(msg, 2); me_putendl_fd(msg, 2);
print_trace(); print_trace();
// me_exit(1); me_exit(134);
abort();
} }

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/07 13:08:52 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* test-skeleton.c :+: :+: :+: */ /* gnu_source.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/22 15:11:51 by maiboyer #+# #+# */ /* Created: 2024/07/10 17:53:46 by maiboyer #+# #+# */
/* Updated: 2024/05/22 15:12:44 by maiboyer ### ########.fr */ /* Updated: 2024/07/10 17:54:49 by maiboyer ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
int do_test(int argc, char **argv); #ifndef GNU_SOURCE_H
# define GNU_SOURCE_H
int main(int argc, char *argv[]) # define _GNU_SOURCE
{
return (do_test(argc, argv)); #endif /* GNU_SOURCE_H */
}

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/03 16:22:41 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -88,7 +88,7 @@ t_error find_binary(t_spawn_info *info, t_process *process)
if (info->binary_path == NULL) if (info->binary_path == NULL)
return (ERROR); return (ERROR);
s = string_new(256); 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) str_find_chr(info->binary_path, '/') != NULL)
string_push(&s, info->binary_path); string_push(&s, info->binary_path);
else else
@ -107,7 +107,8 @@ t_error find_binary(t_spawn_info *info, t_process *process)
return (string_free(s), ERROR); 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) if (cleanup_process && process->stdin.tag != INVALID)
close(process->stdin.vals.ro.fd); close(process->stdin.vals.ro.fd);

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/04 22:25:44 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -36,6 +36,6 @@ bool find_path(const t_str *s)
if (*s == NULL) if (*s == NULL)
return (false); return (false);
ss = *s; 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] == '='); ss[4] == '=');
} }

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/07 18:01:52 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -25,7 +25,8 @@ void me_printf_append_string(t_const_str to_write, t_usize to_write_len,
string_push(arg->buffer, to_write); 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;

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 21:05:47 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,14 +6,11 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 17:50:56 by maiboyer #+# #+# */ /* 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/printf/printf.h"
#include "me/fs/fs.h"
#include "me/fs/write.h"
#include "me/printf/_internal_printf.h"
#include "me/types.h" #include "me/types.h"
#include <stdarg.h> #include <stdarg.h>
@ -38,35 +35,3 @@ t_usize me_eprintf(t_const_str fmt, ...)
va_end(args); va_end(args);
return (res); 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> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/05 19:55:09 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/07 17:27:50 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/09 14:57:28 by maiboyer #+# #+# */ /* 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,7 +16,8 @@
#include "me/types.h" #include "me/types.h"
#include <stdarg.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)
{ {

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 16:05:48 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,13 +6,12 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 18:53:47 by maiboyer #+# #+# */ /* 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" #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;

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 17:52:12 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 21:32:17 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,6 +18,7 @@
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) if (self == NULL || str == NULL || pos > self->len)
return (ERROR); return (ERROR);
if (pos == self->len) if (pos == self->len)

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 21:50:27 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 22:02:49 by maiboyer #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -1,124 +0,0 @@
/* Copyright (C) 2000-2024 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <errno.h>
#include <error.h>
#include <limits.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include "./redef_alloc.h"
/* Number of samples per size. */
#define N 5000
static void fixed_test(int size)
{
char *ptrs[N];
int i;
for (i = 0; i < N; ++i)
{
int j;
ptrs[i] = (char *)calloc(1, size);
if (ptrs[i] == NULL)
break;
for (j = 0; j < size; ++j)
{
if (ptrs[i][j] != '\0')
error(EXIT_FAILURE, 0,
"byte not cleared (size %d, element %d, byte %d)", size,
i, j);
ptrs[i][j] = '\xff';
}
}
while (i-- > 0)
free(ptrs[i]);
}
static void random_test(void)
{
char *ptrs[N];
int i;
for (i = 0; i < N; ++i)
{
int j;
int n = 1 + random() % 10;
int elem = 1 + random() % 100;
int size = n * elem;
ptrs[i] = (char *)calloc(n, elem);
if (ptrs[i] == NULL)
break;
for (j = 0; j < size; ++j)
{
if (ptrs[i][j] != '\0')
error(EXIT_FAILURE, 0,
"byte not cleared (size %d, element %d, byte %d)", size,
i, j);
ptrs[i][j] = '\xff';
}
}
while (i-- > 0)
free(ptrs[i]);
}
static void null_test(void)
{
/* If the size is 0 the result is implementation defined. Just make
sure the program doesn't crash. The result of calloc is
deliberately ignored, so do not warn about that. */
calloc(0, 0);
calloc(0, UINT_MAX);
calloc(UINT_MAX, 0);
calloc(0, ~((size_t)0));
calloc(~((size_t)0), 0);
}
static int do_test(int argc, char **argv)
{
(void)(argc);
(void)(argv);
/* We are allocating blocks with `calloc' and check whether every
block is completely cleared. We first try this for some fixed
times and then with random size. */
fixed_test(15);
fixed_test(5);
fixed_test(17);
fixed_test(6);
fixed_test(31);
fixed_test(96);
random_test();
null_test();
return 0;
}
#define TEST_FUNCTION do_test()
#include "./test-skeleton.c"

View file

@ -1,84 +0,0 @@
/* Copyright (C) 1999-2024 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <errno.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "./redef_alloc.h"
static int errors = 0;
static void merror(const char *msg)
{
++errors;
printf("Error: %s\n", msg);
}
static int do_test(int argc, char **argv)
{
(void)(argc);
(void)(argv);
void *p, *q;
int save;
srandom(time(NULL));
errno = 0;
p = malloc(-1);
save = errno;
if (p != NULL)
merror("malloc (-1) succeeded.");
if (p == NULL && save != ENOMEM)
merror("errno is not set correctly");
p = malloc(10);
if (p == NULL)
merror("malloc (10) failed.");
/* realloc (p, 0) == free (p). */
p = realloc(p, 0);
if (p != NULL)
merror("realloc (p, 0) failed.");
p = malloc(0);
if (p == NULL)
merror("malloc (0) failed.");
p = realloc(p, 0);
if (p != NULL)
merror("realloc (p, 0) failed.");
p = malloc(513 * 1024);
if (p == NULL)
merror("malloc (513K) failed.");
q = malloc(-512 * 1024);
if (q != NULL)
merror("malloc (-512K) succeeded.");
free(p);
return errors != 0;
}
#include "./test-skeleton.c"

View file

@ -1,196 +0,0 @@
/* Copyright (C) 2013-2024 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <errno.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "aq/melloc_interal.h"
#include "./redef_alloc.h"
void FAIL_EXIT1(char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
exit(1);
}
static int do_test(int argc, char **argv)
{
(void)(argv);
(void)(argv);
void *p;
unsigned char *p1, *p2, *p3;
unsigned char *c;
int save, i, ok;
errno = 0;
p1 = realloc(NULL, 50);
memset(p1, 0x10, 50);
for (i = 0; i < 50; i++)
{
if (p1[i] != 0x10)
FAIL_EXIT1("memset didn't set (p[%i] = %#02x)\n", i, p1[i]);
}
p2 = malloc(50);
p3 = realloc(p1, 150);
if (p1 == p3)
FAIL_EXIT1("P1 == P2 \n");
for (i = 0; i < 50; i++)
{
if (p3[i] != 0x10)
FAIL_EXIT1("realloc didn't preserve after move (p3[%i] = %#02x)\n", i, p3[i]);
}
// /* realloc (NULL, ...) behaves similarly to malloc (C89). */
// p = realloc(NULL, -1);
// save = errno;
//
// if (p != NULL)
// FAIL_EXIT1("realloc (NULL, -1) succeeded.\n");
//
// /* errno should be set to ENOMEM on failure (POSIX). */
// if (p == NULL && save != ENOMEM)
// FAIL_EXIT1("errno is not set correctly\n");
//
// errno = 0;
//
// /* realloc (NULL, ...) behaves similarly to malloc (C89). */
// p = realloc(NULL, 10);
// save = errno;
//
// if (p == NULL)
// FAIL_EXIT1("realloc (NULL, 10) failed.\n");
//
// free(p);
//
// p = calloc(20, 1);
// if (p == NULL)
// FAIL_EXIT1("calloc (20, 1) failed.\n");
//
// /* Check increasing size preserves contents (C89). */
// p = realloc(p, 200);
// if (p == NULL)
// FAIL_EXIT1("realloc (p, 200) failed.\n");
//
// c = p;
// ok = 1;
//
// for (i = 0; i < 20; i++)
// {
// if (c[i] != 0)
// ok = 0;
// }
//
// if (ok == 0)
// FAIL_EXIT1("first 20 bytes were not cleared\n");
//
// free(p);
//
// p = realloc(NULL, 100);
// if (p == NULL)
// FAIL_EXIT1("realloc (NULL, 100) failed.\n");
//
// memset(p, 0xff, 100);
//
// /* Check decreasing size preserves contents (C89). */
// p = realloc(p, 16);
// if (p == NULL)
// FAIL_EXIT1("realloc (p, 16) failed.\n");
//
// c = p;
// ok = 1;
//
// for (i = 0; i < 16; i++)
// {
// if (c[i] != 0xff)
// ok = 0;
// }
//
// if (ok == 0)
// FAIL_EXIT1("first 16 bytes were not correct\n");
//
// /* Check failed realloc leaves original untouched (C89). */
// c = realloc(p, -1);
// if (c != NULL)
// FAIL_EXIT1("realloc (p, -1) succeeded.\n");
//
// c = p;
// ok = 1;
//
// for (i = 0; i < 16; i++)
// {
// if (c[i] != 0xff)
// ok = 0;
// }
//
// if (ok == 0)
// FAIL_EXIT1("first 16 bytes were not correct after failed realloc\n");
//
// /* realloc (p, 0) frees p (C89) and returns NULL (glibc). */
// p = realloc(p, 0);
// if (p != NULL)
// FAIL_EXIT1("realloc (p, 0) returned non-NULL.\n");
//
// /* realloc (NULL, 0) acts like malloc (0) (glibc). */
// p = realloc(NULL, 0);
// if (p == NULL)
// FAIL_EXIT1("realloc (NULL, 0) returned NULL.\n");
//
// free(p);
//
// printf("WTF\n");
//
// /* Smoke test to make sure that allocations do not move if they have
// enough
// space to expand in the chunk. */
// for (size_t sz = 3; sz < 256 * 1024; sz += 2048)
// {
// p = realloc(NULL, sz);
// if (p == NULL)
// FAIL_EXIT1("realloc (NULL, %zu) returned NULL.\n", sz);
// size_t newsz = ((t_chunk *)((void *)(p) - sizeof(t_chunk)))->size;
// printf("size: %zu, usable size: %zu, extra: %zu\n", sz, newsz,
// newsz - sz);
// uintptr_t oldp = (uintptr_t)p;
// void *new_p = realloc(p, newsz);
// if ((uintptr_t)new_p != oldp)
// FAIL_EXIT1(
// "Expanding (%zu bytes) to usable size (%zu) moved block\n", sz,
// newsz);
// free(new_p);
//
// /* We encountered a large enough extra size at least once. */
// if (newsz - sz > 1024)
// break;
// }
return 0;
}
#define TEST_FUNCTION do_test()
#include "./test-skeleton.c"

View file

@ -1,28 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redef_alloc.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/22 15:15:52 by maiboyer #+# #+# */
/* Updated: 2024/05/22 15:16:34 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef REDEF_ALLOC_H
#define REDEF_ALLOC_H
#include "me/mem/mem.h"
#undef malloc
#undef calloc
#undef realloc
#undef free
#define malloc(s) mem_alloc((s))
#define calloc(s, l) mem_alloc_array((s), (l))
#define realloc(p, t) mem_realloc((p), (t))
#define free(p) mem_free((p))
#endif /* REDEF_ALLOC_H */