forked from Bananymous/banan-os
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user