DEV 3.2 ; TP01
This commit is contained in:
15
Fun/NewMalloc/newmem.c
Normal file
15
Fun/NewMalloc/newmem.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "newmem.h"
|
||||
|
||||
void* newmalloc(size_t size) {
|
||||
void* start = sbrk(0);
|
||||
void* finish = sbrk(size);
|
||||
|
||||
printf("%d\n", finish);
|
||||
|
||||
if (start == finish) return NULL;
|
||||
return finish;
|
||||
}
|
6
Fun/NewMalloc/newmem.h
Normal file
6
Fun/NewMalloc/newmem.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef NEWMEM
|
||||
#define NEWMEM
|
||||
|
||||
void* newmalloc(size_t size);
|
||||
|
||||
#endif
|
9
Fun/NewMalloc/test.c
Normal file
9
Fun/NewMalloc/test.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "newmem.h"
|
||||
|
||||
int main(void) {
|
||||
char* t = (char*)newmalloc(15);
|
||||
|
||||
printf("%d", t != NULL);
|
||||
}
|
Reference in New Issue
Block a user