Skip to content

Commit 695f2bf

Browse files
committed
Replaced some newlib functions to avoid puling in reent struct
1 parent e983896 commit 695f2bf

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/libc/errno.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* errno.c
3+
*
4+
* Created on: 1 Oct 2022
5+
* Author: David
6+
*
7+
* This file replaces the one in newlib in order to avoid pulling the reent struct
8+
*/
9+
10+
static int globalErrno = 0;
11+
12+
int * __errno () noexcept
13+
{
14+
return &globalErrno;
15+
}
16+
17+
// End

src/libc/nano-mallocr.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@
3232
* Interface documentation refer to malloc.c.
3333
*/
3434

35+
#if 0 // DC we don't want to pull in stdio
3536
#include <stdio.h>
37+
#endif
3638
#include <string.h>
39+
#if 0 // DC we don't want to pull in errno because it pulls in the reent struct
3740
#include <errno.h>
41+
#endif
3842
#include <malloc.h>
3943

4044
#if 1 // DC
@@ -57,6 +61,7 @@
5761
#include <assert.h>
5862
#else
5963
#define assert(x) ((void)0)
64+
#include <stdint.h>
6065
extern void vAssertCalled(uint32_t line, const char *file) noexcept;
6166
#endif
6267

@@ -116,9 +121,9 @@ extern void ReleaseMallocMutex();
116121
#else
117122
#define MALLOC_LOCK
118123
#define MALLOC_UNLOCK
119-
#endif
120124

121125
#define RERRNO errno
126+
#endif
122127

123128
#define nano_malloc malloc
124129
#define nano_free free
@@ -279,7 +284,9 @@ void * nano_malloc(RARG malloc_size_t s)
279284

280285
if (alloc_size >= MAX_ALLOC_SIZE || alloc_size < s)
281286
{
287+
#if 0 // DC
282288
RERRNO = ENOMEM;
289+
#endif
283290
return NULL;
284291
}
285292

@@ -328,7 +335,9 @@ void * nano_malloc(RARG malloc_size_t s)
328335
/* sbrk returns -1 if fail to allocate */
329336
if (r == (void *)-1)
330337
{
338+
#if 0 // DC
331339
RERRNO = ENOMEM;
340+
#endif
332341
MALLOC_UNLOCK;
333342
return NULL;
334343
}

0 commit comments

Comments
 (0)