summaryrefslogtreecommitdiff
path: root/components/libc/compilers
diff options
context:
space:
mode:
authorWayne Lin <[email protected]>2021-11-10 16:01:38 +0800
committerWayne Lin <[email protected]>2021-11-10 16:01:38 +0800
commit9b44e57a6022b8eb46eda7037b719ec918fdcc55 (patch)
tree26be9facf0f37d1c38b9e4b6e4abc99d6f8b5a8d /components/libc/compilers
parent37f5236dfa45b98d02e867536a10ac0b6622b80b (diff)
parentfdbaa2a808d12d522ad90702795c08ae8443aab9 (diff)
Merge branch 'master' of https://github.com/RT-Thread/rt-thread into nuvoton
Diffstat (limited to 'components/libc/compilers')
-rw-r--r--components/libc/compilers/armlibc/SConscript13
-rw-r--r--components/libc/compilers/armlibc/libc.c43
-rw-r--r--components/libc/compilers/armlibc/libc.h28
-rw-r--r--components/libc/compilers/armlibc/mem_std.c3
-rw-r--r--components/libc/compilers/armlibc/stdio.c75
-rw-r--r--components/libc/compilers/armlibc/syscalls.c161
-rw-r--r--components/libc/compilers/common/SConscript19
-rw-r--r--components/libc/compilers/common/delay.c41
-rw-r--r--components/libc/compilers/common/dirent.h23
-rw-r--r--components/libc/compilers/common/fcntl.h67
-rw-r--r--components/libc/compilers/common/nogcc/SConscript (renamed from components/libc/compilers/common/none-gcc/SConscript)0
-rw-r--r--components/libc/compilers/common/nogcc/readme.md (renamed from components/libc/compilers/common/none-gcc/readme.md)0
-rw-r--r--components/libc/compilers/common/nogcc/sys/errno.h (renamed from components/libc/compilers/common/none-gcc/sys/errno.h)4
-rw-r--r--components/libc/compilers/common/nogcc/sys/select.h58
-rw-r--r--components/libc/compilers/common/nogcc/sys/stat.h83
-rw-r--r--components/libc/compilers/common/nogcc/sys/types.h (renamed from components/libc/compilers/common/none-gcc/sys/types.h)7
-rw-r--r--components/libc/compilers/common/nogcc/sys/unistd.h45
-rw-r--r--components/libc/compilers/common/nogcc/unistd.h (renamed from components/libc/compilers/common/none-gcc/unistd.h)0
-rw-r--r--components/libc/compilers/common/none-gcc/sys/stat.h8
-rw-r--r--components/libc/compilers/common/none-gcc/sys/unistd.h81
-rw-r--r--components/libc/compilers/common/poll.h49
-rw-r--r--components/libc/compilers/common/readme.md11
-rw-r--r--components/libc/compilers/common/stdlib.c25
-rw-r--r--components/libc/compilers/common/sys/ioctl.h8
-rw-r--r--components/libc/compilers/common/sys/signal.h194
-rw-r--r--components/libc/compilers/common/sys/statfs.h15
-rw-r--r--components/libc/compilers/common/sys/time.h47
-rw-r--r--components/libc/compilers/common/sys/vfs.h (renamed from components/libc/compilers/common/none-gcc/fcntl.h)11
-rw-r--r--components/libc/compilers/common/time.c156
-rw-r--r--components/libc/compilers/common/unistd.c119
-rw-r--r--components/libc/compilers/dlib/SConscript10
-rw-r--r--components/libc/compilers/dlib/libc.c44
-rw-r--r--components/libc/compilers/dlib/libc.h29
-rw-r--r--components/libc/compilers/dlib/stdio.c58
-rw-r--r--components/libc/compilers/dlib/syscall_close.c11
-rw-r--r--components/libc/compilers/dlib/syscall_lseek.c9
-rw-r--r--components/libc/compilers/dlib/syscall_open.c12
-rw-r--r--components/libc/compilers/dlib/syscall_read.c36
-rw-r--r--components/libc/compilers/dlib/syscall_remove.c12
-rw-r--r--components/libc/compilers/dlib/syscall_write.c52
-rw-r--r--components/libc/compilers/dlib/syscalls.c7
-rw-r--r--components/libc/compilers/gcc/SConscript15
-rw-r--r--components/libc/compilers/gcc/newlib/README.md (renamed from components/libc/compilers/newlib/README.md)3
-rw-r--r--components/libc/compilers/gcc/newlib/SConscript20
-rw-r--r--components/libc/compilers/gcc/newlib/libc_syms.c (renamed from components/libc/compilers/newlib/libc_syms.c)0
-rw-r--r--components/libc/compilers/gcc/newlib/machine/time.h (renamed from components/libc/compilers/newlib/machine/time.h)0
-rw-r--r--components/libc/compilers/gcc/newlib/syscalls.c (renamed from components/libc/compilers/newlib/syscalls.c)303
-rw-r--r--components/libc/compilers/gcc/partial/SConscript15
-rw-r--r--components/libc/compilers/gcc/partial/mips/SConscript20
-rw-r--r--components/libc/compilers/gcc/partial/mips/readme.md4
-rw-r--r--components/libc/compilers/gcc/partial/mips/sys/select.h52
-rw-r--r--components/libc/compilers/gcc/partial/readme.md2
-rw-r--r--components/libc/compilers/newlib/SConscript29
-rw-r--r--components/libc/compilers/newlib/libc.c50
-rw-r--r--components/libc/compilers/newlib/libc.h28
-rw-r--r--components/libc/compilers/newlib/minilib.c66
-rw-r--r--components/libc/compilers/newlib/stdio.c80
57 files changed, 1138 insertions, 1223 deletions
diff --git a/components/libc/compilers/armlibc/SConscript b/components/libc/compilers/armlibc/SConscript
index 52f7a6d93a..bf1a299304 100644
--- a/components/libc/compilers/armlibc/SConscript
+++ b/components/libc/compilers/armlibc/SConscript
@@ -1,21 +1,12 @@
from building import *
Import('rtconfig')
-src = Glob('*.c') + Glob('*.cpp')
-cwd = GetCurrentDir()
+src = Glob('*.c')
group = []
-CPPPATH = [cwd]
CPPDEFINES = ['RT_USING_ARM_LIBC']
-if GetDepend('RT_USING_DFS') == False:
- SrcRemove(src, ['stdio.c'])
-
-if GetDepend('RT_USING_MODULE') == False:
- SrcRemove(src, ['libc_syms.c'])
-
if rtconfig.PLATFORM == 'armcc' or rtconfig.PLATFORM == 'armclang':
- group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'],
- CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
+ group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPDEFINES = CPPDEFINES)
Return('group')
diff --git a/components/libc/compilers/armlibc/libc.c b/components/libc/compilers/armlibc/libc.c
deleted file mode 100644
index 971ddb8d49..0000000000
--- a/components/libc/compilers/armlibc/libc.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard the first version
- */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <rtthread.h>
-
-#include "libc.h"
-
-#ifdef RT_USING_PTHREADS
-#include <pthread.h>
-#endif
-
-int libc_system_init(void)
-{
-#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS)
- rt_device_t dev_console;
-
- dev_console = rt_console_get_device();
- if (dev_console)
- {
- #if defined(RT_USING_POSIX)
- libc_stdio_set_console(dev_console->parent.name, O_RDWR);
- #else
- libc_stdio_set_console(dev_console->parent.name, O_WRONLY);
- #endif
- }
-#endif
-
-#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT
- pthread_system_init();
-#endif
-
- return 0;
-}
-INIT_COMPONENT_EXPORT(libc_system_init);
diff --git a/components/libc/compilers/armlibc/libc.h b/components/libc/compilers/armlibc/libc.h
deleted file mode 100644
index aecf8cdc50..0000000000
--- a/components/libc/compilers/armlibc/libc.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard the first version
- */
-#ifndef __RTT_LIBC_H__
-#define __RTT_LIBC_H__
-
-#include <stddef.h>
-
-#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);
-int libc_stdio_read(void* buffer, size_t size);
-int libc_stdio_write(const void* buffer, size_t size);
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/components/libc/compilers/armlibc/mem_std.c b/components/libc/compilers/armlibc/mem_std.c
index c350aa68fa..fbfd17eee1 100644
--- a/components/libc/compilers/armlibc/mem_std.c
+++ b/components/libc/compilers/armlibc/mem_std.c
@@ -7,7 +7,8 @@
* 2014-08-03 bernard Add file header.
*/
-#include "rtthread.h"
+#include <rtthread.h>
+#include <stddef.h>
#ifdef RT_USING_HEAP
diff --git a/components/libc/compilers/armlibc/stdio.c b/components/libc/compilers/armlibc/stdio.c
deleted file mode 100644
index c786c78aa5..0000000000
--- a/components/libc/compilers/armlibc/stdio.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard implement stdio for armcc.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <rtthread.h>
-#include "libc.h"
-
-#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS)
-#include <dfs_posix.h>
-
-#define STDIO_DEVICE_NAME_MAX 32
-
-static int std_fd = -1;
-int libc_stdio_set_console(const char* device_name, int mode)
-{
- int fd;
- char name[STDIO_DEVICE_NAME_MAX];
-
- snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
- name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
-
- fd = open(name, mode, 0);
- if (fd >= 0)
- {
- if (std_fd >= 0)
- {
- close(std_fd);
- }
- std_fd = fd;
- }
-
- return std_fd;
-}
-
-int libc_stdio_get_console(void)
-{
- return std_fd;
-}
-
-int libc_stdio_read(void *buffer, size_t size)
-{
- if (std_fd >= 0)
- {
- return read(std_fd, buffer, size);
- }
- else
- {
- rt_kprintf("Illegal stdio input!\n");
- return 0;
- }
-}
-
-int libc_stdio_write(const void *buffer, size_t size)
-{
- if (std_fd >= 0)
- {
- return write(std_fd, buffer, size);
- }
- else
- {
- rt_kprintf("Illegal stdio output!\n");
- return size;
- }
-}
-#endif
diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c
index ce4c358993..755ffef1a6 100644
--- a/components/libc/compilers/armlibc/syscalls.c
+++ b/components/libc/compilers/armlibc/syscalls.c
@@ -15,16 +15,20 @@
* 2020-02-14 Meco Man implement _sys_tmpnam()
*/
-#include <string.h>
#include <rt_sys.h>
-
#include <rtthread.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#ifdef RT_USING_POSIX
#include "libc.h"
-
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
#endif
+#define DBG_TAG "armlibc.syscalls"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
#ifdef __CLANG_ARM
__asm(".global __use_no_semihosting\n\t");
#else
@@ -51,7 +55,7 @@ const char __stderr_name[] = "STDERR";
*/
FILEHANDLE _sys_open(const char *name, int openmode)
{
-#ifdef RT_USING_DFS
+#ifdef RT_USING_POSIX
int fd;
int mode = O_RDONLY;
#endif
@@ -64,8 +68,8 @@ FILEHANDLE _sys_open(const char *name, int openmode)
if (strcmp(name, __stderr_name) == 0)
return (STDERR);
-#ifndef RT_USING_DFS
- return -1;
+#ifndef RT_USING_POSIX
+ return 0; /* error */
#else
/* Correct openmode from fopen to open */
if (openmode & OPEN_PLUS)
@@ -95,21 +99,22 @@ FILEHANDLE _sys_open(const char *name, int openmode)
fd = open(name, mode, 0);
if (fd < 0)
- return -1;
+ return 0; /* error */
else
return fd;
-#endif
+#endif /* RT_USING_POSIX */
}
int _sys_close(FILEHANDLE fh)
{
-#ifndef RT_USING_DFS
- return 0;
-#else
- if (fh <= STDERR) return 0;
+#ifdef RT_USING_POSIX
+ if (fh <= STDERR)
+ return 0; /* error */
return close(fh);
-#endif
+#else
+ return 0;
+#endif /* RT_USING_POSIX */
}
/*
@@ -139,33 +144,32 @@ int _sys_close(FILEHANDLE fh)
*/
int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
{
-#ifdef RT_USING_DFS
+#ifdef RT_USING_POSIX
int size;
-#endif
if (fh == STDIN)
{
-#ifdef RT_USING_POSIX
- size = libc_stdio_read(buf, len);
+ if (libc_stdio_get_console() < 0)
+ {
+ LOG_W("Do not invoke standard output before initializing libc");
+ return 0;
+ }
+ size = read(STDIN_FILENO, buf, len);
return len - size;
-#else
- /* no stdin */
- return -1;
-#endif
+ }
+ else if ((fh == STDOUT) || (fh == STDERR))
+ {
+ return 0; /* error */
}
- if ((fh == STDOUT) || (fh == STDERR))
- return -1;
-
-#ifndef RT_USING_DFS
- return 0;
-#else
size = read(fh, buf, len);
if (size >= 0)
return len - size;
else
- return -1;
-#endif
+ return 0; /* error */
+#else
+ return 0; /* error */
+#endif /* RT_USING_POSIX */
}
/*
@@ -175,41 +179,43 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
*/
int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
{
-#ifdef RT_USING_DFS
+#ifdef RT_USING_POSIX
int size;
-#endif
+#endif /* RT_USING_POSIX */
if ((fh == STDOUT) || (fh == STDERR))
{
-#if !defined(RT_USING_CONSOLE) || !defined(RT_USING_DEVICE)
- return 0;
-#else
#ifdef RT_USING_POSIX
- size = libc_stdio_write(buf, len);
+ if (libc_stdio_get_console() < 0)
+ {
+ LOG_W("Do not invoke standard input before initializing libc");
+ return 0;
+ }
+ size = write(STDOUT_FILENO, buf, len);
return len - size;
-#else
+#elif defined(RT_USING_CONSOLE)
if (rt_console_get_device())
{
rt_device_write(rt_console_get_device(), -1, buf, len);
- return 0;
}
- return -1;
-#endif
-#endif
+ return 0; /* error */
+#endif /* RT_USING_POSIX */
+ }
+ else if (fh == STDIN)
+ {
+ return 0; /* error */
}
- if (fh == STDIN) return -1;
-
-#ifndef RT_USING_DFS
- return 0;
-#else
+#ifdef RT_USING_POSIX
size = write(fh, buf, len);
if (size >= 0)
return len - size;
else
- return -1;
-#endif
+ return 0; /* error */
+#else
+ return 0;
+#endif /* RT_USING_POSIX */
}
/*
@@ -218,16 +224,15 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
*/
int _sys_seek(FILEHANDLE fh, long pos)
{
+#ifdef RT_USING_POSIX
if (fh < STDERR)
- return -1;
-
-#ifndef RT_USING_DFS
- return -1;
-#else
+ return 0; /* error */
/* position is relative to the start of file fh */
return lseek(fh, pos, 0);
-#endif
+#else
+ return 0; /* error */
+#endif /* RT_USING_POSIX */
}
/**
@@ -253,7 +258,7 @@ void _ttywrch(int ch)
c = (char)ch;
rt_kprintf(&c);
-#endif
+#endif /* RT_USING_CONSOLE */
}
/* for exit() and abort() */
@@ -272,17 +277,17 @@ RT_WEAK void _sys_exit(int return_code)
*/
long _sys_flen(FILEHANDLE fh)
{
-#ifdef RT_USING_DFS
+#ifdef RT_USING_POSIX
struct stat stat;
if (fh < STDERR)
- return -1;
+ return 0; /* error */
fstat(fh, &stat);
return stat.st_size;
#else
- return -1;
-#endif
+ return 0;
+#endif /* RT_USING_POSIX */
}
int _sys_istty(FILEHANDLE fh)
@@ -295,33 +300,27 @@ int _sys_istty(FILEHANDLE fh)
int remove(const char *filename)
{
-#ifndef RT_USING_DFS
- return -1;
-#else
+#ifdef RT_USING_POSIX
return unlink(filename);
-#endif
-}
-
-#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) && defined(RT_USING_MODULE) && defined(RT_USING_DFS)
-/* use system(const char *string) implementation in the msh */
#else
-int system(const char *string)
-{
- extern int __rt_libc_system(const char *string);
- return __rt_libc_system(string);
+ return 0; /* error */
+#endif /* RT_USING_POSIX */
}
-#endif
#ifdef __MICROLIB
#include <stdio.h>
int fputc(int c, FILE *f)
{
+#ifdef RT_USING_CONSOLE
char ch[2] = {0};
ch[0] = c;
rt_kprintf(&ch[0]);
return 1;
+#else
+ return 0; /* error */
+#endif /* RT_USING_CONSOLE */
}
int fgetc(FILE *f)
@@ -329,10 +328,16 @@ int fgetc(FILE *f)
#ifdef RT_USING_POSIX
char ch;
- if (libc_stdio_read(&ch, 1) == 1)
- return ch;
-#endif
+ if (libc_stdio_get_console() < 0)
+ {
+ LOG_W("Do not invoke standard output before initializing libc");
+ return 0;
+ }
- return -1;
+ if(read(STDIN_FILENO, &ch, 1) == 1)
+ return ch;
+#endif /* RT_USING_POSIX */
+ return 0; /* error */
}
-#endif
+
+#endif /* __MICROLIB */
diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript
index b1982aa329..504bf84e56 100644
--- a/components/libc/compilers/common/SConscript
+++ b/components/libc/compilers/common/SConscript
@@ -1,30 +1,25 @@
from building import *
-
Import('rtconfig')
src = []
cwd = GetCurrentDir()
group = []
CPPPATH = [cwd]
+CPPDEFINES = []
+
+if rtconfig.CROSS_TOOL == 'keil':
+ CPPDEFINES += ['__CLK_TCK=RT_TICK_PER_SECOND']
if GetDepend('RT_USING_LIBC'):
src += Glob('*.c')
- if GetDepend('RT_USING_POSIX') == False:
- SrcRemove(src, ['unistd.c', 'delay.c'])
elif GetDepend('RT_LIBC_USING_TIME'):
src += ['time.c']
-if rtconfig.CROSS_TOOL == 'keil':
- CPPDEFINES = ['__CLK_TCK=RT_TICK_PER_SECOND']
-else:
- CPPDEFINES = []
-
group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
list = os.listdir(cwd)
-for d in list:
- path = os.path.join(cwd, d)
- if os.path.isfile(os.path.join(path, 'SConscript')):
- group = group + SConscript(os.path.join(d, 'SConscript'))
+for item in list:
+ if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
+ group = group + SConscript(os.path.join(item, 'SConscript'))
Return('group')
diff --git a/components/libc/compilers/common/delay.c b/components/libc/compilers/common/delay.c
deleted file mode 100644
index 4666258d3b..0000000000
--- a/components/libc/compilers/common/delay.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2021-05-07 Meco Man first Version
- */
-#include <rtthread.h>
-#include <rthw.h>
-
-void msleep(unsigned int msecs)
-{
- rt_thread_mdelay(msecs);
-}
-RTM_EXPORT(msleep);
-
-void ssleep(unsigned int seconds)
-{
- msleep(seconds * 1000);
-}
-RTM_EXPORT(ssleep);
-
-void mdelay(unsigned long msecs)
-{
- rt_hw_us_delay(msecs * 1000);
-}
-RTM_EXPORT(mdelay);
-
-void udelay(unsigned long usecs)
-{
- rt_hw_us_delay(usecs);
-}
-RTM_EXPORT(udelay);
-
-void ndelay(unsigned long nsecs)
-{
- rt_hw_us_delay(1);
-}
-RTM_EXPORT(ndelay);
diff --git a/components/libc/compilers/common/dirent.h b/components/libc/compilers/common/dirent.h
index bfba586093..a6353fd6f8 100644
--- a/components/libc/compilers/common/dirent.h
+++ b/components/libc/compilers/common/dirent.h
@@ -6,10 +6,14 @@
* Change Logs:
* Date Author Notes
*/
-#ifndef __RTT_DIRENT_H__
-#define __RTT_DIRENT_H__
+#ifndef __DIRENT_H__
+#define __DIRENT_H__
-#include <rtthread.h>
+#include <rtdef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
/*
* dirent.h - format of directory entries
@@ -26,27 +30,28 @@
#define DT_REG 0x01
#define DT_DIR 0x02
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#ifndef HAVE_DIR_STRUCTURE
+#define HAVE_DIR_STRUCTURE
typedef struct
{
int fd; /* directory file */
char buf[512];
int num;
int cur;
-} DIR;
+}DIR;
#endif
#ifndef HAVE_DIRENT_STRUCTURE
+#define HAVE_DIRENT_STRUCTURE
+
+#define DIRENT_NAME_MAX 256
+
struct dirent
{
rt_uint8_t d_type; /* The type of the file */
rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */
rt_uint16_t d_reclen; /* length of this record */
- char d_name[256]; /* The null-terminated file name */
+ char d_name[DIRENT_NAME_MAX]; /* The null-terminated file name */
};
#endif
diff --git a/components/libc/compilers/common/fcntl.h b/components/libc/compilers/common/fcntl.h
new file mode 100644
index 0000000000..3460926708
--- /dev/null
+++ b/components/libc/compilers/common/fcntl.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-09-02 Meco Man First version
+ */
+#ifndef __FCNTL_H__
+#define __FCNTL_H__
+
+#include <sys/types.h>
+
+#define O_RDONLY 0x0000 /* open for reading only */
+#define O_WRONLY 0x0001 /* open for writing only */
+#define O_RDWR 0x0002 /* open for reading and writing */
+#define O_ACCMODE 0x0003 /* mask for above modes */
+
+#define O_CREAT 0100
+#define O_EXCL 0200
+#define O_NOCTTY 0400
+#define O_TRUNC 01000
+#define O_APPEND 02000
+#define O_NONBLOCK 04000
+#define O_DSYNC 010000
+#define O_SYNC 04010000
+#define O_RSYNC 04010000
+#define O_BINARY 0100000
+#define O_DIRECTORY 0200000
+#define O_NOFOLLOW 0400000
+#define O_CLOEXEC 02000000
+#define O_ASYNC 020000
+#define O_DIRECT 040000
+#define O_LARGEFILE 0100000
+#define O_NOATIME 01000000
+#define O_PATH 010000000
+#define O_TMPFILE 020200000
+#define O_NDELAY O_NONBLOCK
+#define O_SEARCH O_PATH
+#define O_EXEC O_PATH
+
+#define F_DUPFD 0
+#define F_GETFD 1
+#define F_SETFD 2
+#define F_GETFL 3
+#define F_SETFL 4
+
+#define F_SETOWN 8
+#define F_GETOWN 9
+#define F_SETSIG 10
+#define F_GETSIG 11
+
+#define F_GETLK 12
+#define F_SETLK 13
+#define F_SETLKW 14
+
+#define F_SETOWN_EX 15
+#define F_GETOWN_EX 16
+
+#define F_GETOWNER_UIDS 17
+
+int open(const char *file, int flags, ...);
+int fcntl(int fildes, int cmd, ...);
+int creat(const char *, mode_t);
+
+#endif
diff --git a/components/libc/compilers/common/none-gcc/SConscript b/components/libc/compilers/common/nogcc/SConscript
index c766c8f82d..c766c8f82d 100644
--- a/components/libc/compilers/common/none-gcc/SConscript
+++ b/components/libc/compilers/common/nogcc/SConscript
diff --git a/components/libc/compilers/common/none-gcc/readme.md b/components/libc/compilers/common/nogcc/readme.md
index b10940d003..b10940d003 100644
--- a/components/libc/compilers/common/none-gcc/readme.md
+++ b/components/libc/compilers/common/nogcc/readme.md
diff --git a/components/libc/compilers/common/none-gcc/sys/errno.h b/components/libc/compilers/common/nogcc/sys/errno.h
index ad3614024d..ff1abca387 100644
--- a/components/libc/compilers/common/none-gcc/sys/errno.h
+++ b/components/libc/compilers/common/nogcc/sys/errno.h
@@ -7,8 +7,8 @@
* Date Author Notes
* 2021-05-22 Meco Man The first version.
*/
-#ifndef _SYS_ERRNO_H
-#define _SYS_ERRNO_H
+#ifndef __SYS_ERRNO_H__
+#define __SYS_ERRNO_H__
#if defined(__ARMCC_VERSION)
/*
diff --git a/components/libc/compilers/common/nogcc/sys/select.h b/components/libc/compilers/common/nogcc/sys/select.h
new file mode 100644
index 0000000000..02fb77dd89
--- /dev/null
+++ b/components/libc/compilers/common/nogcc/sys/select.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-07-21 Meco Man The first version
+ */
+
+#ifndef __SYS_SELECT_H__
+#define __SYS_SELECT_H__
+
+#include <rtconfig.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#ifdef _WIN32
+#include <winsock.h>
+#endif
+
+#ifndef FD_SETSIZE
+#define FD_SETSIZE 32
+#endif
+
+#ifdef SAL_USING_POSIX
+#ifdef FD_SETSIZE
+#undef FD_SETSIZE
+#endif
+#define FD_SETSIZE DFS_FD_MAX
+#endif /* SAL_USING_POSIX */
+
+typedef long fd_mask;
+
+#ifndef _WIN32
+#ifndef _SYS_TYPES_FD_SET /* MIPS */
+
+#define NBBY 8 /* number of bits in a byte */
+#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
+#ifndef howmany
+#define howmany(x,y) (((x)+((y)-1))/(y))
+#endif
+
+typedef struct _types_fd_set {
+ fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
+} _types_fd_set;
+#define fd_set _types_fd_set
+
+#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
+#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
+#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
+#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
+#endif /* _SYS_TYPES_FD_SET */
+
+int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
+#endif /* _WIN32 */
+
+#endif /* __SYS_SELECT_H__ */
diff --git a/components/libc/compilers/common/nogcc/sys/stat.h b/components/libc/compilers/common/nogcc/sys/stat.h
new file mode 100644
index 0000000000..107c15decf
--- /dev/null
+++ b/components/libc/compilers/common/nogcc/sys/stat.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-09-02 Meco Man First version
+ */
+
+#ifndef __SYS_STAT_H__
+#define __SYS_STAT_H__
+
+#include <sys/types.h>
+#include <sys/time.h>
+
+#define S_IFMT 00170000
+#define S_IFSOCK 0140000
+#define S_IFLNK 0120000
+#define S_IFREG 0100000
+#define S_IFBLK 0060000
+#define S_IFDIR 0040000
+#define S_IFCHR 0020000
+#define S_IFIFO 0010000
+#define S_ISUID 0004000
+#define S_ISGID 0002000
+#define S_ISVTX 0001000
+
+#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
+#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
+#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
+#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
+#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
+#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
+
+#define S_IRWXU 00700
+#define S_IRUSR 00400
+#define S_IWUSR 00200
+#define S_IXUSR 00100
+
+#define S_IRWXG 00070
+#define S_IRGRP 00040
+#define S_IWGRP 00020
+#define S_IXGRP 00010
+
+#define S_IRWXO 00007
+#define S_IROTH 00004
+#define S_IWOTH 00002
+#define S_IXOTH 00001
+
+struct stat
+{
+ struct rt_device *st_dev;
+ uint16_t st_ino;
+ uint16_t st_mode;
+ uint16_t st_nlink;
+ uint16_t st_uid;
+ uint16_t st_gid;
+ struct rt_device *st_rdev;
+ uint32_t st_size;
+ time_t st_atime;
+ long st_spare1;
+ time_t st_mtime;
+ long st_spare2;
+ time_t st_ctime;
+ long st_spare3;
+ uint32_t st_blksize;
+ uint32_t st_blocks;
+ long st_spare4[2];
+};
+
+int chmod(const char *, mode_t);
+int fchmod(int, mode_t);
+int fstat(int, struct stat *);
+int lstat(const char *, struct stat *);
+int mkdir(const char *, mode_t);
+int mkfifo(const char *, mode_t);
+int mknod(const char *, mode_t, dev_t);
+int stat(const char *, struct stat *);
+mode_t umask(mode_t);
+
+#endif
diff --git a/components/libc/compilers/common/none-gcc/sys/types.h b/components/libc/compilers/common/nogcc/sys/types.h
index 7222326a2a..5672f54a4d 100644
--- a/components/libc/compilers/common/none-gcc/sys/types.h
+++ b/components/libc/compilers/common/nogcc/sys/types.h
@@ -8,10 +8,12 @@
* 2020-09-05 Meco Man fix bugs
* 2020-12-16 Meco Man add useconds_t
*/
-#ifndef __TYPES_H__
-#define __TYPES_H__
+#ifndef __SYS_TYPES_H__
+#define __SYS_TYPES_H__
#include <stdint.h>
+#include <stddef.h>
+#include <time.h>
typedef int32_t clockid_t;
typedef int32_t key_t; /* Used for interprocess communication. */
@@ -25,6 +27,7 @@ typedef signed int ssize_t; /* Used for a count of bytes or an error
#else
typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */
#endif
+typedef long suseconds_t; /* microseconds. */
typedef unsigned long useconds_t; /* microseconds (unsigned) */
typedef unsigned long dev_t;
diff --git a/components/libc/compilers/common/nogcc/sys/unistd.h b/components/libc/compilers/common/nogcc/sys/unistd.h
new file mode 100644
index 0000000000..6195c4c2aa
--- /dev/null
+++ b/components/libc/compilers/common/nogcc/sys/unistd.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-12-16 Meco Man add usleep
+ * 2021-09-11 Meco Man move functions from dfs_posix.h to unistd.h
+ */
+#ifndef __SYS_UNISTD_H__
+#define __SYS_UNISTD_H__
+
+#include <stddef.h>
+#include "types.h" /* <sys/types.h> */
+
+#define STDIN_FILENO 0 /* standard input file descriptor */
+#define STDOUT_FILENO 1 /* standard output file descriptor */
+#define STDERR_FILENO 2 /* standard error file descriptor */
+
+ssize_t read(int fd, void *buf, size_t len);
+ssize_t write(int fd, const void *buf, size_t len);
+off_t lseek(int fd, off_t offset, int whence);
+int fsync(int fildes);
+int unlink(const char *pathname);
+int close(int d);
+int ftruncate(int fd, off_t length);
+int rmdir(const char *path);
+int chdir(const char *path);
+char *getcwd(char *buf, size_t size);
+int access(const char *path, int amode);
+int pipe(int fildes[2]);
+int isatty(int fd);
+char *ttyname(int desc);
+unsigned int sleep(unsigned int seconds);
+int usleep(useconds_t usec);
+pid_t gettid(void);
+pid_t getpid(void);
+pid_t getppid(void);
+uid_t getuid(void);
+uid_t geteuid(void);
+gid_t getgid(void);
+gid_t getegid(void);
+
+#endif /* _SYS_UNISTD_H */
diff --git a/components/libc/compilers/common/none-gcc/unistd.h b/components/libc/compilers/common/nogcc/unistd.h
index cd77a12e3b..cd77a12e3b 100644
--- a/components/libc/compilers/common/none-gcc/unistd.h
+++ b/components/libc/compilers/common/nogcc/unistd.h
diff --git a/components/libc/compilers/common/none-gcc/sys/stat.h b/components/libc/compilers/common/none-gcc/sys/stat.h
deleted file mode 100644
index c4b42083c4..0000000000
--- a/components/libc/compilers/common/none-gcc/sys/stat.h
+++ /dev/null
@@ -1,8 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
diff --git a/components/libc/compilers/common/none-gcc/sys/unistd.h b/components/libc/compilers/common/none-gcc/sys/unistd.h
deleted file mode 100644
index 2f01f660b3..0000000000
--- a/components/libc/compilers/common/none-gcc/sys/unistd.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2020-12-16 Meco Man add usleep
- */
-#ifndef _SYS_UNISTD_H
-#define _SYS_UNISTD_H
-
-#include <rtconfig.h>
-#include "types.h"
-
-#ifdef RT_USING_DFS
-
-#define STDIN_FILENO 0 /* standard input file descriptor */
-#define STDOUT_FILENO 1 /* standard output file descriptor */
-#define STDERR_FILENO 2 /* standard error file descriptor */
-
-#include <dfs_posix.h>
-#else
-#define _FREAD 0x0001 /* read enabled */
-#define _FWRITE 0x0002 /* write enabled */
-#define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */
-#define _FMARK 0x0010 /* internal; mark during gc() */
-#define _FDEFER 0x0020 /* internal; defer for next gc pass */
-#define _FASYNC 0x0040 /* signal pgrp when data ready */
-#define _FSHLOCK 0x0080 /* BSD flock() shared lock present */
-#define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */
-#define _FCREAT 0x0200 /* open with file create */
-#define _FTRUNC 0x0400 /* open with truncation */
-#define _FEXCL 0x0800 /* error on open if file exists */
-#define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */
-#define _FSYNC 0x2000 /* do all writes synchronously */
-#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */
-#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */
-#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */
-
-
-#ifndef O_RDONLY
-#define O_RDONLY 0 /* +1 == FREAD */
-#endif
-#ifndef O_WRONLY
-#define O_WRONLY 1 /* +1 == FWRITE */
-#endif
-#ifndef O_RDWR
-#define O_RDWR 2 /* +1 == FREAD|FWRITE */
-#endif
-#ifndef O_APPEND
-#define O_APPEND _FAPPEND
-#endif
-#ifndef O_CREAT
-#define O_CREAT _FCREAT
-#endif
-#ifndef O_TRUNC
-#define O_TRUNC _FTRUNC
-#endif
-#ifndef O_EXCL
-#define O_EXCL _FEXCL
-#endif
-#ifndef O_SYNC
-#define O_SYNC _FSYNC
-#endif
-
-#endif
-
-int isatty (int fd);
-char * ttyname (int desc);
-unsigned int sleep(unsigned int seconds);
-int usleep(useconds_t usec);
-pid_t gettid(void);
-pid_t getpid(void);
-pid_t getppid(void);
-uid_t getuid(void);
-uid_t geteuid(void);
-gid_t getgid(void);
-gid_t getegid(void);
-
-#endif /* _SYS_UNISTD_H */
diff --git a/components/libc/compilers/common/poll.h b/components/libc/compilers/common/poll.h
new file mode 100644
index 0000000000..aea73d6eaf
--- /dev/null
+++ b/components/libc/compilers/common/poll.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-09-11 Meco Man First version
+ */
+#ifndef __POLL_H__
+#define __POLL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if !defined(POLLIN) && !defined(POLLOUT)
+#define POLLIN (0x01)
+#define POLLRDNORM (0x01)
+#define POLLRDBAND (0x01)
+#define POLLPRI (0x01)
+
+#define POLLOUT (0x02)
+#define POLLWRNORM (0x02)
+#define POLLWRBAND (0x02)
+
+#define POLLERR (0x04)
+#define POLLHUP (0x08)
+#define POLLNVAL (0x10)
+
+typedef unsigned int nfds_t;
+
+struct pollfd
+{
+ int fd;
+ short events;
+ short revents;
+};
+#endif /* !defined(POLLIN) && !defined(POLLOUT) */
+
+#define POLLMASK_DEFAULT (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
+
+int poll(struct pollfd *fds, nfds_t nfds, int timeout);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __POLL_H__ */
diff --git a/components/libc/compilers/common/readme.md b/components/libc/compilers/common/readme.md
index 856ddeb045..82e23f8970 100644
--- a/components/libc/compilers/common/readme.md
+++ b/components/libc/compilers/common/readme.md
@@ -1,10 +1 @@
-## Attentions
-
-1. This folder is "common" for all toolchains.
-
-2. If you want to add new `.c` files, please do not forget to fix SConscript file too. eg:
-
-```python
-if GetDepend('RT_USING_POSIX') == False:
- SrcRemove(src, ['unistd.c'])
-``` \ No newline at end of file
+This folder is "common" for all toolchains. \ No newline at end of file
diff --git a/components/libc/compilers/common/stdlib.c b/components/libc/compilers/common/stdlib.c
index 9d8952e99e..6cc0b9fdac 100644
--- a/components/libc/compilers/common/stdlib.c
+++ b/components/libc/compilers/common/stdlib.c
@@ -10,19 +10,36 @@
#include <rtthread.h>
+#define DBG_TAG "stdlib"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
void __rt_libc_exit(int status)
{
rt_thread_t self = rt_thread_self();
if (self != RT_NULL)
{
- rt_kprintf("thread:%s exit:%d!\n", self->name, status);
+ LOG_E("thread:%s exit:%d!", self->name, status);
rt_thread_control(self, RT_THREAD_CTRL_CLOSE, RT_NULL);
}
}
-int __rt_libc_system(const char *string)
+#ifdef RT_USING_MSH
+int system(const char *command)
{
- /* TODO */
- return 0;
+ extern int msh_exec(char *cmd, rt_size_t length);
+
+ int ret = -RT_ENOMEM;
+ char *cmd = rt_strdup(command);
+
+ if (cmd)
+ {
+ ret = msh_exec(cmd, rt_strlen(cmd));
+ rt_free(cmd);
+ }
+
+ return ret;
}
+RTM_EXPORT(system);
+#endif
diff --git a/components/libc/compilers/common/sys/ioctl.h b/components/libc/compilers/common/sys/ioctl.h
index 51f51f2ea4..04f73837bc 100644
--- a/components/libc/compilers/common/sys/ioctl.h
+++ b/components/libc/compilers/common/sys/ioctl.h
@@ -15,6 +15,10 @@
#include <dfs_posix.h>
#endif
+#ifdef _WIN32
+#include <winsock.h>
+#endif
+
struct winsize {
unsigned short ws_row;
unsigned short ws_col;
@@ -35,8 +39,8 @@ struct winsize {
#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */
#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */
-#define FIONWRITE _IOR('f', 121, int) /* get # bytes outstanding in send queue */
#endif
+#define FIONWRITE _IOR('f', 121, int) /* get # bytes outstanding in send queue */
#define TCGETS 0x5401
#define TCSETS 0x5402
@@ -235,4 +239,6 @@ struct winsize {
#define SIOCDEVPRIVATE 0x89F0
#define SIOCPROTOPRIVATE 0x89E0
+int ioctl(int fildes, int cmd, ...);
+
#endif
diff --git a/components/libc/compilers/common/sys/signal.h b/components/libc/compilers/common/sys/signal.h
new file mode 100644
index 0000000000..9787958a37
--- /dev/null
+++ b/components/libc/compilers/common/sys/signal.h
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-09-12 Bernard The first version
+ * 2021-07-21 Meco Man move to libc/common
+ */
+
+#ifndef __SYS_SIGNAL_H__
+#define __SYS_SIGNAL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+
+/* Signal Generation and Delivery, P1003.1b-1993, p. 63
+ NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and
+ sigev_notify_attributes to the sigevent structure. */
+union sigval
+{
+ int sival_int; /* Integer signal value */
+ void *sival_ptr; /* Pointer signal value */
+};
+
+struct sigevent
+{
+ int sigev_notify; /* Notification type */
+ int sigev_signo; /* Signal number */
+ union sigval sigev_value; /* Signal value */
+ void (*sigev_notify_function)( union sigval );
+ /* Notification function */
+ void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t */
+};
+
+struct siginfo
+{
+ uint16_t si_signo;
+ uint16_t si_code;
+
+ union sigval si_value;
+};
+typedef struct siginfo siginfo_t;
+
+#define SI_USER 0x01 /* Signal sent by kill(). */
+#define SI_QUEUE 0x02 /* Signal sent by sigqueue(). */
+#define SI_TIMER 0x03 /* Signal generated by expiration of a timer set by timer_settime(). */
+#define SI_ASYNCIO 0x04 /* Signal generated by completion of an asynchronous I/O request. */
+#define SI_MESGQ 0x05 /* Signal generated by arrival of a message on an empty message queue. */
+
+typedef void (*_sig_func_ptr)(int);
+typedef unsigned long sigset_t;
+
+struct sigaction
+{
+ _sig_func_ptr sa_handler;
+ sigset_t sa_mask;
+ int sa_flags;
+};
+
+#define SIG_SETMASK 0 /* set mask with sigprocmask() */
+#define SIG_BLOCK 1 /* set of signals to block */
+#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */
+
+#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0)
+#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0)
+#define sigemptyset(what) (*(what) = 0, 0)
+#define sigfillset(what) (*(what) = ~(0), 0)
+#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
+
+int sigprocmask (int how, const sigset_t *set, sigset_t *oset);
+int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
+
+#ifdef __ARMCC_VERSION
+#define SIGHUP 1
+/* #define SIGINT 2 */
+#define SIGQUIT 3
+/* #define SIGILL 4 */
+#define SIGTRAP 5
+/* #define SIGABRT 6 */
+#define SIGEMT 7
+/* #define SIGFPE 8 */
+#define SIGKILL 9
+#define SIGBUS 10
+/* #define SIGSEGV 11 */
+#define SIGSYS 12
+#define SIGPIPE 13
+#define SIGALRM 14
+/* #define SIGTERM 15 */
+#define SIGURG 16
+#define SIGSTOP 17
+#define SIGTSTP 18
+#define SIGCONT 19
+#define SIGCHLD 20
+#define SIGTTIN 21
+#define SIGTTOU 22
+#define SIGPOLL 23
+#define SIGWINCH 24
+/* #define SIGUSR1 25 */
+/* #define SIGUSR2 26 */
+#define SIGRTMIN 27
+#define SIGRTMAX 31
+#define NSIG 32
+
+#include <signal.h>
+
+#elif defined(__IAR_SYSTEMS_ICC__)
+#define SIGHUP 1
+#define SIGINT 2
+#define SIGQUIT 3
+#define SIGILL 4
+#define SIGTRAP 5
+/* #define SIGABRT 6 */
+#define SIGEMT 7
+#define SIGFPE 8
+#define SIGKILL 9
+#define SIGBUS 10
+#define SIGSEGV 11
+#define SIGSYS 12
+#define SIGPIPE 13
+#define SIGALRM 14
+#define SIGTERM 15
+#define SIGURG 16
+#define SIGSTOP 17
+#define SIGTSTP 18
+#define SIGCONT 19
+#define SIGCHLD 20
+#define SIGTTIN 21
+#define SIGTTOU 22
+#define SIGPOLL 23
+#define SIGWINCH 24
+#define SIGUSR1 25
+#define SIGUSR2 26
+#define SIGRTMIN 27
+#define SIGRTMAX 31
+#define NSIG 32
+
+#include <signal.h>
+
+#elif defined(__GNUC__)
+#define SIGHUP 1 /* hangup */
+#define SIGINT 2 /* interrupt */
+#define SIGQUIT 3 /* quit */
+#define SIGILL 4 /* illegal instruction (not reset when caught) */
+#define SIGTRAP 5 /* trace trap (not reset when caught) */
+#define SIGIOT 6 /* IOT instruction */
+#define SIGABRT 6 /* used by abort, replace SIGIOT in the future */
+#define SIGEMT 7 /* EMT instruction */
+#define SIGFPE 8 /* floating point exception */
+#define SIGKILL 9 /* kill (cannot be caught or ignored) */
+#define SIGBUS 10 /* bus error */
+#define SIGSEGV 11 /* segmentation violation */
+#define SIGSYS 12 /* bad argument to system call */
+#define SIGPIPE 13 /* write on a pipe with no one to read it */
+#define SIGALRM 14 /* alarm clock */
+#define SIGTERM 15 /* software termination signal from kill */
+#define SIGURG 16 /* urgent condition on IO channel */
+#define SIGSTOP 17 /* sendable stop signal not from tty */
+#define SIGTSTP 18 /* stop signal from tty */
+#define SIGCONT 19 /* continue a stopped process */
+#define SIGCHLD 20 /* to parent on child stop or exit */
+#define SIGCLD 20 /* System V name for SIGCHLD */
+#define SIGTTIN 21 /* to readers pgrp upon background tty read */
+#define SIGTTOU 22 /* like TTIN for output if (tp->t_local&LTOSTOP) */
+#define SIGIO 23 /* input/output possible signal */
+#define SIGPOLL SIGIO /* System V name for SIGIO */
+#define SIGXCPU 24 /* exceeded CPU time limit */
+#define SIGXFSZ 25 /* exceeded file size limit */
+#define SIGVTALRM 26 /* virtual time alarm */
+#define SIGPROF 27 /* profiling time alarm */
+#define SIGWINCH 28 /* window changed */
+#define SIGLOST 29 /* resource lost (eg, record-lock lost) */
+#define SIGUSR1 30 /* user defined signal 1 */
+#define SIGUSR2 31 /* user defined signal 2 */
+#define NSIG 32 /* signal 0 implied */
+
+#ifndef _SIGNAL_H_
+/* Some applications take advantage of the fact that <sys/signal.h>
+ * and <signal.h> are equivalent in glibc. Allow for that here. */
+#include <signal.h>
+#endif
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/components/libc/compilers/common/sys/statfs.h b/components/libc/compilers/common/sys/statfs.h
index 0996af9a18..0c6dc44df3 100644
--- a/components/libc/compilers/common/sys/statfs.h
+++ b/components/libc/compilers/common/sys/statfs.h
@@ -6,16 +6,19 @@
* Change Logs:
* Date Author Notes
*/
-#ifndef __RTT_STATFS_H__
-#define __RTT_STATFS_H__
+#ifndef __SYS_STATFS_H__
+#define __SYS_STATFS_H__
-#include <rtthread.h>
+#include <stddef.h>
struct statfs
{
- rt_size_t f_bsize; /* block size */
- rt_size_t f_blocks; /* total data blocks in file system */
- rt_size_t f_bfree; /* free blocks in file system */
+ size_t f_bsize; /* block size */
+ size_t f_blocks; /* total data blocks in file system */
+ size_t f_bfree; /* free blocks in file system */
};
+int statfs(const char *path, struct statfs *buf);
+int fstatfs(int fd, struct statfs *buf);
+
#endif
diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h
index bb1a9c96fd..d14905ebfb 100644
--- a/components/libc/compilers/common/sys/time.h
+++ b/components/libc/compilers/common/sys/time.h
@@ -8,16 +8,19 @@
* 2020-09-07 Meco Man combine gcc armcc iccarm
* 2021-02-12 Meco Man move all definitions located in <clock_time.h> to this file
*/
-#ifndef _SYS_TIME_H_
-#define _SYS_TIME_H_
+#ifndef __SYS_TIME_H__
+#define __SYS_TIME_H__
#include <rtconfig.h>
+#include <sys/types.h>
+#include <stdint.h>
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
+/* timezone */
#define DST_NONE 0 /* not on dst */
#define DST_USA 1 /* USA style dst */
#define DST_AUST 2 /* Australian style dst */
@@ -30,32 +33,37 @@ extern "C" {
#define DST_TUR 9 /* Turkey */
#define DST_AUSTALT 10 /* Australian style with shift in 1986 */
-#ifndef _TIMEVAL_DEFINED
-#define _TIMEVAL_DEFINED
+struct timezone
+{
+ int tz_minuteswest; /* minutes west of Greenwich */
+ int tz_dsttime; /* type of dst correction */
+};
+
/*
* Structure returned by gettimeofday(2) system call,
* and used in other calls.
*/
-#if !(defined(_WIN32))
-struct timeval {
- long tv_sec; /* seconds */
- long tv_usec; /* and microseconds */
+#ifndef _TIMEVAL_DEFINED
+#define _TIMEVAL_DEFINED
+#if !defined(_WIN32)
+struct timeval
+{
+ time_t tv_sec; /* seconds */
+ suseconds_t tv_usec; /* and microseconds */
};
#endif
#endif /* _TIMEVAL_DEFINED */
-#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !(defined(__ICCARM__) && (__VER__ >= 8010001)) && !defined(_WIN32)
-struct timespec {
+#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && \
+ !(defined(__ICCARM__) && (__VER__ >= 8010001)) && \
+ !defined(_WIN32)
+struct timespec
+{
time_t tv_sec; /* seconds */
long tv_nsec; /* and nanoseconds */
};
#endif
-struct timezone {
- int tz_minuteswest; /* minutes west of Greenwich */
- int tz_dsttime; /* type of dst correction */
-};
-
int stime(const time_t *t);
time_t timegm(struct tm * const t);
int gettimeofday(struct timeval *tv, struct timezone *tz);
@@ -65,8 +73,7 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r);
#endif
#ifdef RT_USING_POSIX
-#include <sys/types.h>
-/* posix clock and timer */
+/* POSIX clock and timer */
#define MILLISECOND_PER_SECOND 1000UL
#define MICROSECOND_PER_SECOND 1000000UL
#define NANOSECOND_PER_SECOND 1000000000UL
@@ -95,9 +102,13 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r);
int clock_getres (clockid_t clockid, struct timespec *res);
int clock_gettime (clockid_t clockid, struct timespec *tp);
int clock_settime (clockid_t clockid, const struct timespec *tp);
-int clock_time_to_tick(const struct timespec *time);
+int rt_timespec_to_tick(const struct timespec *time);
#endif /* RT_USING_POSIX */
+void tz_set(int8_t tz);
+int8_t tz_get(void);
+int8_t tz_is_dst(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/components/libc/compilers/common/none-gcc/fcntl.h b/components/libc/compilers/common/sys/vfs.h
index f247b926e9..00739ab1c6 100644
--- a/components/libc/compilers/common/none-gcc/fcntl.h
+++ b/components/libc/compilers/common/sys/vfs.h
@@ -5,14 +5,11 @@
*
* Change Logs:
* Date Author Notes
+ * 2021-09-11 Meco Man First version
*/
-#ifndef FCNTL_H__
-#define FCNTL_H__
+#ifndef __SYS_VFS_H__
+#define __SYS_VFS_H__
-#include <rtconfig.h>
-
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
+#include "statfs.h" /* <sys/statfs.h> */
#endif
diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c
index e79a22b9db..5bfff15914 100644
--- a/components/libc/compilers/common/time.c
+++ b/components/libc/compilers/common/time.c
@@ -18,24 +18,21 @@
* 2021-02-12 Meco Man move all of the functions located in <clock_time.c> to this file
* 2021-03-15 Meco Man fixed a bug of leaking memory in asctime()
* 2021-05-01 Meco Man support fixed timezone
+ * 2021-07-21 Meco Man implement that change/set timezone APIs
*/
#include "sys/time.h"
#include <sys/errno.h>
#include <rtthread.h>
-
+#include <rthw.h>
#ifdef RT_USING_DEVICE
#include <rtdevice.h>
#endif
-#define DBG_TAG "TIME"
+#define DBG_TAG "time"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
-#ifndef RT_LIBC_FIXED_TIMEZONE
-#define RT_LIBC_FIXED_TIMEZONE 8 /* UTC+8 */
-#endif
-
/* seconds per day */
#define SPD 24*60*60
@@ -104,7 +101,7 @@ static rt_err_t get_timeval(struct timeval *tv)
if (rt_device_open(device, 0) == RT_EOK)
{
rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &tv->tv_sec);
- rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME_US, &tv->tv_usec);
+ rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIMEVAL, tv);
rt_device_close(device);
}
}
@@ -150,7 +147,7 @@ static int set_timeval(struct timeval *tv)
if (rt_device_open(device, 0) == RT_EOK)
{
rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &tv->tv_sec);
- rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME_US, &tv->tv_usec);
+ rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIMEVAL, tv);
rt_device_close(device);
}
}
@@ -202,7 +199,7 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r)
r->tm_mon = i;
r->tm_mday += work - __spm[i];
- r->tm_isdst = 0;
+ r->tm_isdst = tz_is_dst();
return r;
}
RTM_EXPORT(gmtime_r);
@@ -218,7 +215,7 @@ struct tm* localtime_r(const time_t* t, struct tm* r)
{
time_t local_tz;
- local_tz = *t + RT_LIBC_FIXED_TIMEZONE * 3600;
+ local_tz = *t + tz_get() * 3600;
return gmtime_r(&local_tz, r);
}
RTM_EXPORT(localtime_r);
@@ -235,13 +232,36 @@ time_t mktime(struct tm * const t)
time_t timestamp;
timestamp = timegm(t);
- timestamp = timestamp - 3600 * RT_LIBC_FIXED_TIMEZONE;
+ timestamp = timestamp - 3600 * tz_get();
return timestamp;
}
RTM_EXPORT(mktime);
char* asctime_r(const struct tm *t, char *buf)
{
+ /* Checking input validity */
+ if ((int)rt_strlen(days) <= (t->tm_wday << 2) || (int)rt_strlen(months) <= (t->tm_mon << 2))
+ {
+ LOG_W("asctime_r: the input parameters exceeded the limit, please check it.");
+ *(int*) buf = *(int*) days;
+ *(int*) (buf + 4) = *(int*) months;
+ num2str(buf + 8, t->tm_mday);
+ if (buf[8] == '0')
+ buf[8] = ' ';
+ buf[10] = ' ';
+ num2str(buf + 11, t->tm_hour);
+ buf[13] = ':';
+ num2str(buf + 14, t->tm_min);
+ buf[16] = ':';
+ num2str(buf + 17, t->tm_sec);
+ buf[19] = ' ';
+ num2str(buf + 20, 2000 / 100);
+ num2str(buf + 22, 2000 % 100);
+ buf[24] = '\n';
+ buf[25] = '\0';
+ return buf;
+ }
+
/* "Wed Jun 30 21:49:08 1993\n" */
*(int*) buf = *(int*) (days + (t->tm_wday << 2));
*(int*) (buf + 4) = *(int*) (months + (t->tm_mon << 2));
@@ -426,7 +446,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
if(tz != RT_NULL)
{
tz->tz_dsttime = DST_NONE;
- tz->tz_minuteswest = -(RT_LIBC_FIXED_TIMEZONE * 60);
+ tz->tz_minuteswest = -(tz_get() * 60);
}
if (tv != RT_NULL && get_timeval(tv) == RT_EOK)
@@ -449,7 +469,6 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
* Thus, the following is purely of historic interest.
*/
if (tv != RT_NULL
- && tv->tv_sec >= 0
&& tv->tv_usec >= 0
&& set_timeval((struct timeval *)tv) == RT_EOK)
{
@@ -468,38 +487,47 @@ RTM_EXPORT(difftime);
RTM_EXPORT(strftime);
#ifdef RT_USING_POSIX
-static struct timeval _timevalue;
-static int clock_time_system_init()
+
+#ifdef RT_USING_RTC
+static volatile struct timeval _timevalue;
+static int _rt_clock_time_system_init()
{
- time_t time;
+ register rt_base_t level;
+ time_t time = 0;
rt_tick_t tick;
rt_device_t device;
- time = 0;
-
-#ifdef RT_USING_RTC
device = rt_device_find("rtc");
if (device != RT_NULL)
{
/* get realtime seconds */
- rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
+ if(rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time) == RT_EOK)
+ {
+ level = rt_hw_interrupt_disable();
+ tick = rt_tick_get(); /* get tick */
+ _timevalue.tv_usec = (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK;
+ _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1;
+ rt_hw_interrupt_enable(level);
+ return 0;
+ }
}
-#else
- LOG_W("Cannot find a RTC device to provide time!");
-#endif
- /* get tick */
- tick = rt_tick_get();
+ level = rt_hw_interrupt_disable();
+ _timevalue.tv_usec = 0;
+ _timevalue.tv_sec = 0;
+ rt_hw_interrupt_enable(level);
- _timevalue.tv_usec = (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK;
- _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1;
-
- return 0;
+ return -1;
}
-INIT_COMPONENT_EXPORT(clock_time_system_init);
+INIT_COMPONENT_EXPORT(_rt_clock_time_system_init);
+#endif /* RT_USING_RTC */
int clock_getres(clockid_t clockid, struct timespec *res)
{
+#ifndef RT_USING_RTC
+ LOG_W("Cannot find a RTC device to save time!");
+ return -1;
+#else
int ret = 0;
if (res == RT_NULL)
@@ -529,11 +557,16 @@ int clock_getres(clockid_t clockid, struct timespec *res)
}
return ret;
+#endif /* RT_USING_RTC */
}
RTM_EXPORT(clock_getres);
int clock_gettime(clockid_t clockid, struct timespec *tp)
{
+#ifndef RT_USING_RTC
+ LOG_W("Cannot find a RTC device to save time!");
+ return -1;
+#else
int ret = 0;
if (tp == RT_NULL)
@@ -546,11 +579,14 @@ int clock_gettime(clockid_t clockid, struct timespec *tp)
{
case CLOCK_REALTIME:
{
- /* get tick */
- int tick = rt_tick_get();
+ int tick;
+ register rt_base_t level;
+ level = rt_hw_interrupt_disable();
+ tick = rt_tick_get(); /* get tick */
tp->tv_sec = _timevalue.tv_sec + tick / RT_TICK_PER_SECOND;
tp->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000;
+ rt_hw_interrupt_enable(level);
}
break;
@@ -574,11 +610,17 @@ int clock_gettime(clockid_t clockid, struct timespec *tp)
}
return ret;
+#endif /* RT_USING_RTC */
}
RTM_EXPORT(clock_gettime);
int clock_settime(clockid_t clockid, const struct timespec *tp)
{
+#ifndef RT_USING_RTC
+ LOG_W("Cannot find a RTC device to save time!");
+ return -1;
+#else
+ register rt_base_t level;
int second;
rt_tick_t tick;
rt_device_t device;
@@ -586,38 +628,36 @@ int clock_settime(clockid_t clockid, const struct timespec *tp)
if ((clockid != CLOCK_REALTIME) || (tp == RT_NULL))
{
rt_set_errno(EINVAL);
-
return -1;
}
/* get second */
second = tp->tv_sec;
- /* get tick */
- tick = rt_tick_get();
+ level = rt_hw_interrupt_disable();
+ tick = rt_tick_get(); /* get tick */
/* update timevalue */
_timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK;
_timevalue.tv_sec = second - tick/RT_TICK_PER_SECOND - 1;
+ rt_hw_interrupt_enable(level);
-#ifdef RT_USING_RTC
/* update for RTC device */
device = rt_device_find("rtc");
if (device != RT_NULL)
{
/* set realtime seconds */
- rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second);
+ if(rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second) == RT_EOK)
+ {
+ return 0;
+ }
}
- else
-#else
- LOG_W("Cannot find a RTC device to save time!");
-#endif
- return -1;
- return 0;
+ return -1;
+#endif /* RT_USING_RTC */
}
RTM_EXPORT(clock_settime);
-int clock_time_to_tick(const struct timespec *time)
+int rt_timespec_to_tick(const struct timespec *time)
{
int tick;
int nsecond, second;
@@ -648,6 +688,32 @@ int clock_time_to_tick(const struct timespec *time)
return tick;
}
-RTM_EXPORT(clock_time_to_tick);
+RTM_EXPORT(rt_timespec_to_tick);
#endif /* RT_USING_POSIX */
+
+
+/* timezone */
+#ifndef RT_LIBC_DEFAULT_TIMEZONE
+#define RT_LIBC_DEFAULT_TIMEZONE 8
+#endif
+
+static volatile int8_t _current_timezone = RT_LIBC_DEFAULT_TIMEZONE;
+
+void tz_set(int8_t tz)
+{
+ register rt_base_t level;
+ level = rt_hw_interrupt_disable();
+ _current_timezone = tz;
+ rt_hw_interrupt_enable(level);
+}
+
+int8_t tz_get(void)
+{
+ return _current_timezone;
+}
+
+int8_t tz_is_dst(void)
+{
+ return 0;
+}
diff --git a/components/libc/compilers/common/unistd.c b/components/libc/compilers/common/unistd.c
deleted file mode 100644
index 9a457c4200..0000000000
--- a/components/libc/compilers/common/unistd.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2020-09-01 Meco Man first Version
- * 2021-02-12 Meco Man move all functions located in <pthread_sleep.c> to this file
- */
-
-#include <unistd.h>
-#include <rtthread.h>
-#include <rthw.h>
-
-#ifdef RT_USING_POSIX_TERMIOS
-#include "termios.h"
-int isatty(int fd)
-{
- struct termios ts;
- return(tcgetattr(fd, &ts) != -1); /*true if no error (is a tty)*/
-}
-#else
-int isatty(int fd)
-{
- if (fd >=0 && fd < 3)
- {
- return 1;
- }
- else
- {
- return 0;
- }
-}
-#endif
-RTM_EXPORT(isatty);
-
-char *ttyname(int fd)
-{
- return "/dev/tty"; /* TODO: need to add more specific */
-}
-RTM_EXPORT(ttyname);
-
-unsigned int sleep(unsigned int seconds)
-{
- if (rt_thread_self() != RT_NULL)
- {
- rt_thread_delay(seconds * RT_TICK_PER_SECOND);
- }
- else /* scheduler has not run yet */
- {
- while(seconds > 0)
- {
- rt_hw_us_delay(1000000u);
- seconds --;
- }
- }
-
- return 0;
-}
-RTM_EXPORT(sleep);
-
-int usleep(useconds_t usec)
-{
- if (rt_thread_self() != RT_NULL)
- {
- rt_thread_mdelay(usec / 1000u);
- }
- else /* scheduler has not run yet */
- {
- rt_hw_us_delay(usec / 1000u);
- }
- rt_hw_us_delay(usec % 1000u);
-
- return 0;
-}
-RTM_EXPORT(usleep);
-
-pid_t gettid(void)
-{
- /*TODO*/
- return 0;
-}
-
-pid_t getpid(void)
-{
- return gettid();
-}
-RTM_EXPORT(getpid);
-
-pid_t getppid(void)
-{
- return 0;
-}
-RTM_EXPORT(getppid);
-
-uid_t getuid(void)
-{
- return 0; /*ROOT*/
-}
-RTM_EXPORT(getuid);
-
-uid_t geteuid(void)
-{
- return 0; /*ROOT*/
-}
-RTM_EXPORT(geteuid);
-
-gid_t getgid(void)
-{
- return 0; /*ROOT*/
-}
-RTM_EXPORT(getgid);
-
-gid_t getegid(void)
-{
- return 0; /*ROOT*/
-}
-RTM_EXPORT(getegid);
diff --git a/components/libc/compilers/dlib/SConscript b/components/libc/compilers/dlib/SConscript
index 75a5812fab..39707abc61 100644
--- a/components/libc/compilers/dlib/SConscript
+++ b/components/libc/compilers/dlib/SConscript
@@ -1,26 +1,20 @@
from building import *
-
Import('rtconfig')
src = Glob('*.c')
-cwd = GetCurrentDir()
group = []
-CPPPATH = [cwd]
CPPDEFINES = ['RT_USING_DLIBC']
if rtconfig.PLATFORM == 'iar':
-
- if GetDepend('RT_USING_DFS'):
+ if GetDepend('RT_USING_POSIX'):
from distutils.version import LooseVersion
from iar import IARVersion
CPPDEFINES = CPPDEFINES + ['_DLIB_FILE_DESCRIPTOR']
-
if LooseVersion(IARVersion()) < LooseVersion("8.20.1"):
CPPDEFINES = CPPDEFINES + ['_DLIB_THREAD_SUPPORT']
- group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'],
- CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
+ group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPDEFINES = CPPDEFINES)
Return('group')
diff --git a/components/libc/compilers/dlib/libc.c b/components/libc/compilers/dlib/libc.c
deleted file mode 100644
index d0dca7c5f6..0000000000
--- a/components/libc/compilers/dlib/libc.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard the first version
- */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <rtthread.h>
-
-#include "libc.h"
-
-#ifdef RT_USING_PTHREADS
-#include <pthread.h>
-#endif
-
-int libc_system_init(void)
-{
-#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS)
- rt_device_t dev_console;
-
- dev_console = rt_console_get_device();
- if (dev_console)
- {
- #if defined(RT_USING_POSIX)
- libc_stdio_set_console(dev_console->parent.name, O_RDWR);
- #else
- libc_stdio_set_console(dev_console->parent.name, O_WRONLY);
- #endif
- }
-#endif
-
-#if defined (RT_USING_PTHREADS) && !defined (RT_USING_COMPONENTS_INIT)
- pthread_system_init();
-#endif
-
- return 0;
-}
-INIT_COMPONENT_EXPORT(libc_system_init);
-
diff --git a/components/libc/compilers/dlib/libc.h b/components/libc/compilers/dlib/libc.h
deleted file mode 100644
index fc3cafca78..0000000000
--- a/components/libc/compilers/dlib/libc.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard the first version
- */
-
-#ifndef __RTT_LIBC_H__
-#define __RTT_LIBC_H__
-
-#include <stddef.h>
-
-#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);
-int libc_stdio_read(void* buffer, size_t size);
-int libc_stdio_write(const void* buffer, size_t size);
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/components/libc/compilers/dlib/stdio.c b/components/libc/compilers/dlib/stdio.c
deleted file mode 100644
index c11157d759..0000000000
--- a/components/libc/compilers/dlib/stdio.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard implement stdio for IAR dlib.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <rtthread.h>
-#include "libc.h"
-
-#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS)
-#include <dfs_posix.h>
-
-#define STDIO_DEVICE_NAME_MAX 32
-
-static int std_fd = -1;
-int libc_stdio_set_console(const char* device_name, int mode)
-{
- int fd;
- char name[STDIO_DEVICE_NAME_MAX];
-
- snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
- name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
-
- fd = open(name, mode, 0);
- if (fd >= 0)
- {
- if (std_fd >= 0)
- {
- close(std_fd);
- }
- std_fd = fd;
- }
-
- return std_fd;
-}
-
-int libc_stdio_get_console(void) {
- return std_fd;
-}
-
-int libc_stdio_read(void *buffer, size_t size)
-{
- return read(std_fd, buffer, size);
-}
-
-int libc_stdio_write(const void *buffer, size_t size)
-{
- return write(std_fd, buffer, size);
-}
-#endif
diff --git a/components/libc/compilers/dlib/syscall_close.c b/components/libc/compilers/dlib/syscall_close.c
index 7ed1cc2f2d..2897c2418a 100644
--- a/components/libc/compilers/dlib/syscall_close.c
+++ b/components/libc/compilers/dlib/syscall_close.c
@@ -8,10 +8,8 @@
* 2015-01-28 Bernard first version
*/
#include <rtthread.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
#include <yfuns.h>
+#include <unistd.h>
#pragma module_name = "?__close"
int __close(int handle)
@@ -20,10 +18,9 @@ int __close(int handle)
handle == _LLIO_STDERR ||
handle == _LLIO_STDIN)
return _LLIO_ERROR;
-
-#ifdef RT_USING_DFS
+#ifdef RT_USING_POSIX
return close(handle);
#else
- return 0;
-#endif
+ return _LLIO_ERROR;
+#endif /* RT_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_lseek.c b/components/libc/compilers/dlib/syscall_lseek.c
index 47a069bf0a..4ea55ef1c3 100644
--- a/components/libc/compilers/dlib/syscall_lseek.c
+++ b/components/libc/compilers/dlib/syscall_lseek.c
@@ -8,10 +8,8 @@
* 2015-01-28 Bernard first version
*/
#include <rtthread.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
#include <yfuns.h>
+#include <unistd.h>
#pragma module_name = "?__lseek"
long __lseek(int handle, long offset, int whence)
@@ -20,10 +18,9 @@ long __lseek(int handle, long offset, int whence)
handle == _LLIO_STDERR ||
handle == _LLIO_STDIN)
return _LLIO_ERROR;
-
-#ifdef RT_USING_DFS
+#ifdef RT_USING_POSIX
return lseek(handle, offset, whence);
#else
return _LLIO_ERROR;
-#endif
+#endif /* RT_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_open.c b/components/libc/compilers/dlib/syscall_open.c
index 37bfcecb47..8fb3c3a11f 100644
--- a/components/libc/compilers/dlib/syscall_open.c
+++ b/components/libc/compilers/dlib/syscall_open.c
@@ -10,17 +10,13 @@
#include <rtthread.h>
#include <yfuns.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
+#include <fcntl.h>
#pragma module_name = "?__open"
int __open(const char *filename, int mode)
{
-#ifndef RT_USING_DFS
- return _LLIO_ERROR;
-#else
+#ifdef RT_USING_POSIX
int handle;
int open_mode = O_RDONLY;
@@ -70,5 +66,7 @@ int __open(const char *filename, int mode)
return _LLIO_ERROR;
return handle;
-#endif
+#else
+ return _LLIO_ERROR;
+#endif /* RT_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c
index afb661bd93..74cedb966a 100644
--- a/components/libc/compilers/dlib/syscall_read.c
+++ b/components/libc/compilers/dlib/syscall_read.c
@@ -9,35 +9,39 @@
*/
#include <rtthread.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
#include <yfuns.h>
+#include <unistd.h>
+#ifdef RT_USING_POSIX
#include "libc.h"
+#endif
+
+#define DBG_TAG "dlib.syscall_read"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
#pragma module_name = "?__read"
size_t __read(int handle, unsigned char *buf, size_t len)
{
-#ifdef RT_USING_DFS
+#ifdef RT_USING_POSIX
int size;
-#endif
if (handle == _LLIO_STDIN)
{
-#ifdef RT_USING_POSIX
- return libc_stdio_read(buf, len);
-#else
- return _LLIO_ERROR;
-#endif
+ if (libc_stdio_get_console() < 0)
+ {
+ LOG_W("Do not invoke standard input before initializing libc");
+ return 0;
+ }
+ return read(STDIN_FILENO, buf, len);
}
-
- if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
+ else if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
+ {
return _LLIO_ERROR;
+ }
-#ifndef RT_USING_DFS
- return _LLIO_ERROR;
-#else
size = read(handle, buf, len);
return size;
-#endif
+#else
+ return _LLIO_ERROR;
+#endif /* RT_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_remove.c b/components/libc/compilers/dlib/syscall_remove.c
index 7d74236f4c..05bfbb67ae 100644
--- a/components/libc/compilers/dlib/syscall_remove.c
+++ b/components/libc/compilers/dlib/syscall_remove.c
@@ -8,17 +8,15 @@
* 2015-01-28 Bernard first version
*/
#include <rtthread.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
#include <yfuns.h>
+#include <unistd.h>
#pragma module_name = "?remove"
int remove(const char *val)
{
-#ifndef RT_USING_DFS
- return -1;
-#else
+#ifdef RT_USING_POSIX
return unlink(val);
-#endif
+#else
+ return -1;
+#endif /* RT_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c
index de464530b8..ab011c1096 100644
--- a/components/libc/compilers/dlib/syscall_write.c
+++ b/components/libc/compilers/dlib/syscall_write.c
@@ -9,46 +9,56 @@
*/
#include <rtthread.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
#include <yfuns.h>
+#include <unistd.h>
+#ifdef RT_USING_POSIX
#include "libc.h"
+#endif
+
+#define DBG_TAG "dlib.syscall_write"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
#pragma module_name = "?__write"
size_t __write(int handle, const unsigned char *buf, size_t len)
{
-#ifdef RT_USING_DFS
+#ifdef RT_USING_POSIX
int size;
-#endif
+#endif /* RT_USING_POSIX */
if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
{
-#ifndef RT_USING_CONSOLE
- return _LLIO_ERROR;
-#else
-
#ifdef RT_USING_POSIX
- return libc_stdio_write((void*)buf, len);
-#else
+ if (libc_stdio_get_console() < 0)
+ {
+ LOG_W("Do not invoke standard output before initializing libc");
+ return 0;
+ }
+ return write(STDOUT_FILENO, (void*)buf, len);
+#elif defined(RT_USING_CONSOLE)
rt_device_t console_device;
console_device = rt_console_get_device();
- if (console_device != 0) rt_device_write(console_device, 0, buf, len);
+ if (console_device != 0)
+ {
+ rt_device_write(console_device, 0, buf, len);
+ }
return len;
-#endif
-#endif
+#else
+ return _LLIO_ERROR;
+#endif /* RT_USING_POSIX */
+ }
+ else if (handle == _LLIO_STDIN)
+ {
+ return _LLIO_ERROR;
}
- if (handle == _LLIO_STDIN) return _LLIO_ERROR;
-
-#ifndef RT_USING_DFS
- return _LLIO_ERROR;
-#else
+#ifdef RT_USING_POSIX
size = write(handle, buf, len);
return size;
-#endif
+#else
+ return _LLIO_ERROR;
+#endif /* RT_USING_POSIX */
}
-
diff --git a/components/libc/compilers/dlib/syscalls.c b/components/libc/compilers/dlib/syscalls.c
index e1c9562b3a..1ee6a3bc12 100644
--- a/components/libc/compilers/dlib/syscalls.c
+++ b/components/libc/compilers/dlib/syscalls.c
@@ -6,7 +6,6 @@
* Change Logs:
* Date Author Notes
* 2021-02-13 Meco Man implement exit() and abort()
- * 2021-02-20 Meco Man add system()
*/
#include <rtthread.h>
@@ -17,9 +16,3 @@ void __exit (int status)
__rt_libc_exit(status);
while(1);
}
-
-int system(const char * string)
-{
- extern int __rt_libc_system(const char *string);
- return __rt_libc_system(string);
-}
diff --git a/components/libc/compilers/gcc/SConscript b/components/libc/compilers/gcc/SConscript
new file mode 100644
index 0000000000..4c815c49b8
--- /dev/null
+++ b/components/libc/compilers/gcc/SConscript
@@ -0,0 +1,15 @@
+# RT-Thread building script for bridge
+
+import os
+from building import *
+
+cwd = GetCurrentDir()
+objs = []
+list = os.listdir(cwd)
+
+for d in list:
+ path = os.path.join(cwd, d)
+ if os.path.isfile(os.path.join(path, 'SConscript')):
+ objs = objs + SConscript(os.path.join(d, 'SConscript'))
+
+Return('objs')
diff --git a/components/libc/compilers/newlib/README.md b/components/libc/compilers/gcc/newlib/README.md
index 385f329a4f..62172e6a55 100644
--- a/components/libc/compilers/newlib/README.md
+++ b/components/libc/compilers/gcc/newlib/README.md
@@ -6,4 +6,5 @@ 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
+https://sourceware.org/newlib/libc.html#Reentrancy
+
diff --git a/components/libc/compilers/gcc/newlib/SConscript b/components/libc/compilers/gcc/newlib/SConscript
new file mode 100644
index 0000000000..ae50098dec
--- /dev/null
+++ b/components/libc/compilers/gcc/newlib/SConscript
@@ -0,0 +1,20 @@
+from building import *
+Import('rtconfig')
+
+src = []
+cwd = GetCurrentDir()
+group = []
+LIBS = ['m'] # link libm
+CPPDEFINES = ['RT_USING_NEWLIB']
+CPPPATH = [cwd]
+
+if rtconfig.PLATFORM == 'gcc':
+ if GetDepend('RT_USING_LIBC'):
+ LIBS += ['c'] # link libc
+ src += Glob('*.c')
+ else:
+ src += ['syscalls.c']
+
+ group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
+
+Return('group')
diff --git a/components/libc/compilers/newlib/libc_syms.c b/components/libc/compilers/gcc/newlib/libc_syms.c
index aaf6980d6b..aaf6980d6b 100644
--- a/components/libc/compilers/newlib/libc_syms.c
+++ b/components/libc/compilers/gcc/newlib/libc_syms.c
diff --git a/components/libc/compilers/newlib/machine/time.h b/components/libc/compilers/gcc/newlib/machine/time.h
index ff754d2473..ff754d2473 100644
--- a/components/libc/compilers/newlib/machine/time.h
+++ b/components/libc/compilers/gcc/newlib/machine/time.h
diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c
index e01dc59eb6..f95e695a85 100644
--- a/components/libc/compilers/newlib/syscalls.c
+++ b/components/libc/compilers/gcc/newlib/syscalls.c
@@ -12,22 +12,89 @@
*/
#include <reent.h>
-#include <errno.h>
-#include <stdio.h>
-#include <sys/time.h>
-
#include <rtthread.h>
-
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
+#include <stdio.h>
+#include <string.h>
+#include <stddef.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/errno.h>
+#include <sys/stat.h>
+#ifdef RT_USING_POSIX
+#include "libc.h"
#endif
-
#ifdef RT_USING_MODULE
#include <dlmodule.h>
#endif
-/* Reentrant versions of system calls. */
+#define DBG_TAG "newlib.syscalls"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
+#ifdef RT_USING_HEAP /* Memory routine */
+void *_malloc_r (struct _reent *ptr, size_t size)
+{
+ void* result;
+
+ result = (void*)rt_malloc (size);
+ if (result == RT_NULL)
+ {
+ ptr->_errno = ENOMEM;
+ }
+
+ return result;
+}
+
+void *_realloc_r (struct _reent *ptr, void *old, size_t newlen)
+{
+ void* result;
+
+ result = (void*)rt_realloc (old, newlen);
+ if (result == RT_NULL)
+ {
+ ptr->_errno = ENOMEM;
+ }
+
+ return result;
+}
+
+void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
+{
+ void* result;
+
+ result = (void*)rt_calloc (size, len);
+ if (result == RT_NULL)
+ {
+ ptr->_errno = ENOMEM;
+ }
+
+ return result;
+}
+
+void _free_r (struct _reent *ptr, void *addr)
+{
+ rt_free (addr);
+}
+
+#else
+void *
+_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
+{
+ LOG_E("Please enable RT_USING_HEAP or RT_USING_LIBC");
+ RT_ASSERT(0);
+ return RT_NULL;
+}
+#endif /*RT_USING_HEAP*/
+
+void __libc_init_array(void)
+{
+ /* we not use __libc init_aray to initialize C++ objects */
+ /* __libc_init_array is ARM code, not Thumb; it will cause a hardfault. */
+}
+
+#ifdef RT_USING_LIBC
+/* Reentrant versions of system calls. */
#ifndef _REENT_ONLY
int *__errno ()
{
@@ -42,39 +109,29 @@ int _getpid_r(struct _reent *ptr)
int _close_r(struct _reent *ptr, int fd)
{
-#ifndef RT_USING_DFS
- /* return "not supported" */
- ptr->_errno = ENOTSUP;
- return -1;
-#else
return close(fd);
-#endif
}
int _execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env)
{
- /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
int _fcntl_r(struct _reent *ptr, int fd, int cmd, int arg)
{
- /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
int _fork_r(struct _reent *ptr)
{
- /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat)
{
- /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
@@ -93,198 +150,147 @@ int _isatty_r(struct _reent *ptr, int fd)
int _kill_r(struct _reent *ptr, int pid, int sig)
{
- /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
int _link_r(struct _reent *ptr, const char *old, const char *new)
{
- /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
-_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
+int _wait_r(struct _reent *ptr, int *status)
{
-#ifndef RT_USING_DFS
- /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
-#else
+}
+
+mode_t umask(mode_t mask)
+{
+ return 022;
+}
+
+int flock(int fd, int operation)
+{
+ return 0;
+}
+
+_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
+{
+#ifdef RT_USING_POSIX
_off_t rc;
rc = lseek(fd, pos, whence);
return rc;
-#endif
+#else
+ ptr->_errno = ENOTSUP;
+ return -1;
+#endif /* RT_USING_POSIX */
}
int _mkdir_r(struct _reent *ptr, const char *name, int mode)
{
-#ifndef RT_USING_DFS
- /* return "not supported" */
- ptr->_errno = ENOTSUP;
- return -1;
-#else
+#ifdef RT_USING_POSIX
int rc;
rc = mkdir(name, mode);
return rc;
-#endif
+#else
+ ptr->_errno = ENOTSUP;
+ return -1;
+#endif /* RT_USING_POSIX */
}
int _open_r(struct _reent *ptr, const char *file, int flags, int mode)
{
-#ifndef RT_USING_DFS
- /* return "not supported" */
- ptr->_errno = ENOTSUP;
- return -1;
-#else
+#ifdef RT_USING_POSIX
int rc;
-
rc = open(file, flags, mode);
return rc;
-#endif
+#else
+ ptr->_errno = ENOTSUP;
+ return -1;
+#endif /* RT_USING_POSIX */
}
_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
{
-#ifndef RT_USING_DFS
- /* return "not supported" */
- ptr->_errno = ENOTSUP;
- return -1;
-#else
+#ifdef RT_USING_POSIX
_ssize_t rc;
-
+ if (libc_stdio_get_console() < 0 && fd == STDIN_FILENO)
+ {
+ LOG_W("Do not invoke standard input before initializing libc");
+ return 0;
+ }
rc = read(fd, buf, nbytes);
return rc;
-#endif
+#else
+ ptr->_errno = ENOTSUP;
+ return -1;
+#endif /* RT_USING_POSIX */
}
int _rename_r(struct _reent *ptr, const char *old, const char *new)
{
-#ifndef RT_USING_DFS
- /* return "not supported" */
- ptr->_errno = ENOTSUP;
- return -1;
-#else
+#ifdef RT_USING_POSIX
int rc;
rc = rename(old, new);
return rc;
-#endif
+#else
+ ptr->_errno = ENOTSUP;
+ return -1;
+#endif /* RT_USING_POSIX */
}
int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
{
-#ifndef RT_USING_DFS
- /* return "not supported" */
- ptr->_errno = ENOTSUP;
- return -1;
-#else
+#ifdef RT_USING_POSIX
int rc;
rc = stat(file, pstat);
return rc;
-#endif
-}
-
-int _unlink_r(struct _reent *ptr, const char *file)
-{
-#ifndef RT_USING_DFS
- /* return "not supported" */
+#else
ptr->_errno = ENOTSUP;
return -1;
-#else
- return unlink(file);
-#endif
+#endif /* RT_USING_POSIX */
}
-int _wait_r(struct _reent *ptr, int *status)
+int _unlink_r(struct _reent *ptr, const char *file)
{
- /* return "not supported" */
+#ifdef RT_USING_POSIX
+ return unlink(file);
+#else
ptr->_errno = ENOTSUP;
return -1;
+#endif /* RT_USING_POSIX */
}
_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
{
-#ifndef RT_USING_DFS
-#ifdef RT_USING_DEVICE
- if (fileno(stdout) == fd)
+#ifdef RT_USING_POSIX
+ _ssize_t rc;
+ if (libc_stdio_get_console() < 0 && fd == STDOUT_FILENO)
{
- rt_device_t console;
-
- console = rt_console_get_device();
- if (console) return rt_device_write(console, -1, buf, nbytes);
+ LOG_W("Do not invoke standard output before initializing libc");
+ return 0;
}
-
- return 0;
-#else
- /* return "not supported" */
- ptr->_errno = ENOTSUP;
- return -1;
-#endif /*RT_USING_DEVICE*/
-#else
- _ssize_t rc;
-
rc = write(fd, buf, nbytes);
return rc;
-#endif
-}
-
-#ifdef RT_USING_HEAP /* Memory routine */
-void *_malloc_r (struct _reent *ptr, size_t size)
-{
- void* result;
-
- result = (void*)rt_malloc (size);
- if (result == RT_NULL)
+#elif defined(RT_USING_CONSOLE)
+ if (STDOUT_FILENO == fd)
{
- ptr->_errno = ENOMEM;
- }
-
- return result;
-}
-
-void *_realloc_r (struct _reent *ptr, void *old, size_t newlen)
-{
- void* result;
-
- result = (void*)rt_realloc (old, newlen);
- if (result == RT_NULL)
- {
- ptr->_errno = ENOMEM;
- }
-
- return result;
-}
-
-void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
-{
- void* result;
+ rt_device_t console;
- result = (void*)rt_calloc (size, len);
- if (result == RT_NULL)
- {
- ptr->_errno = ENOMEM;
+ console = rt_console_get_device();
+ if (console)
+ return rt_device_write(console, -1, buf, nbytes);
}
-
- return result;
-}
-
-void _free_r (struct _reent *ptr, void *addr)
-{
- rt_free (addr);
-}
-
-#else
-void *
-_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
-{
- return RT_NULL;
+#endif /* RT_USING_POSIX */
+ ptr->_errno = ENOTSUP;
+ return -1;
}
-#endif /*RT_USING_HEAP*/
/* for exit() and abort() */
__attribute__ ((noreturn)) void _exit (int status)
@@ -294,29 +300,10 @@ __attribute__ ((noreturn)) void _exit (int status)
while(1);
}
-void _system(const char *s)
-{
- extern int __rt_libc_system(const char *string);
- __rt_libc_system(s);
-}
-
-void __libc_init_array(void)
-{
- /* we not use __libc init_aray to initialize C++ objects */
-}
-
-mode_t umask(mode_t mask)
-{
- return 022;
-}
-
-int flock(int fd, int operation)
-{
- return 0;
-}
-
/*
These functions are implemented and replaced by the 'common/time.c' file
int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp);
_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms);
*/
+
+#endif /* RT_USING_LIBC */
diff --git a/components/libc/compilers/gcc/partial/SConscript b/components/libc/compilers/gcc/partial/SConscript
new file mode 100644
index 0000000000..4c815c49b8
--- /dev/null
+++ b/components/libc/compilers/gcc/partial/SConscript
@@ -0,0 +1,15 @@
+# RT-Thread building script for bridge
+
+import os
+from building import *
+
+cwd = GetCurrentDir()
+objs = []
+list = os.listdir(cwd)
+
+for d in list:
+ path = os.path.join(cwd, d)
+ if os.path.isfile(os.path.join(path, 'SConscript')):
+ objs = objs + SConscript(os.path.join(d, 'SConscript'))
+
+Return('objs')
diff --git a/components/libc/compilers/gcc/partial/mips/SConscript b/components/libc/compilers/gcc/partial/mips/SConscript
new file mode 100644
index 0000000000..7651233d46
--- /dev/null
+++ b/components/libc/compilers/gcc/partial/mips/SConscript
@@ -0,0 +1,20 @@
+from shutil import copy
+from building import *
+
+Import('rtconfig')
+
+src = []
+cwd = GetCurrentDir()
+CPPPATH = [cwd]
+group = []
+
+if rtconfig.PLATFORM == 'gcc' and ('mips' in rtconfig.PREFIX): # identify mips gcc tool chain
+ try:
+ # There is no 'sys/select.h' in tthe mips gcc toolchain; it will be copied from 'nogcc/sys/select.h'
+ copy("../../../common/nogcc/sys/select.h", "./sys/select.h")
+ except:
+ pass
+
+ group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/components/libc/compilers/gcc/partial/mips/readme.md b/components/libc/compilers/gcc/partial/mips/readme.md
new file mode 100644
index 0000000000..a3eeb06c5d
--- /dev/null
+++ b/components/libc/compilers/gcc/partial/mips/readme.md
@@ -0,0 +1,4 @@
+These files don't exist in the mips gcc toolchain. They will be generated by scons automatically , and **DO NOT** change them:
+
+- sys/select.h
+
diff --git a/components/libc/compilers/gcc/partial/mips/sys/select.h b/components/libc/compilers/gcc/partial/mips/sys/select.h
new file mode 100644
index 0000000000..575ad3a1b5
--- /dev/null
+++ b/components/libc/compilers/gcc/partial/mips/sys/select.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-07-21 Meco Man The first version
+ */
+
+#ifndef __SYS_SELECT_H__
+#define __SYS_SELECT_H__
+
+#include <rtconfig.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#ifndef FD_SETSIZE
+#define FD_SETSIZE 32
+#endif
+
+#ifdef SAL_USING_POSIX
+#ifdef FD_SETSIZE
+#undef FD_SETSIZE
+#endif
+#define FD_SETSIZE DFS_FD_MAX
+#endif /* SAL_USING_POSIX */
+
+#define NBBY 8 /* number of bits in a byte */
+
+typedef long fd_mask;
+
+#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
+#ifndef howmany
+#define howmany(x,y) (((x)+((y)-1))/(y))
+#endif
+
+#ifndef _SYS_TYPES_FD_SET /* MIPS */
+typedef struct _types_fd_set {
+ fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
+} _types_fd_set;
+#define fd_set _types_fd_set
+
+#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
+#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
+#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
+#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
+#endif /* _SYS_TYPES_FD_SET */
+
+int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
+
+#endif /* __SYS_SELECT_H__ */
diff --git a/components/libc/compilers/gcc/partial/readme.md b/components/libc/compilers/gcc/partial/readme.md
new file mode 100644
index 0000000000..959fc29f35
--- /dev/null
+++ b/components/libc/compilers/gcc/partial/readme.md
@@ -0,0 +1,2 @@
+This folder is for some particular targets.
+
diff --git a/components/libc/compilers/newlib/SConscript b/components/libc/compilers/newlib/SConscript
deleted file mode 100644
index 542cdecd40..0000000000
--- a/components/libc/compilers/newlib/SConscript
+++ /dev/null
@@ -1,29 +0,0 @@
-from building import *
-Import('rtconfig')
-
-src = []
-cwd = GetCurrentDir()
-group = []
-LIBS = []
-CPPDEFINES = []
-CPPPATH = [cwd]
-
-if rtconfig.PLATFORM == 'gcc':
- if GetDepend('RT_USING_LIBC'):
- CPPDEFINES += ['RT_USING_NEWLIB']
- # link with libc and libm:
- # libm is a frequently used lib. Newlib is compiled with -ffunction-sections in
- # recent GCC tool chains. The linker would just link in the functions that have
- # been referenced. So setting this won't result in bigger text size.
- LIBS += ['c', 'm']
-
- src += Glob('*.c')
- SrcRemove(src, ['minilib.c'])
- if GetDepend('RT_USING_MODULE') == False:
- SrcRemove(src, ['libc_syms.c'])
- else:
- src += ['minilib.c']
-
- group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
-
-Return('group')
diff --git a/components/libc/compilers/newlib/libc.c b/components/libc/compilers/newlib/libc.c
deleted file mode 100644
index 9834a9a015..0000000000
--- a/components/libc/compilers/newlib/libc.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard the first version
- */
-#include <rtthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <sys/time.h>
-
-#include "libc.h"
-
-#ifdef RT_USING_PTHREADS
-#include <pthread.h>
-#endif
-
-int _EXFUN(putenv,(char *__string));
-
-int libc_system_init(void)
-{
-#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS) & defined(RT_USING_CONSOLE)
- rt_device_t dev_console;
-
- dev_console = rt_console_get_device();
- if (dev_console)
- {
- #if defined(RT_USING_POSIX)
- libc_stdio_set_console(dev_console->parent.name, O_RDWR);
- #else
- libc_stdio_set_console(dev_console->parent.name, O_WRONLY);
- #endif
- }
-
- /* set PATH and HOME */
- putenv("PATH=/bin");
- putenv("HOME=/home");
-#endif
-
-#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT
- pthread_system_init();
-#endif
-
- return 0;
-}
-INIT_COMPONENT_EXPORT(libc_system_init);
diff --git a/components/libc/compilers/newlib/libc.h b/components/libc/compilers/newlib/libc.h
deleted file mode 100644
index c1f76d7605..0000000000
--- a/components/libc/compilers/newlib/libc.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard the first version
- */
-#ifndef __RTT_LIBC_H__
-#define __RTT_LIBC_H__
-
-#ifndef _EXFUN
-#define _EXFUN(name, proto) name proto
-#endif
-
-#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);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/components/libc/compilers/newlib/minilib.c b/components/libc/compilers/newlib/minilib.c
deleted file mode 100644
index 612554ca66..0000000000
--- a/components/libc/compilers/newlib/minilib.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2021-02-23 Meco Man first version
- */
-
-#include <reent.h>
-#include <rtthread.h>
-
-#ifdef RT_USING_HEAP /* Memory routine */
-#include <sys/errno.h>
-
-void * _malloc_r (struct _reent *ptr, size_t size)
-{
- void* result;
-
- result = (void*)rt_malloc (size);
- if (result == RT_NULL)
- {
- ptr->_errno = ENOMEM;
- }
-
- return result;
-}
-
-void * _realloc_r (struct _reent *ptr, void *old, size_t newlen)
-{
- void* result;
-
- result = (void*)rt_realloc (old, newlen);
- if (result == RT_NULL)
- {
- ptr->_errno = ENOMEM;
- }
-
- return result;
-}
-
-void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
-{
- void* result;
-
- result = (void*)rt_calloc (size, len);
- if (result == RT_NULL)
- {
- ptr->_errno = ENOMEM;
- }
-
- return result;
-}
-
-void _free_r (struct _reent *ptr, void *addr)
-{
- rt_free (addr);
-}
-
-#else
-void * _sbrk_r(struct _reent *ptr, ptrdiff_t incr)
-{
- return RT_NULL;
-}
-#endif /*RT_USING_HEAP*/
diff --git a/components/libc/compilers/newlib/stdio.c b/components/libc/compilers/newlib/stdio.c
deleted file mode 100644
index ce5bdb75cb..0000000000
--- a/components/libc/compilers/newlib/stdio.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/10/15 bernard the first version
- */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <rtthread.h>
-#include "libc.h"
-
-#define STDIO_DEVICE_NAME_MAX 32
-
-int _EXFUN(fileno, (FILE *));
-
-static FILE* std_console = NULL;
-
-int libc_stdio_set_console(const char* device_name, int mode)
-{
- FILE *fp;
- char name[STDIO_DEVICE_NAME_MAX];
- char *file_mode;
-
- snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
- name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
-
- if (mode == O_RDWR) file_mode = "r+";
- else if (mode == O_WRONLY) file_mode = "wb";
- else file_mode = "rb";
-
- fp = fopen(name, file_mode);
- if (fp)
- {
- setvbuf(fp, NULL, _IONBF, 0);
-
- if (std_console)
- {
- fclose(std_console);
- std_console = NULL;
- }
- std_console = fp;
-
- if (mode == O_RDWR)
- {
- _GLOBAL_REENT->_stdin = std_console;
- }
- else
- {
- _GLOBAL_REENT->_stdin = NULL;
- }
-
- if (mode == O_RDONLY)
- {
- _GLOBAL_REENT->_stdout = NULL;
- _GLOBAL_REENT->_stderr = NULL;
- }
- else
- {
- _GLOBAL_REENT->_stdout = std_console;
- _GLOBAL_REENT->_stderr = std_console;
- }
-
- _GLOBAL_REENT->__sdidinit = 1;
- }
-
- if (std_console) return fileno(std_console);
-
- return -1;
-}
-
-int libc_stdio_get_console(void) {
- if (std_console)
- return fileno(std_console);
- else
- return -1;
-}