summaryrefslogtreecommitdiff
path: root/components/libc/compilers/common
diff options
context:
space:
mode:
authorSherman <[email protected]>2021-11-04 13:59:22 +0800
committerSherman <[email protected]>2021-11-04 13:59:22 +0800
commit6e004d4b12993a1206c6ff0168bd602bd71e9e9b (patch)
tree4ad5048005defe9d48c3969e875066a3ec8a9ec0 /components/libc/compilers/common
parent85934d95e6ac046ed81fc763769c60c48a42c4cb (diff)
parent3f3418d173e5a5d3a5b9cea27da1987491bf9e6a (diff)
Merge branch 'master' of github.com:RT-Thread/rt-thread
Diffstat (limited to 'components/libc/compilers/common')
-rw-r--r--components/libc/compilers/common/SConscript19
-rw-r--r--components/libc/compilers/common/delay.c41
-rw-r--r--components/libc/compilers/common/nogcc/sys/select.h12
-rw-r--r--components/libc/compilers/common/readme.md11
-rw-r--r--components/libc/compilers/common/sys/ioctl.h6
-rw-r--r--components/libc/compilers/common/time.c2
-rw-r--r--components/libc/compilers/common/unistd.c119
7 files changed, 23 insertions, 187 deletions
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/nogcc/sys/select.h b/components/libc/compilers/common/nogcc/sys/select.h
index 575ad3a1b5..02fb77dd89 100644
--- a/components/libc/compilers/common/nogcc/sys/select.h
+++ b/components/libc/compilers/common/nogcc/sys/select.h
@@ -15,6 +15,10 @@
#include <sys/types.h>
#include <sys/time.h>
+#ifdef _WIN32
+#include <winsock.h>
+#endif
+
#ifndef FD_SETSIZE
#define FD_SETSIZE 32
#endif
@@ -26,16 +30,17 @@
#define FD_SETSIZE DFS_FD_MAX
#endif /* SAL_USING_POSIX */
-#define NBBY 8 /* number of bits in a byte */
-
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
-#ifndef _SYS_TYPES_FD_SET /* MIPS */
typedef struct _types_fd_set {
fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
} _types_fd_set;
@@ -48,5 +53,6 @@ typedef struct _types_fd_set {
#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/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/sys/ioctl.h b/components/libc/compilers/common/sys/ioctl.h
index b926a71875..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
diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c
index 24289088fb..5bfff15914 100644
--- a/components/libc/compilers/common/time.c
+++ b/components/libc/compilers/common/time.c
@@ -240,7 +240,7 @@ RTM_EXPORT(mktime);
char* asctime_r(const struct tm *t, char *buf)
{
/* Checking input validity */
- if (rt_strlen(days) <= (t->tm_wday << 2) || rt_strlen(months) <= (t->tm_mon << 2))
+ 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;
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);