Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2022-10-01 14:08:22 +0300
committerDavid Crocker <dcrocker@eschertech.com>2022-10-01 14:08:22 +0300
commit695f2bfe86cab38f87c91ee37c49d3d0f5b3e1a5 (patch)
tree05ebc9ccf167b51db93149738e329ac6cbfe1a45
parente983896d5d1e8f3b27fec56cc671eab4d36f5351 (diff)
Replaced some newlib functions to avoid puling in reent struct
-rw-r--r--src/libc/errno.c17
-rw-r--r--src/libc/nano-mallocr.c11
2 files changed, 27 insertions, 1 deletions
diff --git a/src/libc/errno.c b/src/libc/errno.c
new file mode 100644
index 00000000..0ba05c99
--- /dev/null
+++ b/src/libc/errno.c
@@ -0,0 +1,17 @@
+/*
+ * errno.c
+ *
+ * Created on: 1 Oct 2022
+ * Author: David
+ *
+ * This file replaces the one in newlib in order to avoid pulling the reent struct
+ */
+
+static int globalErrno = 0;
+
+int * __errno () noexcept
+{
+ return &globalErrno;
+}
+
+// End
diff --git a/src/libc/nano-mallocr.c b/src/libc/nano-mallocr.c
index 4b69b6d4..b5c3c1c4 100644
--- a/src/libc/nano-mallocr.c
+++ b/src/libc/nano-mallocr.c
@@ -32,9 +32,13 @@
* Interface documentation refer to malloc.c.
*/
+#if 0 // DC we don't want to pull in stdio
#include <stdio.h>
+#endif
#include <string.h>
+#if 0 // DC we don't want to pull in errno because it pulls in the reent struct
#include <errno.h>
+#endif
#include <malloc.h>
#if 1 // DC
@@ -57,6 +61,7 @@
#include <assert.h>
#else
#define assert(x) ((void)0)
+#include <stdint.h>
extern void vAssertCalled(uint32_t line, const char *file) noexcept;
#endif
@@ -116,9 +121,9 @@ extern void ReleaseMallocMutex();
#else
#define MALLOC_LOCK
#define MALLOC_UNLOCK
-#endif
#define RERRNO errno
+#endif
#define nano_malloc malloc
#define nano_free free
@@ -279,7 +284,9 @@ void * nano_malloc(RARG malloc_size_t s)
if (alloc_size >= MAX_ALLOC_SIZE || alloc_size < s)
{
+#if 0 // DC
RERRNO = ENOMEM;
+#endif
return NULL;
}
@@ -328,7 +335,9 @@ void * nano_malloc(RARG malloc_size_t s)
/* sbrk returns -1 if fail to allocate */
if (r == (void *)-1)
{
+#if 0 // DC
RERRNO = ENOMEM;
+#endif
MALLOC_UNLOCK;
return NULL;
}