summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--components/libc/compilers/common/SConscript2
-rw-r--r--components/libc/compilers/common/cctype.c25
-rw-r--r--components/libc/compilers/common/cstdio.c85
-rw-r--r--components/libc/compilers/common/cstdlib.c144
-rw-r--r--components/libc/compilers/common/cstring.c223
-rw-r--r--components/libc/compilers/common/ctime.c (renamed from components/libc/compilers/common/time.c)49
-rw-r--r--components/libc/compilers/common/cwchar.c140
-rw-r--r--components/libc/compilers/common/extension/fcntl/msvc/fcntl.h8
-rw-r--r--components/libc/compilers/common/extension/fcntl/octal/fcntl.h2
-rw-r--r--components/libc/compilers/common/extension/sys/errno.h2
-rw-r--r--components/libc/compilers/common/extension/sys/stat.h2
-rw-r--r--components/libc/compilers/common/extension/sys/types.h2
-rw-r--r--components/libc/compilers/common/include/compiler_private.h (renamed from components/libc/compilers/common/compiler_private.h)2
-rw-r--r--components/libc/compilers/common/include/dirent.h (renamed from components/libc/compilers/common/dirent.h)2
-rw-r--r--components/libc/compilers/common/include/posix/ctype.h31
-rw-r--r--components/libc/compilers/common/include/posix/stdio.h28
-rw-r--r--components/libc/compilers/common/include/posix/stdlib.h32
-rw-r--r--components/libc/compilers/common/include/posix/string.h43
-rw-r--r--components/libc/compilers/common/include/posix/wchar.h27
-rw-r--r--components/libc/compilers/common/include/sys/ioctl.h (renamed from components/libc/compilers/common/sys/ioctl.h)2
-rw-r--r--components/libc/compilers/common/include/sys/select.h (renamed from components/libc/compilers/common/sys/select.h)2
-rw-r--r--components/libc/compilers/common/include/sys/signal.h (renamed from components/libc/compilers/common/sys/signal.h)2
-rw-r--r--components/libc/compilers/common/include/sys/statfs.h (renamed from components/libc/compilers/common/sys/statfs.h)2
-rw-r--r--components/libc/compilers/common/include/sys/time.h (renamed from components/libc/compilers/common/sys/time.h)0
-rw-r--r--components/libc/compilers/common/include/sys/unistd.h (renamed from components/libc/compilers/common/sys/unistd.h)2
-rw-r--r--components/libc/compilers/common/include/sys/vfs.h (renamed from components/libc/compilers/common/sys/vfs.h)2
-rw-r--r--components/libc/compilers/common/include/unistd.h (renamed from components/libc/compilers/common/unistd.h)2
-rw-r--r--components/libc/compilers/common/stdlib.c46
28 files changed, 836 insertions, 73 deletions
diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript
index 1a341f5ad1..fda7c6bf61 100644
--- a/components/libc/compilers/common/SConscript
+++ b/components/libc/compilers/common/SConscript
@@ -4,7 +4,7 @@ Import('rtconfig')
src = []
cwd = GetCurrentDir()
group = []
-CPPPATH = [cwd]
+CPPPATH = [cwd + '/include']
CPPDEFINES = []
if rtconfig.PLATFORM in ['armcc', 'armclang']:
diff --git a/components/libc/compilers/common/cctype.c b/components/libc/compilers/common/cctype.c
new file mode 100644
index 0000000000..ddcff1b39d
--- /dev/null
+++ b/components/libc/compilers/common/cctype.c
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2006-2022, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2022-06-07 Meco Man The first version.
+ */
+
+#include "posix/ctype.h"
+
+#ifndef isascii /* some toolchain use macro to define it */
+int isascii(int c)
+{
+ return c >= 0x00 && c <= 0x7f;
+}
+#endif
+
+#ifndef toascii
+int toascii(int c)
+{
+ return (c)&0177;
+}
+#endif
diff --git a/components/libc/compilers/common/cstdio.c b/components/libc/compilers/common/cstdio.c
new file mode 100644
index 0000000000..3dffe55aa7
--- /dev/null
+++ b/components/libc/compilers/common/cstdio.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2006-2022, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2014-05-22 ivanrad implement getline
+ */
+
+#include "posix/stdio.h"
+#include <stdlib.h>
+#include <limits.h>
+#include <sys/errno.h>
+
+ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream)
+{
+ char *cur_pos, *new_lineptr;
+ size_t new_lineptr_len;
+ int c;
+
+ if (lineptr == NULL || n == NULL || stream == NULL)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (*lineptr == NULL)
+ {
+ *n = 128; /* init len */
+ if ((*lineptr = (char *)malloc(*n)) == NULL)
+ {
+ errno = ENOMEM;
+ return -1;
+ }
+ }
+
+ cur_pos = *lineptr;
+ for (;;)
+ {
+ c = getc(stream);
+
+ if (ferror(stream) || (c == EOF && cur_pos == *lineptr))
+ return -1;
+
+ if (c == EOF)
+ break;
+
+ if ((*lineptr + *n - cur_pos) < 2)
+ {
+ if (LONG_MAX / 2 < *n)
+ {
+#ifdef EOVERFLOW
+ errno = EOVERFLOW;
+#else
+ errno = ERANGE; /* no EOVERFLOW defined */
+#endif
+ return -1;
+ }
+ new_lineptr_len = *n * 2;
+
+ if ((new_lineptr = (char *)realloc(*lineptr, new_lineptr_len)) == NULL)
+ {
+ errno = ENOMEM;
+ return -1;
+ }
+ cur_pos = new_lineptr + (cur_pos - *lineptr);
+ *lineptr = new_lineptr;
+ *n = new_lineptr_len;
+ }
+
+ *cur_pos++ = (char)c;
+
+ if (c == delim)
+ break;
+ }
+
+ *cur_pos = '\0';
+ return (ssize_t)(cur_pos - *lineptr);
+}
+
+ssize_t getline(char **lineptr, size_t *n, FILE *stream)
+{
+ return getdelim(lineptr, n, '\n', stream);
+}
diff --git a/components/libc/compilers/common/cstdlib.c b/components/libc/compilers/common/cstdlib.c
new file mode 100644
index 0000000000..9d1667b5d3
--- /dev/null
+++ b/components/libc/compilers/common/cstdlib.c
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2006-2022, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-02-15 Meco Man first version
+ */
+
+#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)
+ {
+#ifdef RT_USING_PTHREADS
+ extern void pthread_exit(void *value);
+ pthread_exit((void *)status);
+#else
+ LOG_E("thread:%s exit:%d!", self->name, status);
+ rt_thread_control(self, RT_THREAD_CTRL_CLOSE, RT_NULL);
+#endif
+ }
+}
+
+#ifdef RT_USING_MSH
+int system(const char *command)
+{
+ extern int msh_exec(char *cmd, rt_size_t length);
+
+ if (command)
+ {
+ msh_exec((char *)command, rt_strlen(command));
+ }
+
+ return 0;
+}
+RTM_EXPORT(system);
+#endif /* RT_USING_MSH */
+
+char *ltoa(long value, char *string, int radix)
+{
+ char tmp[33];
+ char *tp = tmp;
+ long i;
+ unsigned long v;
+ int sign;
+ char *sp;
+
+ if (string == NULL)
+ {
+ return 0 ;
+ }
+
+ if (radix > 36 || radix <= 1)
+ {
+ return 0 ;
+ }
+
+ sign = (radix == 10 && value < 0);
+ if (sign)
+ {
+ v = -value;
+ }
+ else
+ {
+ v = (unsigned long)value;
+ }
+
+ while (v || tp == tmp)
+ {
+ i = v % radix;
+ v = v / radix;
+ if (i < 10)
+ *tp++ = i+'0';
+ else
+ *tp++ = i + 'a' - 10;
+ }
+
+ sp = string;
+
+ if (sign)
+ *sp++ = '-';
+ while (tp > tmp)
+ *sp++ = *--tp;
+ *sp = 0;
+
+ return string;
+}
+
+char *itoa(int value, char *string, int radix)
+{
+ return ltoa(value, string, radix) ;
+}
+
+
+char *ultoa(unsigned long value, char *string, int radix)
+{
+ char tmp[33];
+ char *tp = tmp;
+ long i;
+ unsigned long v = value;
+ char *sp;
+
+ if (string == NULL)
+ {
+ return 0;
+ }
+
+ if (radix > 36 || radix <= 1)
+ {
+ return 0;
+ }
+
+ while (v || tp == tmp)
+ {
+ i = v % radix;
+ v = v / radix;
+ if (i < 10)
+ *tp++ = i+'0';
+ else
+ *tp++ = i + 'a' - 10;
+ }
+
+ sp = string;
+
+ while (tp > tmp)
+ *sp++ = *--tp;
+ *sp = 0;
+
+ return string;
+}
+
+char *utoa(unsigned value, char *string, int radix)
+{
+ return ultoa(value, string, radix) ;
+}
diff --git a/components/libc/compilers/common/cstring.c b/components/libc/compilers/common/cstring.c
new file mode 100644
index 0000000000..dec1213d79
--- /dev/null
+++ b/components/libc/compilers/common/cstring.c
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2006-2022, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2022-01-12 Meco Man The first version.
+ */
+
+#include "posix/string.h"
+#include <ctype.h>
+#include <rtthread.h>
+#include <stdlib.h>
+
+/**
+ * @brief erases the data in the n bytes of the memory starting at the
+ * location pointed to by s, by writing zeros (bytes containing '\0') to that area.
+ *
+ * @note The bzero() function is deprecated (marked as LEGACY in POSIX. 1-2001).
+ */
+void bzero(void* s, size_t n)
+{
+ rt_memset(s, 0, n);
+}
+
+void bcopy(const void* src, void* dest, size_t n)
+{
+ rt_memcpy(dest, src, n);
+}
+
+int bcmp(const void* s1, const void* s2, size_t n)
+{
+ return rt_memcmp(s1, s2, n);
+}
+
+void explicit_bzero(void* s, size_t n)
+{
+ volatile char* vs = (volatile char*)s;
+ while (n)
+ {
+ *vs++ = 0;
+ n--;
+ }
+}
+
+char* index(const char* s, int c)
+{
+ return strchr(s, c);
+}
+
+char* rindex(const char* s, int c)
+{
+ return strrchr(s, c);
+}
+
+int ffs(int i)
+{
+ int bit;
+
+ if (0 == i)
+ return 0;
+
+ for (bit = 1; !(i & 1); ++bit)
+ i >>= 1;
+ return bit;
+}
+
+int ffsl(long i)
+{
+ int bit;
+
+ if (0 == i)
+ return 0;
+
+ for (bit = 1; !(i & 1); ++bit)
+ i >>= 1;
+ return bit;
+}
+
+int ffsll(long long i)
+{
+ int bit;
+
+ if (0 == i)
+ return 0;
+
+ for (bit = 1; !(i & 1); ++bit)
+ i >>= 1;
+ return bit;
+}
+
+/**
+ * @brief The memchr() function scans the initial n bytes of the memory area pointed to
+ * by s for the first instance of c. Both c and the bytes of the memory area
+ * pointed to by s are interpreted as unsigned char.
+ *
+ * @note This function is GNU extension, available since glibc 2.1.91.
+ */
+void* memrchr(const void* ptr, int ch, size_t pos)
+{
+ char* end = (char*)ptr + pos - 1;
+ while (end != ptr)
+ {
+ if (*end == ch)
+ return end;
+ end--;
+ }
+ return (*end == ch) ? (end) : (NULL);
+}
+
+size_t strnlen(const char *s, size_t maxlen)
+{
+ const char *sc;
+ for (sc = s; maxlen != 0 && *sc != '\0'; maxlen--, ++sc);
+ return sc - s;
+}
+
+char* strchrnul(const char* s, int c)
+{
+ while (*s != '\0' && *s != c)
+ s++;
+ return (char*)s;
+}
+
+int strcasecmp(const char* s1, const char* s2)
+{
+ const unsigned char* u1 = (const unsigned char*)s1;
+ const unsigned char* u2 = (const unsigned char*)s2;
+ int result;
+
+ while ((result = tolower(*u1) - tolower(*u2)) == 0 && *u1 != 0)
+ {
+ u1++;
+ u2++;
+ }
+
+ return result;
+}
+
+int strncasecmp(const char* s1, const char* s2, size_t n)
+{
+ const unsigned char* u1 = (const unsigned char*)s1;
+ const unsigned char* u2 = (const unsigned char*)s2;
+ int result;
+
+ for (; n != 0; n--)
+ {
+ result = tolower(*u1) - tolower(*u2);
+ if (result)
+ return result;
+ if (*u1 == 0)
+ return 0;
+ u1++;
+ u2++;
+ }
+ return 0;
+}
+
+char *strdup(const char *s)
+{
+ char *news = (char *)malloc(strlen(s) + 1);
+
+ if (news)
+ {
+ strcpy(news, s);
+ }
+
+ return news;
+}
+
+char *strndup(const char *s, size_t size)
+{
+ size_t nsize = strnlen(s, size);
+ char *news = (char *)malloc(nsize + 1);
+ if (news)
+ {
+ rt_memcpy(news, s, nsize);
+ news[nsize] = '\0';
+ }
+
+ return news;
+}
+
+char *strtok_r(char *str, const char *delim, char **saveptr)
+{
+ char *pbegin;
+ char *pend = NULL;
+
+ if (str)
+ {
+ pbegin = str;
+ }
+ else if (saveptr && *saveptr)
+ {
+ pbegin = *saveptr;
+ }
+ else
+ {
+ return NULL;
+ }
+
+ for (;*pbegin && strchr(delim, *pbegin) != NULL; pbegin++);
+
+ if (!*pbegin)
+ {
+ return NULL;
+ }
+
+ for (pend = pbegin + 1; *pend && strchr(delim, *pend) == NULL; pend++);
+
+ if (*pend)
+ {
+ *pend++ = '\0';
+ }
+
+ if (saveptr)
+ {
+ *saveptr = pend;
+ }
+
+ return pbegin;
+}
diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/ctime.c
index 96591113b8..6cef1e222d 100644
--- a/components/libc/compilers/common/time.c
+++ b/components/libc/compilers/common/ctime.c
@@ -173,6 +173,15 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r)
{
time_t i;
time_t work = *timep % (SPD);
+
+ if(timep == RT_NULL || r == RT_NULL)
+ {
+ rt_set_errno(EFAULT);
+ return RT_NULL;
+ }
+
+ rt_memset(r, RT_NULL, sizeof(struct tm));
+
r->tm_sec = work % 60;
work /= 60;
r->tm_min = work % 60;
@@ -198,8 +207,8 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r)
work -= 1;
}
- for (i = 11; i && (__spm[i] > work); --i)
- ;
+ for (i = 11; i && (__spm[i] > work); --i);
+
r->tm_mon = i;
r->tm_mday += work - __spm[i];
@@ -243,6 +252,14 @@ RTM_EXPORT(mktime);
char* asctime_r(const struct tm *t, char *buf)
{
+ if(t == RT_NULL || buf == RT_NULL)
+ {
+ rt_set_errno(EFAULT);
+ return RT_NULL;
+ }
+
+ rt_memset(buf, RT_NULL, 26);
+
/* Checking input validity */
if ((int)rt_strlen(days) <= (t->tm_wday << 2) || (int)rt_strlen(months) <= (t->tm_mon << 2))
{
@@ -354,7 +371,7 @@ int stime(const time_t *t)
{
struct timeval tv;
- if (!t)
+ if (t == RT_NULL)
{
rt_set_errno(EFAULT);
return -1;
@@ -377,8 +394,15 @@ time_t timegm(struct tm * const t)
{
time_t day;
time_t i;
- time_t years = (time_t)t->tm_year - 70;
+ time_t years;
+
+ if(t == RT_NULL)
+ {
+ rt_set_errno(EFAULT);
+ return (time_t)-1;
+ }
+ years = (time_t)t->tm_year - 70;
if (t->tm_sec > 60) /* seconds after the minute - [0, 60] including leap second */
{
t->tm_min += t->tm_sec / 60;
@@ -415,7 +439,10 @@ time_t timegm(struct tm * const t)
}
if (t->tm_year < 70)
- return (time_t) - 1;
+ {
+ rt_set_errno(EINVAL);
+ return (time_t) -1;
+ }
/* Days since 1970 is 365 * number of years + number of leap years since 1970 */
day = years * 365 + (years + 1) / 4;
@@ -467,7 +494,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
}
else
{
- rt_set_errno(EFAULT);
+ rt_set_errno(EINVAL);
return -1;
}
}
@@ -549,7 +576,7 @@ int clock_getres(clockid_t clockid, struct timespec *res)
if (res == RT_NULL)
{
- rt_set_errno(EINVAL);
+ rt_set_errno(EFAULT);
return -1;
}
@@ -568,6 +595,8 @@ int clock_getres(clockid_t clockid, struct timespec *res)
#endif
default:
+ res->tv_sec = 0;
+ res->tv_nsec = 0;
ret = -1;
rt_set_errno(EINVAL);
break;
@@ -588,7 +617,7 @@ int clock_gettime(clockid_t clockid, struct timespec *tp)
if (tp == RT_NULL)
{
- rt_set_errno(EINVAL);
+ rt_set_errno(EFAULT);
return -1;
}
@@ -622,6 +651,8 @@ int clock_gettime(clockid_t clockid, struct timespec *tp)
break;
#endif
default:
+ tp->tv_sec = 0;
+ tp->tv_nsec = 0;
rt_set_errno(EINVAL);
ret = -1;
}
@@ -655,7 +686,7 @@ int clock_settime(clockid_t clockid, const struct timespec *tp)
if ((clockid != CLOCK_REALTIME) || (tp == RT_NULL))
{
- rt_set_errno(EINVAL);
+ rt_set_errno(EFAULT);
return -1;
}
diff --git a/components/libc/compilers/common/cwchar.c b/components/libc/compilers/common/cwchar.c
new file mode 100644
index 0000000000..c808083331
--- /dev/null
+++ b/components/libc/compilers/common/cwchar.c
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2006-2022, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2014-01-01 mattn implement wcwidth
+ */
+
+#include "posix/wchar.h"
+#include <string.h>
+
+struct interval
+{
+ long first;
+ long last;
+};
+
+static int bisearch(wchar_t ucs, const struct interval *table, int max)
+{
+ int min = 0;
+ int mid;
+
+ if (ucs < table[0].first || ucs > table[max].last)
+ {
+ return 0;
+ }
+
+ while (max >= min)
+ {
+ mid = (min + max) / 2;
+ if (ucs > table[mid].last)
+ {
+ min = mid + 1;
+ }
+ else if (ucs < table[mid].first)
+ {
+ max = mid - 1;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+int wcwidth(wchar_t ucs)
+{
+ /* sorted list of non-overlapping intervals of non-spacing characters */
+ static const struct interval combining[] = {
+ { 0x0300, 0x034E }, { 0x0360, 0x0362 }, { 0x0483, 0x0486 },
+ { 0x0488, 0x0489 }, { 0x0591, 0x05A1 }, { 0x05A3, 0x05B9 },
+ { 0x05BB, 0x05BD }, { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 },
+ { 0x05C4, 0x05C4 }, { 0x064B, 0x0655 }, { 0x0670, 0x0670 },
+ { 0x06D6, 0x06E4 }, { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED },
+ { 0x070F, 0x070F }, { 0x0711, 0x0711 }, { 0x0730, 0x074A },
+ { 0x07A6, 0x07B0 }, { 0x0901, 0x0902 }, { 0x093C, 0x093C },
+ { 0x0941, 0x0948 }, { 0x094D, 0x094D }, { 0x0951, 0x0954 },
+ { 0x0962, 0x0963 }, { 0x0981, 0x0981 }, { 0x09BC, 0x09BC },
+ { 0x09C1, 0x09C4 }, { 0x09CD, 0x09CD }, { 0x09E2, 0x09E3 },
+ { 0x0A02, 0x0A02 }, { 0x0A3C, 0x0A3C }, { 0x0A41, 0x0A42 },
+ { 0x0A47, 0x0A48 }, { 0x0A4B, 0x0A4D }, { 0x0A70, 0x0A71 },
+ { 0x0A81, 0x0A82 }, { 0x0ABC, 0x0ABC }, { 0x0AC1, 0x0AC5 },
+ { 0x0AC7, 0x0AC8 }, { 0x0ACD, 0x0ACD }, { 0x0B01, 0x0B01 },
+ { 0x0B3C, 0x0B3C }, { 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 },
+ { 0x0B4D, 0x0B4D }, { 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 },
+ { 0x0BC0, 0x0BC0 }, { 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 },
+ { 0x0C46, 0x0C48 }, { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 },
+ { 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 }, { 0x0CCC, 0x0CCD },
+ { 0x0D41, 0x0D43 }, { 0x0D4D, 0x0D4D }, { 0x0DCA, 0x0DCA },
+ { 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 }, { 0x0E31, 0x0E31 },
+ { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E }, { 0x0EB1, 0x0EB1 },
+ { 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC }, { 0x0EC8, 0x0ECD },
+ { 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 }, { 0x0F37, 0x0F37 },
+ { 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E }, { 0x0F80, 0x0F84 },
+ { 0x0F86, 0x0F87 }, { 0x0F90, 0x0F97 }, { 0x0F99, 0x0FBC },
+ { 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 }, { 0x1032, 0x1032 },
+ { 0x1036, 0x1037 }, { 0x1039, 0x1039 }, { 0x1058, 0x1059 },
+ { 0x1160, 0x11FF }, { 0x17B7, 0x17BD }, { 0x17C6, 0x17C6 },
+ { 0x17C9, 0x17D3 }, { 0x180B, 0x180E }, { 0x18A9, 0x18A9 },
+ { 0x200B, 0x200F }, { 0x202A, 0x202E }, { 0x206A, 0x206F },
+ { 0x20D0, 0x20E3 }, { 0x302A, 0x302F }, { 0x3099, 0x309A },
+ { 0xFB1E, 0xFB1E }, { 0xFE20, 0xFE23 }, { 0xFEFF, 0xFEFF },
+ { 0xFFF9, 0xFFFB }
+ };
+
+ /* test for 8-bit control characters */
+ if (ucs == 0)
+ {
+ return 0;
+ }
+ if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0))
+ {
+ return -1;
+ }
+
+ /* binary search in table of non-spacing characters */
+ if (bisearch(ucs, combining, sizeof(combining) / sizeof(struct interval) - 1))
+ {
+ return 0;
+ }
+
+ return 1 +
+ (ucs >= 0x1100 &&
+ (ucs <= 0x115f || /* Hangul Jamo init. consonants */
+ (ucs >= 0x2e80 && ucs <= 0xa4cf && (ucs & ~0x0011) != 0x300a &&
+ ucs != 0x303f) || /* CJK ... Yi */
+ (ucs >= 0xac00 && ucs <= 0xd7a3) || /* Hangul Syllables */
+ (ucs >= 0xf900 && ucs <= 0xfaff) || /* CJK Compatibility Ideographs */
+ (ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */
+ (ucs >= 0xff00 && ucs <= 0xff5f) || /* Fullwidth Forms */
+ (ucs >= 0xffe0 && ucs <= 0xffe6) // ||
+ //#ifndef _WIN32
+ // (ucs >= 0x20000 && ucs <= 0x2ffff)
+ //#else
+ // 0
+ //#endif
+ ));
+}
+
+int wcswidth(const wchar_t *pwcs, size_t n)
+{
+ int w, width = 0;
+
+ for (;*pwcs && n-- > 0; pwcs++)
+ {
+ if ((w = wcwidth(*pwcs)) < 0)
+ {
+ return -1;
+ }
+ else
+ {
+ width += w;
+ }
+ }
+ return width;
+}
diff --git a/components/libc/compilers/common/extension/fcntl/msvc/fcntl.h b/components/libc/compilers/common/extension/fcntl/msvc/fcntl.h
index 26a380119d..7c0b55bb25 100644
--- a/components/libc/compilers/common/extension/fcntl/msvc/fcntl.h
+++ b/components/libc/compilers/common/extension/fcntl/msvc/fcntl.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -39,9 +39,9 @@ extern "C" {
#define O_RANDOM 0x0010 /* file access is primarily random */
/* extension */
-#define O_ACCMODE 0x0003 /* mask for above modes, from 4.4BSD https://minnie.tuhs.org/cgi-bin/utree.pl?file=4.4BSD/usr/include/sys/fcntl.h */
-#define O_NONBLOCK 0x0004 /* non blocking I/O, from BSD apple https://opensource.apple.com/source/xnu/xnu-1228.0.2/bsd/sys/fcntl.h */
-#define O_DIRECTORY 0x200000 /* from Newlib */
+#define O_ACCMODE 0x0003 /* mask for above modes, from 4.4BSD https://minnie.tuhs.org/cgi-bin/utree.pl?file=4.4BSD/usr/include/sys/fcntl.h */
+#define O_NONBLOCK 0x0004 /* non blocking I/O, from BSD apple https://opensource.apple.com/source/xnu/xnu-1228.0.2/bsd/sys/fcntl.h */
+#define O_DIRECTORY 0x200000 /* from Newlib */
#define F_DUPFD 0
#define F_GETFD 1
diff --git a/components/libc/compilers/common/extension/fcntl/octal/fcntl.h b/components/libc/compilers/common/extension/fcntl/octal/fcntl.h
index c3bf851523..117dcc432f 100644
--- a/components/libc/compilers/common/extension/fcntl/octal/fcntl.h
+++ b/components/libc/compilers/common/extension/fcntl/octal/fcntl.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/common/extension/sys/errno.h b/components/libc/compilers/common/extension/sys/errno.h
index d53ce4b386..6c6727ca84 100644
--- a/components/libc/compilers/common/extension/sys/errno.h
+++ b/components/libc/compilers/common/extension/sys/errno.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/common/extension/sys/stat.h b/components/libc/compilers/common/extension/sys/stat.h
index d0e6cc9140..2164ee512f 100644
--- a/components/libc/compilers/common/extension/sys/stat.h
+++ b/components/libc/compilers/common/extension/sys/stat.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/common/extension/sys/types.h b/components/libc/compilers/common/extension/sys/types.h
index 1275803c37..71907a65db 100644
--- a/components/libc/compilers/common/extension/sys/types.h
+++ b/components/libc/compilers/common/extension/sys/types.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/common/compiler_private.h b/components/libc/compilers/common/include/compiler_private.h
index 7f6b42e837..8f150bf104 100644
--- a/components/libc/compilers/common/compiler_private.h
+++ b/components/libc/compilers/common/include/compiler_private.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/common/dirent.h b/components/libc/compilers/common/include/dirent.h
index a9c7ef856d..55ebcd2d01 100644
--- a/components/libc/compilers/common/dirent.h
+++ b/components/libc/compilers/common/include/dirent.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/common/include/posix/ctype.h b/components/libc/compilers/common/include/posix/ctype.h
new file mode 100644
index 0000000000..0ac42e3faf
--- /dev/null
+++ b/components/libc/compilers/common/include/posix/ctype.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2006-2022, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2022-06-07 Meco Man The first version.
+ */
+
+#ifndef __POSIX_CTYPE_H__
+#define __POSIX_CTYPE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <ctype.h>
+
+#ifndef isascii /* some toolchain use macro to define it */
+int isascii(int c);
+#endif
+#ifndef toascii
+int toascii(int c);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __POSIX_CTYPE_H__ */
diff --git a/components/libc/compilers/common/include/posix/stdio.h b/components/libc/compilers/common/include/posix/stdio.h
new file mode 100644
index 0000000000..7dea03bb0d
--- /dev/null
+++ b/components/libc/compilers/common/include/posix/stdio.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2006-2022, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2022-06-07 Meco Man first version
+ */
+
+#ifndef __POSIX_STDIO_H__
+#define __POSIX_STDIO_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+
+ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
+ssize_t getline(char **lineptr, size_t *n, FILE *stream);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __POSIX_STDIO_H__ */
diff --git a/components/libc/compilers/common/include/posix/stdlib.h b/components/libc/compilers/common/include/posix/stdlib.h
new file mode 100644
index 0000000000..bc53ebdecf
--- /dev/null
+++ b/components/libc/compilers/common/include/posix/stdlib.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2006-2022, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2022-06-07 Meco Man The first version.
+ */
+
+#ifndef __POSIX_STDLIB_H__
+#define __POSIX_STDLIB_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <stdlib.h>
+
+char *itoa(int n, char *buffer, int radix);
+char *lltoa(int64_t ll, char *buffer, int radix);
+char *ltoa(long l, char *buffer, int radix);
+char *ulltoa(uint64_t ll, char *buffer, int radix);
+char *ultoa(unsigned long l, char *buffer, int radix);
+char *utoa(unsigned int n, char *buffer, int radix);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __POSIX_STDLIB_H__ */
diff --git a/components/libc/compilers/common/include/posix/string.h b/components/libc/compilers/common/include/posix/string.h
new file mode 100644
index 0000000000..475de513fc
--- /dev/null
+++ b/components/libc/compilers/common/include/posix/string.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2006-2022, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2022-01-12 Meco Man The first version.
+ */
+
+#ifndef __POSIX_STRING_H__
+#define __POSIX_STRING_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stddef.h>
+#include <string.h>
+
+void bzero(void * s, size_t n);
+void bcopy(const void * src, void * dest, size_t n);
+int bcmp(const void * s1, const void * s2, size_t n);
+void explicit_bzero(void * s, size_t n);
+char *index(const char * s, int c);
+char *rindex(const char * s, int c);
+int ffs(int i);
+int ffsl(long i);
+int ffsll(long long i);
+void *memrchr(const void* ptr, int ch, size_t pos);
+size_t strnlen(const char *s, size_t maxlen);
+char* strchrnul(const char *s, int c);
+int strcasecmp(const char * s1, const char * s2);
+int strncasecmp(const char * s1, const char * s2, size_t n);
+char *strdup(const char *s);
+char *strndup(const char *s, size_t size);
+char *strtok_r(char *str, const char *delim, char **saveptr);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __POSIX_STRING_H__ */
diff --git a/components/libc/compilers/common/include/posix/wchar.h b/components/libc/compilers/common/include/posix/wchar.h
new file mode 100644
index 0000000000..91aed4e279
--- /dev/null
+++ b/components/libc/compilers/common/include/posix/wchar.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2006-2022, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2022-06-07 Meco Man The first version
+ */
+
+#ifndef __POSIX_WCHAR_H__
+#define __POSIX_WCHAR_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <wchar.h>
+
+int wcwidth(wchar_t);
+int wcswidth(const wchar_t*, size_t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __POSIX_WCHAR_H__ */
diff --git a/components/libc/compilers/common/sys/ioctl.h b/components/libc/compilers/common/include/sys/ioctl.h
index 4f9287304e..e33f19cd6f 100644
--- a/components/libc/compilers/common/sys/ioctl.h
+++ b/components/libc/compilers/common/include/sys/ioctl.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/common/sys/select.h b/components/libc/compilers/common/include/sys/select.h
index 1232edd6e8..9004658be9 100644
--- a/components/libc/compilers/common/sys/select.h
+++ b/components/libc/compilers/common/include/sys/select.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/common/sys/signal.h b/components/libc/compilers/common/include/sys/signal.h
index 041dd765b7..dbd947acb9 100644
--- a/components/libc/compilers/common/sys/signal.h
+++ b/components/libc/compilers/common/include/sys/signal.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/common/sys/statfs.h b/components/libc/compilers/common/include/sys/statfs.h
index 6f92bf1cf3..818ec9eb77 100644
--- a/components/libc/compilers/common/sys/statfs.h
+++ b/components/libc/compilers/common/include/sys/statfs.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/include/sys/time.h
index 8a4dbb68f3..8a4dbb68f3 100644
--- a/components/libc/compilers/common/sys/time.h
+++ b/components/libc/compilers/common/include/sys/time.h
diff --git a/components/libc/compilers/common/sys/unistd.h b/components/libc/compilers/common/include/sys/unistd.h
index fcf6e342e7..0eaf52423c 100644
--- a/components/libc/compilers/common/sys/unistd.h
+++ b/components/libc/compilers/common/include/sys/unistd.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/common/sys/vfs.h b/components/libc/compilers/common/include/sys/vfs.h
index a9330df002..25b36877f8 100644
--- a/components/libc/compilers/common/sys/vfs.h
+++ b/components/libc/compilers/common/include/sys/vfs.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/common/unistd.h b/components/libc/compilers/common/include/unistd.h
index 4dd71c842e..6e63bc94d8 100644
--- a/components/libc/compilers/common/unistd.h
+++ b/components/libc/compilers/common/include/unistd.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/common/stdlib.c b/components/libc/compilers/common/stdlib.c
deleted file mode 100644
index 12e379acbf..0000000000
--- a/components/libc/compilers/common/stdlib.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2021-02-15 Meco Man first version
- */
-
-#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)
- {
-#ifdef RT_USING_PTHREADS
- extern void pthread_exit(void *value);
- pthread_exit((void *)status);
-#else
- LOG_E("thread:%s exit:%d!", self->name, status);
- rt_thread_control(self, RT_THREAD_CTRL_CLOSE, RT_NULL);
-#endif
- }
-}
-
-#ifdef RT_USING_MSH
-int system(const char *command)
-{
- extern int msh_exec(char *cmd, rt_size_t length);
-
- if (command)
- {
- msh_exec((char *)command, rt_strlen(command));
- }
-
- return 0;
-}
-RTM_EXPORT(system);
-#endif /* RT_USING_MSH */