summaryrefslogtreecommitdiff
path: root/components/libc/compilers/newlib
diff options
context:
space:
mode:
authoryangjie11 <[email protected]>2020-11-18 09:56:35 +0800
committerGitHub <[email protected]>2020-11-18 09:56:35 +0800
commitd4a682e8d97fa131e5a8d795f8c5451d55cdd5b0 (patch)
tree4773b40cb012475c5daf74bfd55707e141477669 /components/libc/compilers/newlib
parent2b98f4720c827ae1850df78299f6b273d568c8c7 (diff)
parent2ef3c9d861f55253620996a94831a4be31ca6620 (diff)
Merge pull request #3 from RT-Thread/master
sync
Diffstat (limited to 'components/libc/compilers/newlib')
-rw-r--r--components/libc/compilers/newlib/README.md9
-rw-r--r--components/libc/compilers/newlib/libc.h12
-rw-r--r--components/libc/compilers/newlib/syscalls.c31
-rw-r--r--components/libc/compilers/newlib/termios.h15
-rw-r--r--components/libc/compilers/newlib/time.c85
5 files changed, 44 insertions, 108 deletions
diff --git a/components/libc/compilers/newlib/README.md b/components/libc/compilers/newlib/README.md
new file mode 100644
index 0000000000..385f329a4f
--- /dev/null
+++ b/components/libc/compilers/newlib/README.md
@@ -0,0 +1,9 @@
+# NEWLIB (GCC) porting for RT-Thread
+
+Please define RT_USING_LIBC and compile RT-Thread with GCC compiler.
+
+
+
+## More Information
+
+https://sourceware.org/newlib/libc.html#Reentrancy \ No newline at end of file
diff --git a/components/libc/compilers/newlib/libc.h b/components/libc/compilers/newlib/libc.h
index ab9334fe26..fdf2ab4f60 100644
--- a/components/libc/compilers/newlib/libc.h
+++ b/components/libc/compilers/newlib/libc.h
@@ -27,13 +27,19 @@
#define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND)
#define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND)
+#ifdef __cplusplus
+extern "C" {
+#endif
int libc_system_init(void);
int libc_stdio_set_console(const char* device_name, int mode);
int libc_stdio_get_console(void);
/* some time related function */
-int libc_set_time(const struct timespec *time);
-int libc_get_time(struct timespec *time);
-int libc_time_to_tick(const struct timespec *time);
+int libc_set_time(const struct timespec* time);
+int libc_get_time(struct timespec* time);
+int libc_time_to_tick(const struct timespec* time);
+#ifdef __cplusplus
+}
+#endif
#endif
diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c
index e4cda478cb..228fa0d140 100644
--- a/components/libc/compilers/newlib/syscalls.c
+++ b/components/libc/compilers/newlib/syscalls.c
@@ -9,22 +9,28 @@
#include <reent.h>
#include <sys/errno.h>
#include <sys/time.h>
+#include <stdio.h>
+
#include <rtthread.h>
#ifdef RT_USING_DFS
#include <dfs_posix.h>
#endif
-#ifdef RT_USING_PTHREADS
-#include <pthread.h>
-#endif
-
#ifdef RT_USING_MODULE
#include <dlmodule.h>
#endif
/* Reentrant versions of system calls. */
+#ifndef _REENT_ONLY
+int *
+__errno ()
+{
+ return _rt_errno();
+}
+#endif
+
int
_close_r(struct _reent *ptr, int fd)
{
@@ -218,7 +224,7 @@ _ssize_t
_write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
{
#ifndef RT_USING_DFS
- if (fd == 0)
+ if (fileno(stdout) == fd)
{
rt_device_t console;
@@ -432,3 +438,18 @@ void abort(void)
while (1);
}
+
+uid_t getuid(void)
+{
+ return 0;
+}
+
+mode_t umask(mode_t mask)
+{
+ return 022;
+}
+
+int flock(int fd, int operation)
+{
+ return 0;
+}
diff --git a/components/libc/compilers/newlib/termios.h b/components/libc/compilers/newlib/termios.h
deleted file mode 100644
index 1956121225..0000000000
--- a/components/libc/compilers/newlib/termios.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef _TERMIOS_H__
-#define _TERMIOS_H__
-
-#include <sys/types.h>
-#include <posix_termios.h>
-
-#endif
diff --git a/components/libc/compilers/newlib/time.c b/components/libc/compilers/newlib/time.c
deleted file mode 100644
index 29c5c6cdd2..0000000000
--- a/components/libc/compilers/newlib/time.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#include <sys/time.h>
-#include <rtthread.h>
-
-#ifdef RT_USING_DEVICE
-int gettimeofday(struct timeval *tp, void *ignore)
-{
- time_t time;
- rt_device_t device;
-
- device = rt_device_find("rtc");
- if (device != RT_NULL)
- {
- rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
- if (tp != RT_NULL)
- {
- tp->tv_sec = time;
- tp->tv_usec = 0;
- }
-
- return time;
- }
-
- return 0;
-}
-#endif
-
-/**
- * Returns the current time.
- *
- * @param time_t * t the timestamp pointer, if not used, keep NULL.
- *
- * @return time_t return timestamp current.
- *
- */
-/* for IAR 6.2 later Compiler */
-#if defined (__IAR_SYSTEMS_ICC__) && (__VER__) >= 6020000
-#pragma module_name = "?time"
-time_t (__time32)(time_t *t) /* Only supports 32-bit timestamp */
-#else
-time_t time(time_t *t)
-#endif
-{
- time_t time_now = 0;
-
-#ifdef RT_USING_RTC
- static rt_device_t device = RT_NULL;
-
- /* optimization: find rtc device only first. */
- if (device == RT_NULL)
- {
- device = rt_device_find("rtc");
- }
-
- /* read timestamp from RTC device. */
- if (device != RT_NULL)
- {
- if (rt_device_open(device, 0) == RT_EOK)
- {
- rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now);
- rt_device_close(device);
- }
- }
-#endif /* RT_USING_RTC */
-
- /* if t is not NULL, write timestamp to *t */
- if (t != RT_NULL)
- {
- *t = time_now;
- }
-
- return time_now;
-}
-
-RT_WEAK clock_t clock(void)
-{
- return rt_tick_get();
-}