Kernel/LibC: add free function for FixedWidthAllocator

I have to rework the syscall API and allocators in process. For
now this works well enough :)
This commit is contained in:
Bananymous
2023-05-07 01:21:50 +03:00
parent 890aa9aa15
commit 12e42f40c5
9 changed files with 112 additions and 45 deletions

View File

@@ -3,42 +3,24 @@
int main()
{
void* ptr = malloc(10);
if (ptr == NULL)
for (int i = 0; i < 10; i++)
{
perror("malloc");
return 1;
}
*(int*)ptr = 5;
putc('0' + *(int*)ptr, stdout);
return 0;
FILE* fp = fopen("/boot/grub/grub.cfg", "r");
if (fp == NULL)
{
perror("fopen");
return 1;
}
for (;;)
{
char buffer[128];
size_t nread = fread(buffer, 1, sizeof(buffer) - 1, fp);
if (nread == 0)
int* ptrs[10];
for (int j = 0; j < 10; j++)
{
if (ferror(fp))
perror("fread");
break;
ptrs[j] = malloc(10);
if (ptrs[j] == NULL)
{
perror("malloc");
return 1;
}
*ptrs[j] = j;
putc('0' + *ptrs[j], stdout);
}
buffer[nread] = '\0';
fputs(buffer, stdout);
for (int j = 0; j < 10; j++)
free(ptrs[j]);
putc('\n', stdout);
}
if (fclose(fp) == EOF)
{
perror("fclose");
return 1;
}
return 0;
}