added unused sys functions to avoid warning on compile

This commit is contained in:
Màrius Montón 2019-09-07 11:40:00 +02:00
parent a703c5f4ba
commit 96c17868e4
1 changed files with 45 additions and 1 deletions

View File

@ -2,10 +2,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <sys/stat.h>
#define BUFFER_SIZE (512)
#define TRACE (*(unsigned char *)0x40000000)
extern int errno;
int _write(int file, const char *ptr, int len) {
int x;
@ -16,16 +20,46 @@ int _write(int file, const char *ptr, int len) {
return (len);
}
int _read (int file, char *ptr, int len) {
return 0;
}
int _close (int file) {
errno = EBADF;
return -1;
}
int _fstat (int file, struct stat *st) {
st->st_mode = S_IFCHR;
return 0;
}
int _isatty (int file) {
return 1;
}
int _lseek (int file, int offset, int whence) {
return 0;
}
int main(void) {
uint16_t *buffA, *buffB;
bool test_ok = true;
uint8_t *buffC;
printf("Malloc Test\n");
printf("buffA: %p\n", (void *) buffA);
printf("buffB: %p\n", (void *) buffB);
printf("buffC: %p\n", (void *) buffC);
buffA = malloc(BUFFER_SIZE * sizeof(uint16_t));
buffB = malloc(BUFFER_SIZE * sizeof(uint16_t));
printf("buffA: %p\n", (void *) buffA);
printf("buffB: %p\n", (void *) buffB);
printf("buffC: %p\n", (void *) buffC);
if ( (buffA == NULL ) || (buffB == NULL) ) {
printf("Error malloc\n");
}
@ -34,7 +68,6 @@ int main(void) {
buffA[i] = i;
}
memcpy(buffB, buffA, BUFFER_SIZE * sizeof(uint16_t));
for(int i=0;i<BUFFER_SIZE;i++) {
@ -45,6 +78,17 @@ int main(void) {
}
}
free(buffA);
free(buffB);
printf("buffA: %p\n", (void *) buffA);
printf("buffB: %p\n", (void *) buffB);
printf("buffC: %p\n", (void *) buffC);
/* buffC should reuse address previously used by buffA (?) */
buffC = malloc(512);
printf("buffC: %p\n", (void *) buffC);
if (test_ok == true) {
printf("Test were OK\n");
}