summaryrefslogtreecommitdiff
path: root/components/libc
diff options
context:
space:
mode:
authorlizhirui <[email protected]>2021-05-18 09:54:11 +0800
committerlizhirui <[email protected]>2021-05-18 09:54:11 +0800
commit9a4e270f9770f778128ffdabe94f101416ce8c61 (patch)
tree9df43fbcc25c3f288ed6fdecd65909d4094d849f /components/libc
parente7fc0c89d2367533dcd1b77e46acaeea7bc3f876 (diff)
parent4e9e3f79a565bb4fdc1d96deda18f9c771aeb0c9 (diff)
Merge branch 'RT-Thread:master' into master
Diffstat (limited to 'components/libc')
-rw-r--r--components/libc/Kconfig38
-rw-r--r--components/libc/aio/posix_aio.c378
-rw-r--r--components/libc/aio/posix_aio.h2
-rw-r--r--components/libc/compilers/armlibc/dirent.h62
-rw-r--r--components/libc/compilers/armlibc/libc.c2
-rw-r--r--components/libc/compilers/armlibc/libc.h2
-rw-r--r--components/libc/compilers/armlibc/libc_syms.c9
-rw-r--r--components/libc/compilers/armlibc/mem_std.c2
-rw-r--r--components/libc/compilers/armlibc/stdio.c2
-rw-r--r--components/libc/compilers/armlibc/sys/README.md1
-rw-r--r--components/libc/compilers/armlibc/sys/errno.h14
-rw-r--r--components/libc/compilers/armlibc/sys/mman.h58
-rw-r--r--components/libc/compilers/armlibc/syscalls.c9
-rw-r--r--components/libc/compilers/common/SConscript10
-rw-r--r--components/libc/compilers/common/dirent.h (renamed from components/libc/compilers/dlib/dirent.h)7
-rw-r--r--components/libc/compilers/common/none-gcc/SConscript13
-rw-r--r--components/libc/compilers/common/none-gcc/fcntl.h (renamed from components/libc/compilers/armlibc/fcntl.h)2
-rw-r--r--components/libc/compilers/common/none-gcc/readme.md3
-rw-r--r--components/libc/compilers/common/none-gcc/sys/stat.h (renamed from components/libc/compilers/armlibc/sys/stat.h)2
-rw-r--r--components/libc/compilers/common/none-gcc/sys/types.h (renamed from components/libc/compilers/armlibc/sys/types.h)14
-rw-r--r--components/libc/compilers/common/none-gcc/sys/unistd.h (renamed from components/libc/compilers/armlibc/sys/unistd.h)11
-rw-r--r--components/libc/compilers/common/none-gcc/unistd.h (renamed from components/libc/compilers/armlibc/unistd.h)2
-rw-r--r--components/libc/compilers/common/readme.md4
-rw-r--r--components/libc/compilers/common/stdlib.c27
-rw-r--r--components/libc/compilers/common/sys/ioctl.h (renamed from components/libc/compilers/armlibc/sys/ioctl.h)7
-rw-r--r--components/libc/compilers/common/sys/mman.h (renamed from components/libc/compilers/newlib/sys/mman.h)4
-rw-r--r--components/libc/compilers/common/sys/statfs.h21
-rw-r--r--components/libc/compilers/common/sys/termios.h (renamed from components/libc/compilers/newlib/sys/termios.h)2
-rw-r--r--components/libc/compilers/common/sys/time.h63
-rw-r--r--components/libc/compilers/common/termios.h2
-rw-r--r--components/libc/compilers/common/time.c431
-rw-r--r--components/libc/compilers/common/unistd.c88
-rw-r--r--components/libc/compilers/dlib/environ.c2
-rw-r--r--components/libc/compilers/dlib/fcntl.h8
-rw-r--r--components/libc/compilers/dlib/libc.c2
-rw-r--r--components/libc/compilers/dlib/libc.h2
-rw-r--r--components/libc/compilers/dlib/rmtx.c60
-rw-r--r--components/libc/compilers/dlib/stdio.c2
-rw-r--r--components/libc/compilers/dlib/sys/README.md1
-rw-r--r--components/libc/compilers/dlib/sys/errno.h16
-rw-r--r--components/libc/compilers/dlib/sys/mman.h58
-rw-r--r--components/libc/compilers/dlib/sys/signal.h16
-rw-r--r--components/libc/compilers/dlib/sys/stat.h8
-rw-r--r--components/libc/compilers/dlib/sys/types.h25
-rw-r--r--components/libc/compilers/dlib/sys/unistd.h50
-rw-r--r--components/libc/compilers/dlib/syscall_close.c2
-rw-r--r--components/libc/compilers/dlib/syscall_lseek.c2
-rw-r--r--components/libc/compilers/dlib/syscall_mem.c2
-rw-r--r--components/libc/compilers/dlib/syscall_open.c2
-rw-r--r--components/libc/compilers/dlib/syscall_read.c2
-rw-r--r--components/libc/compilers/dlib/syscall_remove.c2
-rw-r--r--components/libc/compilers/dlib/syscall_write.c2
-rw-r--r--components/libc/compilers/dlib/syscalls.c13
-rw-r--r--components/libc/compilers/dlib/unistd.h14
-rw-r--r--components/libc/compilers/minilibc/SConscript15
-rw-r--r--components/libc/compilers/minilibc/ctype.c49
-rw-r--r--components/libc/compilers/minilibc/ctype.h18
-rw-r--r--components/libc/compilers/minilibc/errno.h16
-rw-r--r--components/libc/compilers/minilibc/inttypes.h14
-rw-r--r--components/libc/compilers/minilibc/math.c176
-rw-r--r--components/libc/compilers/minilibc/math.h20
-rw-r--r--components/libc/compilers/minilibc/qsort.c52
-rw-r--r--components/libc/compilers/minilibc/rand.c43
-rw-r--r--components/libc/compilers/minilibc/signal.h20
-rw-r--r--components/libc/compilers/minilibc/stddef.h15
-rw-r--r--components/libc/compilers/minilibc/stdint.h266
-rw-r--r--components/libc/compilers/minilibc/stdio.h26
-rw-r--r--components/libc/compilers/minilibc/stdlib.c75
-rw-r--r--components/libc/compilers/minilibc/stdlib.h33
-rw-r--r--components/libc/compilers/minilibc/string.c630
-rw-r--r--components/libc/compilers/minilibc/string.h69
-rw-r--r--components/libc/compilers/minilibc/sys/mman.h58
-rw-r--r--components/libc/compilers/minilibc/sys/stat.h44
-rw-r--r--components/libc/compilers/minilibc/sys/time.h54
-rw-r--r--components/libc/compilers/minilibc/sys/types.h50
-rw-r--r--components/libc/compilers/minilibc/time.c287
-rw-r--r--components/libc/compilers/minilibc/time.h24
-rw-r--r--components/libc/compilers/newlib/SConscript30
-rw-r--r--components/libc/compilers/newlib/libc.c4
-rw-r--r--components/libc/compilers/newlib/libc.h2
-rw-r--r--components/libc/compilers/newlib/libc_syms.c6
-rw-r--r--components/libc/compilers/newlib/machine/time.h2
-rw-r--r--components/libc/compilers/newlib/minilib.c68
-rw-r--r--components/libc/compilers/newlib/stdio.c6
-rw-r--r--components/libc/compilers/newlib/sys/dirent.h65
-rw-r--r--components/libc/compilers/newlib/sys/statfs.h21
-rw-r--r--components/libc/compilers/newlib/syscalls.c108
-rw-r--r--components/libc/getline/README.md10
-rw-r--r--components/libc/getline/posix_getline.c7
-rw-r--r--components/libc/getline/posix_getline.h5
-rw-r--r--components/libc/libdl/arch/arm.c4
-rw-r--r--components/libc/libdl/arch/riscv.c60
-rw-r--r--components/libc/libdl/arch/x86.c10
-rw-r--r--components/libc/libdl/dlclose.c2
-rw-r--r--components/libc/libdl/dlelf.c114
-rw-r--r--components/libc/libdl/dlelf.h119
-rw-r--r--components/libc/libdl/dlerror.c6
-rw-r--r--components/libc/libdl/dlfcn.h4
-rw-r--r--components/libc/libdl/dlmodule.c10
-rw-r--r--components/libc/libdl/dlmodule.h2
-rw-r--r--components/libc/libdl/dlopen.c6
-rw-r--r--components/libc/libdl/dlsym.c4
-rw-r--r--components/libc/mmap/posix_mmap.c2
-rw-r--r--components/libc/pthreads/mqueue.c2
-rw-r--r--components/libc/pthreads/mqueue.h2
-rw-r--r--components/libc/pthreads/posix_types.h11
-rw-r--r--components/libc/pthreads/pthread.c27
-rw-r--r--components/libc/pthreads/pthread.h4
-rw-r--r--components/libc/pthreads/pthread_attr.c4
-rw-r--r--components/libc/pthreads/pthread_barrier.c2
-rw-r--r--components/libc/pthreads/pthread_cond.c10
-rw-r--r--components/libc/pthreads/pthread_internal.h5
-rw-r--r--components/libc/pthreads/pthread_mutex.c4
-rw-r--r--components/libc/pthreads/pthread_rwlock.c10
-rw-r--r--components/libc/pthreads/pthread_spin.c2
-rw-r--r--components/libc/pthreads/pthread_tls.c2
-rw-r--r--components/libc/pthreads/sched.c2
-rw-r--r--components/libc/pthreads/sched.h2
-rw-r--r--components/libc/pthreads/semaphore.c2
-rw-r--r--components/libc/pthreads/semaphore.h2
-rw-r--r--components/libc/signal/posix_signal.c2
-rw-r--r--components/libc/signal/posix_signal.h2
-rw-r--r--components/libc/termios/posix_termios.c2
-rw-r--r--components/libc/termios/posix_termios.h2
-rw-r--r--components/libc/time/SConscript12
-rw-r--r--components/libc/time/clock_time.c188
-rw-r--r--components/libc/time/clock_time.h52
-rw-r--r--components/libc/time/posix_sleep.c30
128 files changed, 1309 insertions, 3388 deletions
diff --git a/components/libc/Kconfig b/components/libc/Kconfig
index 65c8d44225..a89b252caa 100644
--- a/components/libc/Kconfig
+++ b/components/libc/Kconfig
@@ -16,26 +16,26 @@ endif
if RT_USING_LIBC && RT_USING_DFS
config RT_USING_POSIX
- bool "Enable POSIX layer for poll/select, stdin etc"
+ bool "Enable POSIX layer for compatibility with UNIX APIs, poll/select etc"
select RT_USING_DFS_DEVFS
default y
if RT_USING_POSIX
- config RT_USING_POSIX_MMAP
- bool "Enable mmap() API"
- default n
+ config RT_USING_POSIX_MMAP
+ bool "Enable mmap() API"
+ default n
- config RT_USING_POSIX_TERMIOS
- bool "Enable termios APIs"
- default n
+ config RT_USING_POSIX_TERMIOS
+ bool "Enable termios APIs"
+ default n
- config RT_USING_POSIX_GETLINE
- bool "Enable getline()/getdelim() APIs"
- default n
+ config RT_USING_POSIX_GETLINE
+ bool "Enable getline()/getdelim() APIs"
+ default n
- config RT_USING_POSIX_AIO
- bool "Enable AIO"
- default n
+ config RT_USING_POSIX_AIO
+ bool "Enable AIO"
+ default n
endif
endif
@@ -54,9 +54,15 @@ if RT_USING_LIBC
endif
if RT_USING_LIBC != y
- config RT_LIBC_USING_TIME
- bool "Enable TIME FUNCTIONS WITHOUT COMPILER'S LIBC"
- default y
+ config RT_LIBC_USING_TIME
+ bool "Enable time functions without compiler's libc"
+ default y
endif
+config RT_LIBC_FIXED_TIMEZONE
+ depends on (RT_LIBC_USING_TIME || RT_USING_LIBC)
+ int "Manually set a fixed time zone (UTC+)"
+ range -12 12
+ default 8
+
endmenu
diff --git a/components/libc/aio/posix_aio.c b/components/libc/aio/posix_aio.c
index 3eb7634495..66f15e4c57 100644
--- a/components/libc/aio/posix_aio.c
+++ b/components/libc/aio/posix_aio.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -22,25 +22,25 @@
struct rt_workqueue* aio_queue = NULL;
/**
- * The aio_cancel() function shall attempt to cancel one or more asynchronous I/O
- * requests currently outstanding against file descriptor fildes. The aiocbp
- * argument points to the asynchronous I/O control block for a particular request
- * to be canceled. If aiocbp is NULL, then all outstanding cancelable asynchronous
+ * The aio_cancel() function shall attempt to cancel one or more asynchronous I/O
+ * requests currently outstanding against file descriptor fildes. The aiocbp
+ * argument points to the asynchronous I/O control block for a particular request
+ * to be canceled. If aiocbp is NULL, then all outstanding cancelable asynchronous
* I/O requests against fildes shall be canceled.
- *
- * Normal asynchronous notification shall occur for asynchronous I/O operations
- * that are successfully canceled. If there are requests that cannot be canceled,
- * then the normal asynchronous completion process shall take place for those
+ *
+ * Normal asynchronous notification shall occur for asynchronous I/O operations
+ * that are successfully canceled. If there are requests that cannot be canceled,
+ * then the normal asynchronous completion process shall take place for those
* requests when they are completed.
- *
- * For requested operations that are successfully canceled, the associated error
- * status shall be set to [ECANCELED] and the return status shall be -1. For
- * requested operations that are not successfully canceled, the aiocbp shall not
+ *
+ * For requested operations that are successfully canceled, the associated error
+ * status shall be set to [ECANCELED] and the return status shall be -1. For
+ * requested operations that are not successfully canceled, the aiocbp shall not
* be modified by aio_cancel().
- *
- * If aiocbp is not NULL, then if fildes does not have the same value as the file
+ *
+ * If aiocbp is not NULL, then if fildes does not have the same value as the file
* descriptor with which the asynchronous operation was initiated, unspecified results occur.
- *
+ *
* Which operations are cancelable is implementation-defined.
*/
int aio_cancel(int fd, struct aiocb *cb)
@@ -61,9 +61,9 @@ int aio_cancel(int fd, struct aiocb *cb)
}
/**
- * The aio_error() function shall return the error status associated with the
- * aiocb structure referenced by the aiocbp argument. The error status for an
- * asynchronous I/O operation is the errno value that would be set by the corresponding
+ * The aio_error() function shall return the error status associated with the
+ * aiocb structure referenced by the aiocbp argument. The error status for an
+ * asynchronous I/O operation is the errno value that would be set by the corresponding
* read(), write(),
*/
int aio_error (const struct aiocb *cb)
@@ -77,44 +77,44 @@ int aio_error (const struct aiocb *cb)
}
/**
- * The aio_fsync() function shall asynchronously perform a file synchronization
- * operation, as specified by the op argument, for I/O operations associated with
- * the file indicated by the file descriptor aio_fildes member of the aiocb
- * structure referenced by the aiocbp argument and queued at the time of the
- * call to aio_fsync(). The function call shall return when the synchronization
- * request has been initiated or queued to the file or device (even when the data
+ * The aio_fsync() function shall asynchronously perform a file synchronization
+ * operation, as specified by the op argument, for I/O operations associated with
+ * the file indicated by the file descriptor aio_fildes member of the aiocb
+ * structure referenced by the aiocbp argument and queued at the time of the
+ * call to aio_fsync(). The function call shall return when the synchronization
+ * request has been initiated or queued to the file or device (even when the data
* cannot be synchronized immediately).
- *
- * option: If op is O_DSYNC, all currently queued I/O operations shall be completed
- * as if by a call to fdatasync(); that is, as defined for synchronized I/O data
+ *
+ * option: If op is O_DSYNC, all currently queued I/O operations shall be completed
+ * as if by a call to fdatasync(); that is, as defined for synchronized I/O data
* integrity completion.
- *
- * option: If op is O_SYNC, all currently queued I/O operations shall be completed
- * as if by a call to fsync(); that is, as defined for synchronized I/O file integrity
- * completion. If the aio_fsync() function fails, or if the operation queued by
- * aio_fsync() fails, then outstanding I/O operations are not guaranteed to have
+ *
+ * option: If op is O_SYNC, all currently queued I/O operations shall be completed
+ * as if by a call to fsync(); that is, as defined for synchronized I/O file integrity
+ * completion. If the aio_fsync() function fails, or if the operation queued by
+ * aio_fsync() fails, then outstanding I/O operations are not guaranteed to have
* been completed.
- *
- * If aio_fsync() succeeds, then it is only the I/O that was queued at the time
- * of the call to aio_fsync() that is guaranteed to be forced to the relevant
+ *
+ * If aio_fsync() succeeds, then it is only the I/O that was queued at the time
+ * of the call to aio_fsync() that is guaranteed to be forced to the relevant
* completion state. The completion of subsequent I/O on the file descriptor is
* not guaranteed to be completed in a synchronized fashion.
- *
- * The aiocbp argument refers to an asynchronous I/O control block. The aiocbp
- * value may be used as an argument to aio_error() and aio_return() in order to
- * determine the error status and return status, respectively, of the asynchronous
- * operation while it is proceeding. When the request is queued, the error status
- * for the operation is [EINPROGRESS]. When all data has been successfully transferred,
- * the error status shall be reset to reflect the success or failure of the operation.
- * If the operation does not complete successfully, the error status for the
- * operation shall be set to indicate the error. The aio_sigevent member determines
- * the asynchronous notification to occur as specified in Signal Generation and
- * Delivery when all operations have achieved synchronized I/O completion. All
- * other members of the structure referenced by aiocbp are ignored. If the control
- * block referenced by aiocbp becomes an illegal address prior to asynchronous
+ *
+ * The aiocbp argument refers to an asynchronous I/O control block. The aiocbp
+ * value may be used as an argument to aio_error() and aio_return() in order to
+ * determine the error status and return status, respectively, of the asynchronous
+ * operation while it is proceeding. When the request is queued, the error status
+ * for the operation is [EINPROGRESS]. When all data has been successfully transferred,
+ * the error status shall be reset to reflect the success or failure of the operation.
+ * If the operation does not complete successfully, the error status for the
+ * operation shall be set to indicate the error. The aio_sigevent member determines
+ * the asynchronous notification to occur as specified in Signal Generation and
+ * Delivery when all operations have achieved synchronized I/O completion. All
+ * other members of the structure referenced by aiocbp are ignored. If the control
+ * block referenced by aiocbp becomes an illegal address prior to asynchronous
* I/O completion, then the behavior is undefined.
- *
- * If the aio_fsync() function fails or aiocbp indicates an error condition,
+ *
+ * If the aio_fsync() function fails or aiocbp indicates an error condition,
* data is not guaranteed to have been successfully transferred.
*/
static void aio_fync_work(struct rt_work* work, void* work_data)
@@ -169,7 +169,7 @@ static void aio_read_work(struct rt_work* work, void* work_data)
level = rt_hw_interrupt_disable();
if (len <= 0)
cb->aio_result = errno;
- else
+ else
cb->aio_result = len;
rt_hw_interrupt_enable(level);
@@ -177,51 +177,51 @@ static void aio_read_work(struct rt_work* work, void* work_data)
}
/**
- * The aio_read() function shall read aiocbp->aio_nbytes from the file associated
- * with aiocbp->aio_fildes into the buffer pointed to by aiocbp->aio_buf. The
- * function call shall return when the read request has been initiated or queued
+ * The aio_read() function shall read aiocbp->aio_nbytes from the file associated
+ * with aiocbp->aio_fildes into the buffer pointed to by aiocbp->aio_buf. The
+ * function call shall return when the read request has been initiated or queued
* to the file or device (even when the data cannot be delivered immediately).
- *
- * If prioritized I/O is supported for this file, then the asynchronous operation
- * shall be submitted at a priority equal to a base scheduling priority minus
- * aiocbp->aio_reqprio. If Thread Execution Scheduling is not supported, then
+ *
+ * If prioritized I/O is supported for this file, then the asynchronous operation
+ * shall be submitted at a priority equal to a base scheduling priority minus
+ * aiocbp->aio_reqprio. If Thread Execution Scheduling is not supported, then
* the base scheduling priority is that of the calling process;
- *
- * otherwise, the base scheduling priority is that of the calling thread.
- *
- * The aiocbp value may be used as an argument to aio_error() and aio_return()
- * in order to determine the error status and return status, respectively, of
- * the asynchronous operation while it is proceeding. If an error condition is
- * encountered during queuing, the function call shall return without having
- * initiated or queued the request. The requested operation takes place at the
- * absolute position in the file as given by aio_offset, as if lseek() were called
- * immediately prior to the operation with an offset equal to aio_offset and a
- * whence equal to SEEK_SET. After a successful call to enqueue an asynchronous
+ *
+ * otherwise, the base scheduling priority is that of the calling thread.
+ *
+ * The aiocbp value may be used as an argument to aio_error() and aio_return()
+ * in order to determine the error status and return status, respectively, of
+ * the asynchronous operation while it is proceeding. If an error condition is
+ * encountered during queuing, the function call shall return without having
+ * initiated or queued the request. The requested operation takes place at the
+ * absolute position in the file as given by aio_offset, as if lseek() were called
+ * immediately prior to the operation with an offset equal to aio_offset and a
+ * whence equal to SEEK_SET. After a successful call to enqueue an asynchronous
* I/O operation, the value of the file offset for the file is unspecified.
*
- * The aio_sigevent member specifies the notification which occurs when the
+ * The aio_sigevent member specifies the notification which occurs when the
* request is completed.
*
* The aiocbp->aio_lio_opcode field shall be ignored by aio_read().
- *
- * The aiocbp argument points to an aiocb structure. If the buffer pointed to by
- * aiocbp->aio_buf or the control block pointed to by aiocbp becomes an illegal
+ *
+ * The aiocbp argument points to an aiocb structure. If the buffer pointed to by
+ * aiocbp->aio_buf or the control block pointed to by aiocbp becomes an illegal
* address prior to asynchronous I/O completion, then the behavior is undefined.
- *
- * Simultaneous asynchronous operations using the same aiocbp produce undefined
+ *
+ * Simultaneous asynchronous operations using the same aiocbp produce undefined
* results.
- *
+ *
* If synchronized I/O is enabled on the file associated with aiocbp->aio_fildes,
- * the behavior of this function shall be according to the definitions of synchronized
- * I/O data integrity completion and synchronized I/O file integrity completion.
- *
- * For any system action that changes the process memory space while an asynchronous
- * I/O is outstanding to the address range being changed, the result of that action
+ * the behavior of this function shall be according to the definitions of synchronized
+ * I/O data integrity completion and synchronized I/O file integrity completion.
+ *
+ * For any system action that changes the process memory space while an asynchronous
+ * I/O is outstanding to the address range being changed, the result of that action
* is undefined.
- *
- * For regular files, no data transfer shall occur past the offset maximum
+ *
+ * For regular files, no data transfer shall occur past the offset maximum
* established in the open file description associated with aiocbp->aio_fildes.
- *
+ *
*/
int aio_read(struct aiocb *cb)
{
@@ -242,16 +242,16 @@ int aio_read(struct aiocb *cb)
}
/**
- * The aio_return() function shall return the return status associated with the
- * aiocb structure referenced by the aiocbp argument. The return status for an
- * asynchronous I/O operation is the value that would be returned by the corresponding
- * read(), write(), or fsync() function call. If the error status for the operation
- * is equal to [EINPROGRESS], then the return status for the operation is undefined.
- * The aio_return() function may be called exactly once to retrieve the return
- * status of a given asynchronous operation; thereafter, if the same aiocb structure
- * is used in a call to aio_return() or aio_error(), an error may be returned.
- * When the aiocb structure referred to by aiocbp is used to submit another asynchronous
- * operation, then aio_return() may be successfully used to retrieve the return
+ * The aio_return() function shall return the return status associated with the
+ * aiocb structure referenced by the aiocbp argument. The return status for an
+ * asynchronous I/O operation is the value that would be returned by the corresponding
+ * read(), write(), or fsync() function call. If the error status for the operation
+ * is equal to [EINPROGRESS], then the return status for the operation is undefined.
+ * The aio_return() function may be called exactly once to retrieve the return
+ * status of a given asynchronous operation; thereafter, if the same aiocb structure
+ * is used in a call to aio_return() or aio_error(), an error may be returned.
+ * When the aiocb structure referred to by aiocbp is used to submit another asynchronous
+ * operation, then aio_return() may be successfully used to retrieve the return
* status of that operation.
*/
ssize_t aio_return(struct aiocb *cb)
@@ -268,23 +268,23 @@ ssize_t aio_return(struct aiocb *cb)
}
/**
- * The aio_suspend() function shall suspend the calling thread until at least
- * one of the asynchronous I/O operations referenced by the list argument has
- * completed, until a signal interrupts the function, or, if timeout is not NULL,
- * until the time interval specified by timeout has passed. If any of the aiocb
- * structures in the list correspond to completed asynchronous I/O operations
- * (that is, the error status for the operation is not equal to [EINPROGRESS])
- * at the time of the call, the function shall return without suspending the
- * calling thread. The list argument is an array of pointers to asynchronous I/O
- * control blocks. The nent argument indicates the number of elements in the
- * array. Each aiocb structure pointed to has been used in initiating an asynchronous
- * I/O request via aio_read(), aio_write(), or lio_listio(). This array may
- * contain null pointers, which are ignored. If this array contains pointers
- * that refer to aiocb structures that have not been used in submitting asynchronous
+ * The aio_suspend() function shall suspend the calling thread until at least
+ * one of the asynchronous I/O operations referenced by the list argument has
+ * completed, until a signal interrupts the function, or, if timeout is not NULL,
+ * until the time interval specified by timeout has passed. If any of the aiocb
+ * structures in the list correspond to completed asynchronous I/O operations
+ * (that is, the error status for the operation is not equal to [EINPROGRESS])
+ * at the time of the call, the function shall return without suspending the
+ * calling thread. The list argument is an array of pointers to asynchronous I/O
+ * control blocks. The nent argument indicates the number of elements in the
+ * array. Each aiocb structure pointed to has been used in initiating an asynchronous
+ * I/O request via aio_read(), aio_write(), or lio_listio(). This array may
+ * contain null pointers, which are ignored. If this array contains pointers
+ * that refer to aiocb structures that have not been used in submitting asynchronous
* I/O, the effect is undefined.
- *
- * If the time interval indicated in the timespec structure pointed to by timeout
- * passes before any of the I/O operations referenced by list are completed, then
+ *
+ * If the time interval indicated in the timespec structure pointed to by timeout
+ * passes before any of the I/O operations referenced by list are completed, then
* aio_suspend() shall return with an error.
*/
int aio_suspend(const struct aiocb *const list[], int nent,
@@ -315,7 +315,7 @@ static void aio_write_work(struct rt_work* work, void* work_data)
level = rt_hw_interrupt_disable();
if (len <= 0)
cb->aio_result = errno;
- else
+ else
cb->aio_result = len;
rt_hw_interrupt_enable(level);
@@ -323,42 +323,42 @@ static void aio_write_work(struct rt_work* work, void* work_data)
}
/**
- * The aio_write() function shall write aiocbp->aio_nbytes to the file associated
- * with aiocbp->aio_fildes from the buffer pointed to by aiocbp->aio_buf. The
- * function shall return when the write request has been initiated or, at a minimum,
+ * The aio_write() function shall write aiocbp->aio_nbytes to the file associated
+ * with aiocbp->aio_fildes from the buffer pointed to by aiocbp->aio_buf. The
+ * function shall return when the write request has been initiated or, at a minimum,
* queued to the file or device.
- *
- * The aiocbp argument may be used as an argument to aio_error() and aio_return()
- * in order to determine the error status and return status, respectively, of the
+ *
+ * The aiocbp argument may be used as an argument to aio_error() and aio_return()
+ * in order to determine the error status and return status, respectively, of the
* asynchronous operation while it is proceeding.
- *
- * The aiocbp argument points to an aiocb structure. If the buffer pointed to by
- * aiocbp->aio_buf or the control block pointed to by aiocbp becomes an illegal
+ *
+ * The aiocbp argument points to an aiocb structure. If the buffer pointed to by
+ * aiocbp->aio_buf or the control block pointed to by aiocbp becomes an illegal
* address prior to asynchronous I/O completion, then the behavior is undefined.
- *
- * If O_APPEND is not set for the file descriptor aio_fildes, then the requested
- * operation shall take place at the absolute position in the file as given by
- * aio_offset, as if lseek() were called immediately prior to the operation with
- * an offset equal to aio_offset and a whence equal to SEEK_SET. If O_APPEND is
- * set for the file descriptor, or if aio_fildes is associated with a device that
- * is incapable of seeking, write operations append to the file in the same order
- * as the calls were made, except under circumstances described in Asynchronous
- * I/O. After a successful call to enqueue an asynchronous I/O operation, the value
+ *
+ * If O_APPEND is not set for the file descriptor aio_fildes, then the requested
+ * operation shall take place at the absolute position in the file as given by
+ * aio_offset, as if lseek() were called immediately prior to the operation with
+ * an offset equal to aio_offset and a whence equal to SEEK_SET. If O_APPEND is
+ * set for the file descriptor, or if aio_fildes is associated with a device that
+ * is incapable of seeking, write operations append to the file in the same order
+ * as the calls were made, except under circumstances described in Asynchronous
+ * I/O. After a successful call to enqueue an asynchronous I/O operation, the value
* of the file offset for the file is unspecified.
- *
- * The aio_sigevent member specifies the notification which occurs when the request
+ *
+ * The aio_sigevent member specifies the notification which occurs when the request
* is completed.
- *
+ *
* The aiocbp->aio_lio_opcode field shall be ignored by aio_write().
- *
- * Simultaneous asynchronous operations using the same aiocbp produce undefined
+ *
+ * Simultaneous asynchronous operations using the same aiocbp produce undefined
* results.
- *
- * If synchronized I/O is enabled on the file associated with aiocbp->aio_fildes,
- * the behavior of this function shall be according to the definitions of synchronized
+ *
+ * If synchronized I/O is enabled on the file associated with aiocbp->aio_fildes,
+ * the behavior of this function shall be according to the definitions of synchronized
* I/O data integrity completion, and synchronized I/O file integrity completion.
- *
- * For regular files, no data transfer shall occur past the offset maximum established
+ *
+ * For regular files, no data transfer shall occur past the offset maximum established
* in the open file description associated with aiocbp->aio_fildes.
*/
int aio_write(struct aiocb *cb)
@@ -385,69 +385,69 @@ int aio_write(struct aiocb *cb)
}
/**
- * The lio_listio() function shall initiate a list of I/O requests with a single
+ * The lio_listio() function shall initiate a list of I/O requests with a single
* function call.
- *
- * The mode argument takes one of the values LIO_WAIT or LIO_NOWAIT declared in
- * <aio.h> and determines whether the function returns when the I/O operations
- * have been completed, or as soon as the operations have been queued. If the
- * mode argument is LIO_WAIT, the function shall wait until all I/O is complete
+ *
+ * The mode argument takes one of the values LIO_WAIT or LIO_NOWAIT declared in
+ * <aio.h> and determines whether the function returns when the I/O operations
+ * have been completed, or as soon as the operations have been queued. If the
+ * mode argument is LIO_WAIT, the function shall wait until all I/O is complete
* and the sig argument shall be ignored.
- *
- * If the mode argument is LIO_NOWAIT, the function shall return immediately, and
- * asynchronous notification shall occur, according to the sig argument, when all
- * the I/O operations complete. If sig is NULL, then no asynchronous notification
- * shall occur. If sig is not NULL, asynchronous notification occurs as specified
+ *
+ * If the mode argument is LIO_NOWAIT, the function shall return immediately, and
+ * asynchronous notification shall occur, according to the sig argument, when all
+ * the I/O operations complete. If sig is NULL, then no asynchronous notification
+ * shall occur. If sig is not NULL, asynchronous notification occurs as specified
* in Signal Generation and Delivery when all the requests in list have completed.
- *
+ *
* The I/O requests enumerated by list are submitted in an unspecified order.
- *
- * The list argument is an array of pointers to aiocb structures. The array contains
+ *
+ * The list argument is an array of pointers to aiocb structures. The array contains
* nent elements. The array may contain NULL elements, which shall be ignored.
- *
- * If the buffer pointed to by list or the aiocb structures pointed to by the
- * elements of the array list become illegal addresses before all asynchronous I/O
- * completed and, if necessary, the notification is sent, then the behavior is
- * undefined. If the buffers pointed to by the aio_buf member of the aiocb structure
- * pointed to by the elements of the array list become illegal addresses prior to
- * the asynchronous I/O associated with that aiocb structure being completed, the
+ *
+ * If the buffer pointed to by list or the aiocb structures pointed to by the
+ * elements of the array list become illegal addresses before all asynchronous I/O
+ * completed and, if necessary, the notification is sent, then the behavior is
+ * undefined. If the buffers pointed to by the aio_buf member of the aiocb structure
+ * pointed to by the elements of the array list become illegal addresses prior to
+ * the asynchronous I/O associated with that aiocb structure being completed, the
* behavior is undefined.
- *
- * The aio_lio_opcode field of each aiocb structure specifies the operation to be
- * performed. The supported operations are LIO_READ, LIO_WRITE, and LIO_NOP; these
- * symbols are defined in <aio.h>. The LIO_NOP operation causes the list entry to
- * be ignored. If the aio_lio_opcode element is equal to LIO_READ, then an I/O operation
- * is submitted as if by a call to aio_read() with the aiocbp equal to the address
- * of the aiocb structure. If the aio_lio_opcode element is equal to LIO_WRITE, then
- * an I/O operation is submitted as if by a call to aio_write() with the aiocbp equal
+ *
+ * The aio_lio_opcode field of each aiocb structure specifies the operation to be
+ * performed. The supported operations are LIO_READ, LIO_WRITE, and LIO_NOP; these
+ * symbols are defined in <aio.h>. The LIO_NOP operation causes the list entry to
+ * be ignored. If the aio_lio_opcode element is equal to LIO_READ, then an I/O operation
+ * is submitted as if by a call to aio_read() with the aiocbp equal to the address
+ * of the aiocb structure. If the aio_lio_opcode element is equal to LIO_WRITE, then
+ * an I/O operation is submitted as if by a call to aio_write() with the aiocbp equal
* to the address of the aiocb structure.
- *
- * The aio_fildes member specifies the file descriptor on which the operation is to
+ *
+ * The aio_fildes member specifies the file descriptor on which the operation is to
* be performed.
- *
- * The aio_buf member specifies the address of the buffer to or from which the data
+ *
+ * The aio_buf member specifies the address of the buffer to or from which the data
* is transferred.
- *
+ *
* The aio_nbytes member specifies the number of bytes of data to be transferred.
- *
- * The members of the aiocb structure further describe the I/O operation to be
- * performed, in a manner identical to that of the corresponding aiocb structure
+ *
+ * The members of the aiocb structure further describe the I/O operation to be
+ * performed, in a manner identical to that of the corresponding aiocb structure
* when used by the aio_read() and aio_write() functions.
- *
- * The nent argument specifies how many elements are members of the list; that is,
+ *
+ * The nent argument specifies how many elements are members of the list; that is,
* the length of the array.
- *
- * The behavior of this function is altered according to the definitions of synchronized
- * I/O data integrity completion and synchronized I/O file integrity completion if
+ *
+ * The behavior of this function is altered according to the definitions of synchronized
+ * I/O data integrity completion and synchronized I/O file integrity completion if
* synchronized I/O is enabled on the file associated with aio_fildes.
- *
- * For regular files, no data transfer shall occur past the offset maximum established
+ *
+ * For regular files, no data transfer shall occur past the offset maximum established
* in the open file description associated with aiocbp->aio_fildes.
- *
- * If sig->sigev_notify is SIGEV_THREAD and sig->sigev_notify_attributes is a
- * non-null pointer and the block pointed to by this pointer becomes an illegal
- * address prior to all asynchronous I/O being completed, then the behavior is
- * undefined.
+ *
+ * If sig->sigev_notify is SIGEV_THREAD and sig->sigev_notify_attributes is a
+ * non-null pointer and the block pointed to by this pointer becomes an illegal
+ * address prior to all asynchronous I/O being completed, then the behavior is
+ * undefined.
*/
int lio_listio(int mode, struct aiocb * const list[], int nent,
struct sigevent *sig)
diff --git a/components/libc/aio/posix_aio.h b/components/libc/aio/posix_aio.h
index f20ed48cb3..de11738515 100644
--- a/components/libc/aio/posix_aio.h
+++ b/components/libc/aio/posix_aio.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/armlibc/dirent.h b/components/libc/compilers/armlibc/dirent.h
deleted file mode 100644
index d3bc58cbc5..0000000000
--- a/components/libc/compilers/armlibc/dirent.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __RTT_DIRENT_H__
-#define __RTT_DIRENT_H__
-
-#include <rtthread.h>
-#include <rtlibc.h>
-
-/*
-* dirent.h - format of directory entries
- * Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html
- */
-
-/* File types */
-#define FT_REGULAR 0 /* regular file */
-#define FT_SOCKET 1 /* socket file */
-#define FT_DIRECTORY 2 /* directory */
-#define FT_USER 3 /* user defined */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef HAVE_DIR_STRUCTURE
-typedef struct
-{
- int fd; /* directory file */
- char buf[512];
- int num;
- int cur;
-} DIR;
-#endif
-
-#ifndef HAVE_DIRENT_STRUCTURE
-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 */
-};
-#endif
-
-int closedir(DIR *);
-DIR *opendir(const char *);
-struct dirent *readdir(DIR *);
-int readdir_r(DIR *, struct dirent *, struct dirent **);
-void rewinddir(DIR *);
-void seekdir(DIR *, long int);
-long telldir(DIR *);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/components/libc/compilers/armlibc/libc.c b/components/libc/compilers/armlibc/libc.c
index fee390d4b4..971ddb8d49 100644
--- a/components/libc/compilers/armlibc/libc.c
+++ b/components/libc/compilers/armlibc/libc.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/armlibc/libc.h b/components/libc/compilers/armlibc/libc.h
index b9b1b6212d..aecf8cdc50 100644
--- a/components/libc/compilers/armlibc/libc.h
+++ b/components/libc/compilers/armlibc/libc.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/armlibc/libc_syms.c b/components/libc/compilers/armlibc/libc_syms.c
index 0e1c42d899..829d57b559 100644
--- a/components/libc/compilers/armlibc/libc_syms.c
+++ b/components/libc/compilers/armlibc/libc_syms.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -10,8 +10,6 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
-#include <time.h>
-
#include <rtm.h>
/* some export routines for module */
@@ -35,11 +33,6 @@ RTM_EXPORT(memchr);
RTM_EXPORT(toupper);
RTM_EXPORT(atoi);
-#ifdef RT_USING_RTC
-RTM_EXPORT(localtime);
-RTM_EXPORT(time);
-#endif
-
/* import the full stdio for printf */
#if defined(RT_USING_MODULE) && defined(__MICROLIB)
#error "[RT_USING_LIBC] Please use standard libc but not microlib."
diff --git a/components/libc/compilers/armlibc/mem_std.c b/components/libc/compilers/armlibc/mem_std.c
index e160104a25..c350aa68fa 100644
--- a/components/libc/compilers/armlibc/mem_std.c
+++ b/components/libc/compilers/armlibc/mem_std.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/armlibc/stdio.c b/components/libc/compilers/armlibc/stdio.c
index 5262a4dd92..c786c78aa5 100644
--- a/components/libc/compilers/armlibc/stdio.c
+++ b/components/libc/compilers/armlibc/stdio.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/armlibc/sys/README.md b/components/libc/compilers/armlibc/sys/README.md
deleted file mode 100644
index 7ad10a7d43..0000000000
--- a/components/libc/compilers/armlibc/sys/README.md
+++ /dev/null
@@ -1 +0,0 @@
-Because Keil MDK leaks some system header file, we put them in here. \ No newline at end of file
diff --git a/components/libc/compilers/armlibc/sys/errno.h b/components/libc/compilers/armlibc/sys/errno.h
deleted file mode 100644
index 9c4307ebfb..0000000000
--- a/components/libc/compilers/armlibc/sys/errno.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef SYS_ERRNO_H__
-#define SYS_ERRNO_H__
-
-#include <rtthread.h>
-
-#endif
diff --git a/components/libc/compilers/armlibc/sys/mman.h b/components/libc/compilers/armlibc/sys/mman.h
deleted file mode 100644
index 8c61b32b7c..0000000000
--- a/components/libc/compilers/armlibc/sys/mman.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/11/30 Bernard The first version.
- */
-
-#ifndef _SYS_MMAN_H
-#define _SYS_MMAN_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MAP_FAILED ((void *) -1)
-
-#define MAP_SHARED 0x01
-#define MAP_PRIVATE 0x02
-#define MAP_TYPE 0x0f
-#define MAP_FIXED 0x10
-#define MAP_ANON 0x20
-#define MAP_ANONYMOUS MAP_ANON
-#define MAP_NORESERVE 0x4000
-#define MAP_GROWSDOWN 0x0100
-#define MAP_DENYWRITE 0x0800
-#define MAP_EXECUTABLE 0x1000
-#define MAP_LOCKED 0x2000
-#define MAP_POPULATE 0x8000
-#define MAP_NONBLOCK 0x10000
-#define MAP_STACK 0x20000
-#define MAP_HUGETLB 0x40000
-#define MAP_FILE 0
-
-#define PROT_NONE 0
-#define PROT_READ 1
-#define PROT_WRITE 2
-#define PROT_EXEC 4
-#define PROT_GROWSDOWN 0x01000000
-#define PROT_GROWSUP 0x02000000
-
-#define MS_ASYNC 1
-#define MS_INVALIDATE 2
-#define MS_SYNC 4
-
-#define MCL_CURRENT 1
-#define MCL_FUTURE 2
-#define MCL_ONFAULT 4
-
-void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off);
-int munmap (void *start, size_t len);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c
index 37f296fc3a..ce4c358993 100644
--- a/components/libc/compilers/armlibc/syscalls.c
+++ b/components/libc/compilers/armlibc/syscalls.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -9,7 +9,7 @@
* 2013-11-24 aozima fixed _sys_read()/_sys_write() issues.
* 2014-08-03 bernard If using msh, use system() implementation
* in msh.
- * 2020-08-05 Meco Man fixed _sys_flen() compiling-warning when
+ * 2020-08-05 Meco Man fixed _sys_flen() compiling-warning when
* RT_USING_DFS is not defined
* 2020-02-13 Meco Man re-implement exit() and abort()
* 2020-02-14 Meco Man implement _sys_tmpnam()
@@ -256,6 +256,7 @@ void _ttywrch(int ch)
#endif
}
+/* for exit() and abort() */
RT_WEAK void _sys_exit(int return_code)
{
extern void __rt_libc_exit(int status);
@@ -314,7 +315,7 @@ int system(const char *string)
#ifdef __MICROLIB
#include <stdio.h>
-int fputc(int c, FILE *f)
+int fputc(int c, FILE *f)
{
char ch[2] = {0};
@@ -323,7 +324,7 @@ int fputc(int c, FILE *f)
return 1;
}
-int fgetc(FILE *f)
+int fgetc(FILE *f)
{
#ifdef RT_USING_POSIX
char ch;
diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript
index ecdee2637e..039e53a0b3 100644
--- a/components/libc/compilers/common/SConscript
+++ b/components/libc/compilers/common/SConscript
@@ -10,7 +10,7 @@ CPPPATH = [cwd]
if GetDepend('RT_USING_LIBC'):
src += Glob('*.c')
else:
- if GetDepend('RT_LIBC_USING_TIME') and not GetDepend('RT_USING_MINILIBC'):
+ if GetDepend('RT_LIBC_USING_TIME'):
src += ['time.c']
if GetDepend('RT_USING_POSIX') == False:
@@ -21,7 +21,13 @@ if rtconfig.CROSS_TOOL == 'keil':
else:
CPPDEFINES = []
-if not GetDepend('RT_USING_MINILIBC') and (GetDepend('RT_USING_LIBC') or GetDepend('RT_LIBC_USING_TIME')):
+if GetDepend('RT_USING_LIBC') or GetDepend('RT_LIBC_USING_TIME'):
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'))
+
Return('group')
diff --git a/components/libc/compilers/dlib/dirent.h b/components/libc/compilers/common/dirent.h
index 4c897cc550..bfba586093 100644
--- a/components/libc/compilers/dlib/dirent.h
+++ b/components/libc/compilers/common/dirent.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -10,7 +10,6 @@
#define __RTT_DIRENT_H__
#include <rtthread.h>
-#include <rtlibc.h>
/*
* dirent.h - format of directory entries
@@ -23,6 +22,10 @@
#define FT_DIRECTORY 2 /* directory */
#define FT_USER 3 /* user defined */
+#define DT_UNKNOWN 0x00
+#define DT_REG 0x01
+#define DT_DIR 0x02
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/components/libc/compilers/common/none-gcc/SConscript b/components/libc/compilers/common/none-gcc/SConscript
new file mode 100644
index 0000000000..c5838f8949
--- /dev/null
+++ b/components/libc/compilers/common/none-gcc/SConscript
@@ -0,0 +1,13 @@
+from building import *
+
+Import('rtconfig')
+
+src = []
+cwd = GetCurrentDir()
+CPPPATH = [cwd]
+group = []
+src += Glob('*.c')
+
+if rtconfig.PLATFORM != 'gcc' or rtconfig.ARCH == 'sim':
+ group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPPATH = CPPPATH)
+Return('group')
diff --git a/components/libc/compilers/armlibc/fcntl.h b/components/libc/compilers/common/none-gcc/fcntl.h
index 3e650a8471..f247b926e9 100644
--- a/components/libc/compilers/armlibc/fcntl.h
+++ b/components/libc/compilers/common/none-gcc/fcntl.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/common/none-gcc/readme.md b/components/libc/compilers/common/none-gcc/readme.md
new file mode 100644
index 0000000000..b10940d003
--- /dev/null
+++ b/components/libc/compilers/common/none-gcc/readme.md
@@ -0,0 +1,3 @@
+## Attentions
+
+This folder is "common" for toolchains excluding gcc. \ No newline at end of file
diff --git a/components/libc/compilers/armlibc/sys/stat.h b/components/libc/compilers/common/none-gcc/sys/stat.h
index ce95230e88..c4b42083c4 100644
--- a/components/libc/compilers/armlibc/sys/stat.h
+++ b/components/libc/compilers/common/none-gcc/sys/stat.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/armlibc/sys/types.h b/components/libc/compilers/common/none-gcc/sys/types.h
index 78fee1bb99..7222326a2a 100644
--- a/components/libc/compilers/armlibc/sys/types.h
+++ b/components/libc/compilers/common/none-gcc/sys/types.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -15,7 +15,11 @@
typedef int32_t clockid_t;
typedef int32_t key_t; /* Used for interprocess communication. */
-typedef int32_t pid_t; /* Used for process IDs and process group IDs. */
+typedef int pid_t; /* Used for process IDs and process group IDs. */
+typedef unsigned short uid_t;
+typedef unsigned short gid_t;
+typedef signed long off_t;
+typedef int mode_t;
#ifndef ARCH_CPU_64BIT
typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */
#else
@@ -23,4 +27,10 @@ typedef long signed int ssize_t; /* Used for a count of bytes or an error
#endif
typedef unsigned long useconds_t; /* microseconds (unsigned) */
+typedef unsigned long dev_t;
+
+typedef unsigned int u_int;
+typedef unsigned char u_char;
+typedef unsigned long u_long;
+
#endif
diff --git a/components/libc/compilers/armlibc/sys/unistd.h b/components/libc/compilers/common/none-gcc/sys/unistd.h
index 73a73a267e..2f01f660b3 100644
--- a/components/libc/compilers/armlibc/sys/unistd.h
+++ b/components/libc/compilers/common/none-gcc/sys/unistd.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -66,11 +66,16 @@
#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/armlibc/unistd.h b/components/libc/compilers/common/none-gcc/unistd.h
index 736fc219a8..cd77a12e3b 100644
--- a/components/libc/compilers/armlibc/unistd.h
+++ b/components/libc/compilers/common/none-gcc/unistd.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/common/readme.md b/components/libc/compilers/common/readme.md
index 99797d933c..856ddeb045 100644
--- a/components/libc/compilers/common/readme.md
+++ b/components/libc/compilers/common/readme.md
@@ -1,8 +1,8 @@
## Attentions
-1. This folder is "common" for armlibc newlibc and dlib. It's not "common" for minilibc.
+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:
+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:
diff --git a/components/libc/compilers/common/stdlib.c b/components/libc/compilers/common/stdlib.c
index b485bbd836..9d8952e99e 100644
--- a/components/libc/compilers/common/stdlib.c
+++ b/components/libc/compilers/common/stdlib.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -9,39 +9,18 @@
*/
#include <rtthread.h>
-#include <stdlib.h>
void __rt_libc_exit(int status)
{
rt_thread_t self = rt_thread_self();
-#ifdef RT_USING_MODULE
- if (dlmodule_self())
- {
- dlmodule_exit(status);
- }
-#endif
-
if (self != RT_NULL)
{
- if(status == EXIT_FAILURE) /* abort() */
- {
- rt_kprintf("thread:%s abort!\n", self->name);
- }
- else /* exit() */
- {
- rt_kprintf("thread:%s exit:%d!\n", self->name, status);
- }
- rt_thread_suspend(self);
- rt_schedule();
+ rt_kprintf("thread:%s exit:%d!\n", self->name, status);
+ rt_thread_control(self, RT_THREAD_CTRL_CLOSE, RT_NULL);
}
}
-void __rt_libc_abort(void)
-{
- __rt_libc_exit(EXIT_FAILURE);
-}
-
int __rt_libc_system(const char *string)
{
/* TODO */
diff --git a/components/libc/compilers/armlibc/sys/ioctl.h b/components/libc/compilers/common/sys/ioctl.h
index 033a57014a..648d90230d 100644
--- a/components/libc/compilers/armlibc/sys/ioctl.h
+++ b/components/libc/compilers/common/sys/ioctl.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -10,6 +10,9 @@
#ifndef _SYS_IOCTL_H
#define _SYS_IOCTL_H
-
+#include <rtconfig.h>
+#ifdef RT_USING_POSIX
+#include <dfs_posix.h>
+#endif
#endif
diff --git a/components/libc/compilers/newlib/sys/mman.h b/components/libc/compilers/common/sys/mman.h
index 8c61b32b7c..2da2ddf716 100644
--- a/components/libc/compilers/newlib/sys/mman.h
+++ b/components/libc/compilers/common/sys/mman.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -15,6 +15,8 @@
extern "C" {
#endif
+#include <sys/types.h>
+
#define MAP_FAILED ((void *) -1)
#define MAP_SHARED 0x01
diff --git a/components/libc/compilers/common/sys/statfs.h b/components/libc/compilers/common/sys/statfs.h
new file mode 100644
index 0000000000..0996af9a18
--- /dev/null
+++ b/components/libc/compilers/common/sys/statfs.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ */
+#ifndef __RTT_STATFS_H__
+#define __RTT_STATFS_H__
+
+#include <rtthread.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 */
+};
+
+#endif
diff --git a/components/libc/compilers/newlib/sys/termios.h b/components/libc/compilers/common/sys/termios.h
index ce95230e88..c4b42083c4 100644
--- a/components/libc/compilers/newlib/sys/termios.h
+++ b/components/libc/compilers/common/sys/termios.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, 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/sys/time.h
index 599b8b5262..bb1a9c96fd 100644
--- a/components/libc/compilers/common/sys/time.h
+++ b/components/libc/compilers/common/sys/time.h
@@ -1,28 +1,34 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 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_
+#include <rtconfig.h>
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
-/*
- * Skip define timespec for IAR version over 8.10.1 where __VER__ is 8010001.
- */
-#if defined ( __ICCARM__ ) && (__VER__ >= 8010001)
-#define _TIMESPEC_DEFINED
-#endif
-
+#define DST_NONE 0 /* not on dst */
+#define DST_USA 1 /* USA style dst */
+#define DST_AUST 2 /* Australian style dst */
+#define DST_WET 3 /* Western European dst */
+#define DST_MET 4 /* Middle European dst */
+#define DST_EET 5 /* Eastern European dst */
+#define DST_CAN 6 /* Canada */
+#define DST_GB 7 /* Great Britain and Eire */
+#define DST_RUM 8 /* Rumania */
+#define DST_TUR 9 /* Turkey */
+#define DST_AUSTALT 10 /* Australian style with shift in 1986 */
#ifndef _TIMEVAL_DEFINED
#define _TIMEVAL_DEFINED
@@ -30,13 +36,15 @@ extern "C" {
* 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 */
};
+#endif
#endif /* _TIMEVAL_DEFINED */
-#if !defined __GNUC__ && !defined __ICCARM__
+#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 */
@@ -52,6 +60,43 @@ int stime(const time_t *t);
time_t timegm(struct tm * const t);
int gettimeofday(struct timeval *tv, struct timezone *tz);
int settimeofday(const struct timeval *tv, const struct timezone *tz);
+#if defined(__ARMCC_VERSION) || defined (__ICCARM__)
+struct tm *gmtime_r(const time_t *timep, struct tm *r);
+#endif
+
+#ifdef RT_USING_POSIX
+#include <sys/types.h>
+/* posix clock and timer */
+#define MILLISECOND_PER_SECOND 1000UL
+#define MICROSECOND_PER_SECOND 1000000UL
+#define NANOSECOND_PER_SECOND 1000000000UL
+
+#define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND)
+#define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND)
+#define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND)
+
+#ifndef CLOCK_REALTIME
+#define CLOCK_REALTIME 1
+#endif
+
+#define CLOCK_CPUTIME_ID 2
+
+#ifndef CLOCK_PROCESS_CPUTIME_ID
+#define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID
+#endif
+#ifndef CLOCK_THREAD_CPUTIME_ID
+#define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID
+#endif
+
+#ifndef CLOCK_MONOTONIC
+#define CLOCK_MONOTONIC 4
+#endif
+
+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);
+#endif /* RT_USING_POSIX */
#ifdef __cplusplus
}
diff --git a/components/libc/compilers/common/termios.h b/components/libc/compilers/common/termios.h
index 414d0c0cb3..2960d52c58 100644
--- a/components/libc/compilers/common/termios.h
+++ b/components/libc/compilers/common/termios.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c
index a980f742fb..9996212444 100644
--- a/components/libc/compilers/common/time.c
+++ b/components/libc/compilers/common/time.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -12,21 +12,34 @@
* 2021-02-08 Meco Man add settimeofday() stime()
* 2021-02-10 Meco Man add ctime_r() and re-implement ctime()
* 2021-02-11 Meco Man fix bug #3183 - align days[] and months[] to 4 bytes
- * add difftime()
* 2021-02-12 Meco Man add errno
+ * 2012-12-08 Bernard <clock_time.c> fix the issue of _timevalue.tv_usec initialization,
+ * which found by Rob <[email protected]>
+ * 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
*/
-#include <sys/time.h>
+#include "sys/time.h"
#include <rtthread.h>
+
#ifdef RT_USING_DEVICE
#include <rtdevice.h>
#endif
+#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
/* days per month -- nonleap! */
-const short __spm[13] =
+static const short __spm[13] =
{
0,
(31),
@@ -60,6 +73,100 @@ static void num2str(char *c, int i)
c[1] = i % 10 + '0';
}
+/**
+ * Get time from RTC device (without timezone, UTC+0)
+ * @param tv: struct timeval
+ * @return the operation status, RT_EOK on successful
+ */
+static rt_err_t get_timeval(struct timeval *tv)
+{
+#ifdef RT_USING_RTC
+ static rt_device_t device = RT_NULL;
+ rt_err_t rst = -RT_ERROR;
+
+ if (tv == RT_NULL)
+ return -RT_EINVAL;
+
+ /* default is 0 */
+ tv->tv_sec = 0;
+ tv->tv_usec = 0;
+
+ /* optimization: find rtc device only first */
+ if (device == RT_NULL)
+ {
+ device = rt_device_find("rtc");
+ }
+
+ /* read timestamp from RTC device */
+ if (device != RT_NULL)
+ {
+ if (rt_device_open(device, 0) == RT_EOK)
+ {
+ 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_close(device);
+ }
+ }
+ else
+ {
+ /* LOG_W will cause a recursive printing if ulog timestamp function is enabled */
+ rt_kprintf("Cannot find a RTC device to provide time!\r\n");
+ return -RT_ENOSYS;
+ }
+
+ return rst;
+
+#else
+ /* LOG_W will cause a recursive printing if ulog timestamp function is enabled */
+ rt_kprintf("Cannot find a RTC device to provide time!\r\n");
+ return -RT_ENOSYS;
+#endif /* RT_USING_RTC */
+}
+
+/**
+ * Set time to RTC device (without timezone)
+ * @param tv: struct timeval
+ * @return the operation status, RT_EOK on successful
+ */
+static int set_timeval(struct timeval *tv)
+{
+#ifdef RT_USING_RTC
+ static rt_device_t device = RT_NULL;
+ rt_err_t rst = -RT_ERROR;
+
+ if (tv == RT_NULL)
+ return -RT_EINVAL;
+
+ /* optimization: find rtc device only first */
+ if (device == RT_NULL)
+ {
+ device = rt_device_find("rtc");
+ }
+
+ /* read timestamp from RTC device */
+ if (device != RT_NULL)
+ {
+ if (rt_device_open(device, 0) == RT_EOK)
+ {
+ 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_close(device);
+ }
+ }
+ else
+ {
+ LOG_W("Cannot find a RTC device to provide time!");
+ return -RT_ENOSYS;
+ }
+
+ return rst;
+
+#else
+ LOG_W("Cannot find a RTC device to provide time!");
+ return -RT_ENOSYS;
+#endif /* RT_USING_RTC */
+}
+
struct tm *gmtime_r(const time_t *timep, struct tm *r)
{
time_t i;
@@ -97,35 +204,40 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r)
r->tm_isdst = 0;
return r;
}
+RTM_EXPORT(gmtime_r);
struct tm* gmtime(const time_t* t)
{
static struct tm tmp;
return gmtime_r(t, &tmp);
}
+RTM_EXPORT(gmtime);
-/*TODO: timezone */
struct tm* localtime_r(const time_t* t, struct tm* r)
{
time_t local_tz;
- int utc_plus;
- utc_plus = 0; /* GTM: UTC+0 */
- local_tz = *t + utc_plus * 3600;
+ local_tz = *t + RT_LIBC_FIXED_TIMEZONE * 3600;
return gmtime_r(&local_tz, r);
}
+RTM_EXPORT(localtime_r);
struct tm* localtime(const time_t* t)
{
static struct tm tmp;
return localtime_r(t, &tmp);
}
+RTM_EXPORT(localtime);
-/* TODO: timezone */
time_t mktime(struct tm * const t)
{
- return timegm(t);
+ time_t timestamp;
+
+ timestamp = timegm(t);
+ timestamp = timestamp - 3600 * RT_LIBC_FIXED_TIMEZONE;
+ return timestamp;
}
+RTM_EXPORT(mktime);
char* asctime_r(const struct tm *t, char *buf)
{
@@ -145,107 +257,88 @@ char* asctime_r(const struct tm *t, char *buf)
num2str(buf + 20, (t->tm_year + 1900) / 100);
num2str(buf + 22, (t->tm_year + 1900) % 100);
buf[24] = '\n';
+ buf[25] = '\0';
return buf;
}
+RTM_EXPORT(asctime_r);
char* asctime(const struct tm *timeptr)
{
- static char buf[25];
+ static char buf[26];
return asctime_r(timeptr, buf);
}
+RTM_EXPORT(asctime);
-char *ctime_r (const time_t * tim_p, char * result)
+char *ctime_r(const time_t * tim_p, char * result)
{
struct tm tm;
- return asctime_r (localtime_r (tim_p, &tm), result);
+ return asctime_r(localtime_r(tim_p, &tm), result);
}
+RTM_EXPORT(ctime_r);
char* ctime(const time_t *tim_p)
{
- return asctime (localtime (tim_p));
-}
-
-double difftime (time_t tim1, time_t tim2)
-{
- return (double)(tim1 - tim2);
+ return asctime(localtime(tim_p));
}
+RTM_EXPORT(ctime);
/**
* Returns the current time.
*
* @param time_t * t the timestamp pointer, if not used, keep NULL.
*
- * @return The value ((time_t)-1) is returned if the calendar time is not available.
+ * @return The value ((time_t)-1) is returned if the calendar time is not available.
* If timer is not a NULL pointer, the return value is also stored in timer.
*
*/
RT_WEAK time_t time(time_t *t)
{
- time_t time_now = ((time_t)-1); /* default is not available */
+ struct timeval now;
-#ifdef RT_USING_RTC
- static rt_device_t device = RT_NULL;
-
- /* optimization: find rtc device only first */
- if (device == RT_NULL)
- {
- device = rt_device_find("rtc");
- }
-
- /* read timestamp from RTC device */
- if (device != RT_NULL)
+ if(get_timeval(&now) == RT_EOK)
{
- if (rt_device_open(device, 0) == RT_EOK)
+ if (t)
{
- rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now);
- rt_device_close(device);
+ *t = now.tv_sec;
}
+ return now.tv_sec;
}
-#endif /* RT_USING_RTC */
-
- /* if t is not NULL, write timestamp to *t */
- if (t != RT_NULL)
- {
- *t = time_now;
- }
-
- if(time_now == (time_t)-1)
+ else
{
- errno = ENOSYS;
+ rt_set_errno(EFAULT);
+ return ((time_t)-1);
}
-
- return time_now;
}
+RTM_EXPORT(time);
RT_WEAK clock_t clock(void)
{
return rt_tick_get();
}
+RTM_EXPORT(clock);
int stime(const time_t *t)
{
-#ifdef RT_USING_RTC
- rt_device_t device;
+ struct timeval tv;
- /* read timestamp from RTC device. */
- device = rt_device_find("rtc");
- if (rt_device_open(device, 0) == RT_EOK)
+ if (!t)
+ {
+ rt_set_errno(EFAULT);
+ return -1;
+ }
+
+ tv.tv_sec = *t;
+ if (set_timeval(&tv) == RT_EOK)
{
- rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, (void*)t);
- rt_device_close(device);
+ return 0;
}
else
{
- errno = ENOSYS;
+ rt_set_errno(EFAULT);
return -1;
}
- return 0;
-
-#else
- errno = ENOSYS;
- return -1;
-#endif /* RT_USING_RTC */
}
+RTM_EXPORT(stime);
time_t timegm(struct tm * const t)
{
@@ -320,35 +413,231 @@ time_t timegm(struct tm * const t)
i = 60;
return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec;
}
+RTM_EXPORT(timegm);
-/* TODO: timezone */
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
- time_t t = time(RT_NULL);
+ /* The use of the timezone structure is obsolete;
+ * the tz argument should normally be specified as NULL.
+ * The tz_dsttime field has never been used under Linux.
+ * Thus, the following is purely of historic interest.
+ */
+ if(tz != RT_NULL)
+ {
+ tz->tz_dsttime = DST_NONE;
+ tz->tz_minuteswest = -(RT_LIBC_FIXED_TIMEZONE * 60);
+ }
- if (tv != RT_NULL && t != (time_t)-1)
+ if (tv != RT_NULL && get_timeval(tv) == RT_EOK)
{
- tv->tv_sec = t;
- tv->tv_usec = 0;
return 0;
}
else
{
- errno = ENOSYS;
+ rt_set_errno(EFAULT);
return -1;
}
}
+RTM_EXPORT(gettimeofday);
-/* TODO: timezone */
int settimeofday(const struct timeval *tv, const struct timezone *tz)
{
- if (tv != RT_NULL)
+ /* The use of the timezone structure is obsolete;
+ * the tz argument should normally be specified as NULL.
+ * The tz_dsttime field has never been used under Linux.
+ * 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)
{
- return stime((const time_t *)&tv->tv_sec);
+ return 0;
}
else
{
- errno = ENOSYS;
+ rt_set_errno(EINVAL);
+ return -1;
+ }
+}
+RTM_EXPORT(settimeofday);
+
+/* inherent in the toolchain */
+RTM_EXPORT(difftime);
+RTM_EXPORT(strftime);
+
+#ifdef RT_USING_POSIX
+static struct timeval _timevalue;
+static int clock_time_system_init()
+{
+ time_t time;
+ rt_tick_t tick;
+ rt_device_t device;
+
+ time = 0;
+ device = rt_device_find("rtc");
+ if (device != RT_NULL)
+ {
+ /* get realtime seconds */
+ rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
+ }
+
+ /* get tick */
+ tick = rt_tick_get();
+
+ _timevalue.tv_usec = (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK;
+ _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1;
+
+ return 0;
+}
+INIT_COMPONENT_EXPORT(clock_time_system_init);
+
+int clock_getres(clockid_t clockid, struct timespec *res)
+{
+ int ret = 0;
+
+ if (res == RT_NULL)
+ {
+ rt_set_errno(EINVAL);
+ return -1;
+ }
+
+ switch (clockid)
+ {
+ case CLOCK_REALTIME:
+ res->tv_sec = 0;
+ res->tv_nsec = NANOSECOND_PER_SECOND/RT_TICK_PER_SECOND;
+ break;
+
+#ifdef RT_USING_CPUTIME
+ case CLOCK_CPUTIME_ID:
+ res->tv_sec = 0;
+ res->tv_nsec = clock_cpu_getres();
+ break;
+#endif
+
+ default:
+ ret = -1;
+ rt_set_errno(EINVAL);
+ break;
+ }
+
+ return ret;
+}
+RTM_EXPORT(clock_getres);
+
+int clock_gettime(clockid_t clockid, struct timespec *tp)
+{
+ int ret = 0;
+
+ if (tp == RT_NULL)
+ {
+ rt_set_errno(EINVAL);
+ return -1;
+ }
+
+ switch (clockid)
+ {
+ case CLOCK_REALTIME:
+ {
+ /* get tick */
+ int tick = rt_tick_get();
+
+ 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;
+ }
+ break;
+
+#ifdef RT_USING_CPUTIME
+ case CLOCK_CPUTIME_ID:
+ {
+ float unit = 0;
+ long long cpu_tick;
+
+ unit = clock_cpu_getres();
+ cpu_tick = clock_cpu_gettime();
+
+ tp->tv_sec = ((int)(cpu_tick * unit)) / NANOSECOND_PER_SECOND;
+ tp->tv_nsec = ((int)(cpu_tick * unit)) % NANOSECOND_PER_SECOND;
+ }
+ break;
+#endif
+ default:
+ rt_set_errno(EINVAL);
+ ret = -1;
+ }
+
+ return ret;
+}
+RTM_EXPORT(clock_gettime);
+
+int clock_settime(clockid_t clockid, const struct timespec *tp)
+{
+ int second;
+ rt_tick_t tick;
+ rt_device_t device;
+
+ 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();
+
+ /* 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;
+
+ /* 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);
+ }
+ else
+ return -1;
+
+ return 0;
}
+RTM_EXPORT(clock_settime);
+
+int clock_time_to_tick(const struct timespec *time)
+{
+ int tick;
+ int nsecond, second;
+ struct timespec tp;
+
+ RT_ASSERT(time != RT_NULL);
+
+ tick = RT_WAITING_FOREVER;
+ if (time != NULL)
+ {
+ /* get current tp */
+ clock_gettime(CLOCK_REALTIME, &tp);
+
+ if ((time->tv_nsec - tp.tv_nsec) < 0)
+ {
+ nsecond = NANOSECOND_PER_SECOND - (tp.tv_nsec - time->tv_nsec);
+ second = time->tv_sec - tp.tv_sec - 1;
+ }
+ else
+ {
+ nsecond = time->tv_nsec - tp.tv_nsec;
+ second = time->tv_sec - tp.tv_sec;
+ }
+
+ tick = second * RT_TICK_PER_SECOND + nsecond * RT_TICK_PER_SECOND / NANOSECOND_PER_SECOND;
+ if (tick < 0) tick = 0;
+ }
+
+ return tick;
+}
+RTM_EXPORT(clock_time_to_tick);
+
+#endif /* RT_USING_POSIX */
diff --git a/components/libc/compilers/common/unistd.c b/components/libc/compilers/common/unistd.c
index df970b2b59..6c81fc7662 100644
--- a/components/libc/compilers/common/unistd.c
+++ b/components/libc/compilers/common/unistd.c
@@ -1,26 +1,104 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * 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
+ * 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)*/
+ 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/tty0"; /*TODO: need to add more specific*/
+ return "/dev/tty"; /*TODO: need to add more specific*/
+}
+RTM_EXPORT(ttyname);
+
+unsigned int sleep(unsigned int seconds)
+{
+ rt_tick_t delta_tick;
+
+ delta_tick = rt_tick_get();
+ rt_thread_delay(seconds * RT_TICK_PER_SECOND);
+ delta_tick = rt_tick_get() - delta_tick;
+
+ return seconds - delta_tick/RT_TICK_PER_SECOND;
+}
+RTM_EXPORT(sleep);
+
+int usleep(useconds_t usec)
+{
+ rt_thread_mdelay(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/environ.c b/components/libc/compilers/dlib/environ.c
index ac19758838..84b04fda55 100644
--- a/components/libc/compilers/dlib/environ.c
+++ b/components/libc/compilers/dlib/environ.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/dlib/fcntl.h b/components/libc/compilers/dlib/fcntl.h
deleted file mode 100644
index ce95230e88..0000000000
--- a/components/libc/compilers/dlib/fcntl.h
+++ /dev/null
@@ -1,8 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
diff --git a/components/libc/compilers/dlib/libc.c b/components/libc/compilers/dlib/libc.c
index 8b42411a6b..d0dca7c5f6 100644
--- a/components/libc/compilers/dlib/libc.c
+++ b/components/libc/compilers/dlib/libc.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/dlib/libc.h b/components/libc/compilers/dlib/libc.h
index 5b46bee0c8..fc3cafca78 100644
--- a/components/libc/compilers/dlib/libc.h
+++ b/components/libc/compilers/dlib/libc.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/dlib/rmtx.c b/components/libc/compilers/dlib/rmtx.c
deleted file mode 100644
index 69405c8f6a..0000000000
--- a/components/libc/compilers/dlib/rmtx.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2015-01-28 Bernard first version
- */
-#include <rtthread.h>
-#include <yfuns.h>
-
-/*
- * for IAR compiler, we recommand to define _DLIB_THREAD_SUPPORT
- * as 2 for dlib multi-thread support.
- */
-
-#if _DLIB_THREAD_SUPPORT
-typedef void* _Rmtx;
-void _Mtxinit(_Rmtx *m)
-{
- rt_mutex_t mutex;
-
- RT_ASSERT(m != RT_NULL);
-
- mutex = (rt_mutex_t)m;
- rt_mutex_init(mutex, "iarMtx", RT_IPC_FLAG_FIFO);
-}
-
-void _Mtxdst(_Rmtx *m)
-{
- rt_mutex_t mutex;
-
- RT_ASSERT(m != RT_NULL);
-
- mutex = (rt_mutex_t)m;
- rt_mutex_detach(mutex);
-}
-
-void _Mtxlock(_Rmtx *m)
-{
- rt_mutex_t mutex;
-
- RT_ASSERT(m != RT_NULL);
-
- mutex = (rt_mutex_t)m;
- rt_mutex_take(mutex, RT_WAITING_FOREVER);
-}
-
-void _Mtxunlock(_Rmtx *m)
-{
- rt_mutex_t mutex;
-
- RT_ASSERT(m != RT_NULL);
-
- mutex = (rt_mutex_t)m;
- rt_mutex_release(mutex);
-}
-#endif
-
diff --git a/components/libc/compilers/dlib/stdio.c b/components/libc/compilers/dlib/stdio.c
index b35ade7a38..c11157d759 100644
--- a/components/libc/compilers/dlib/stdio.c
+++ b/components/libc/compilers/dlib/stdio.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/dlib/sys/README.md b/components/libc/compilers/dlib/sys/README.md
deleted file mode 100644
index 4f0d203180..0000000000
--- a/components/libc/compilers/dlib/sys/README.md
+++ /dev/null
@@ -1 +0,0 @@
-Because IAR leaks some system header file, we put them in here. \ No newline at end of file
diff --git a/components/libc/compilers/dlib/sys/errno.h b/components/libc/compilers/dlib/sys/errno.h
deleted file mode 100644
index 1ad4c8acc0..0000000000
--- a/components/libc/compilers/dlib/sys/errno.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2019-07-08 Bernard The first version
- */
-
-#ifndef SYS_ERRNO_H__
-#define SYS_ERRNO_H__
-
-#include <errno.h>
-
-#endif
diff --git a/components/libc/compilers/dlib/sys/mman.h b/components/libc/compilers/dlib/sys/mman.h
deleted file mode 100644
index 8c61b32b7c..0000000000
--- a/components/libc/compilers/dlib/sys/mman.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/11/30 Bernard The first version.
- */
-
-#ifndef _SYS_MMAN_H
-#define _SYS_MMAN_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MAP_FAILED ((void *) -1)
-
-#define MAP_SHARED 0x01
-#define MAP_PRIVATE 0x02
-#define MAP_TYPE 0x0f
-#define MAP_FIXED 0x10
-#define MAP_ANON 0x20
-#define MAP_ANONYMOUS MAP_ANON
-#define MAP_NORESERVE 0x4000
-#define MAP_GROWSDOWN 0x0100
-#define MAP_DENYWRITE 0x0800
-#define MAP_EXECUTABLE 0x1000
-#define MAP_LOCKED 0x2000
-#define MAP_POPULATE 0x8000
-#define MAP_NONBLOCK 0x10000
-#define MAP_STACK 0x20000
-#define MAP_HUGETLB 0x40000
-#define MAP_FILE 0
-
-#define PROT_NONE 0
-#define PROT_READ 1
-#define PROT_WRITE 2
-#define PROT_EXEC 4
-#define PROT_GROWSDOWN 0x01000000
-#define PROT_GROWSUP 0x02000000
-
-#define MS_ASYNC 1
-#define MS_INVALIDATE 2
-#define MS_SYNC 4
-
-#define MCL_CURRENT 1
-#define MCL_FUTURE 2
-#define MCL_ONFAULT 4
-
-void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off);
-int munmap (void *start, size_t len);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/components/libc/compilers/dlib/sys/signal.h b/components/libc/compilers/dlib/sys/signal.h
deleted file mode 100644
index 22adb1228b..0000000000
--- a/components/libc/compilers/dlib/sys/signal.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2019-07-08 Bernard The first version
- */
-
-#ifndef SYS_SIGNAL_H__
-#define SYS_SIGNAL_H__
-
-#include <libc/libc_signal.h>
-
-#endif
diff --git a/components/libc/compilers/dlib/sys/stat.h b/components/libc/compilers/dlib/sys/stat.h
deleted file mode 100644
index ce95230e88..0000000000
--- a/components/libc/compilers/dlib/sys/stat.h
+++ /dev/null
@@ -1,8 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
diff --git a/components/libc/compilers/dlib/sys/types.h b/components/libc/compilers/dlib/sys/types.h
deleted file mode 100644
index 7dbeddcaa9..0000000000
--- a/components/libc/compilers/dlib/sys/types.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2020-12-16 Meco Man add useconds_t
- */
-#ifndef __TYPES_H__
-#define __TYPES_H__
-
-#include <stdint.h>
-
-typedef int32_t clockid_t;
-typedef int32_t key_t; /* Used for interprocess communication. */
-typedef int32_t pid_t; /* Used for process IDs and process group IDs. */
-#ifndef ARCH_CPU_64BIT
-typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */
-#else
-typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */
-#endif
-typedef unsigned long useconds_t; /* microseconds (unsigned) */
-
-#endif
diff --git a/components/libc/compilers/dlib/sys/unistd.h b/components/libc/compilers/dlib/sys/unistd.h
deleted file mode 100644
index 6d99cd6c55..0000000000
--- a/components/libc/compilers/dlib/sys/unistd.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2006-2018, 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 */
-
-#endif
-
-
-int isatty (int fd);
-char * ttyname (int desc);
-
-unsigned int sleep(unsigned int seconds);
-int usleep(useconds_t usec);
-
-#endif /* _SYS_UNISTD_H */
diff --git a/components/libc/compilers/dlib/syscall_close.c b/components/libc/compilers/dlib/syscall_close.c
index f46162deb7..7ed1cc2f2d 100644
--- a/components/libc/compilers/dlib/syscall_close.c
+++ b/components/libc/compilers/dlib/syscall_close.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/dlib/syscall_lseek.c b/components/libc/compilers/dlib/syscall_lseek.c
index b79cc410b7..47a069bf0a 100644
--- a/components/libc/compilers/dlib/syscall_lseek.c
+++ b/components/libc/compilers/dlib/syscall_lseek.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/dlib/syscall_mem.c b/components/libc/compilers/dlib/syscall_mem.c
index 236ef1c12d..9c6de64455 100644
--- a/components/libc/compilers/dlib/syscall_mem.c
+++ b/components/libc/compilers/dlib/syscall_mem.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/dlib/syscall_open.c b/components/libc/compilers/dlib/syscall_open.c
index 96e02dc32a..37bfcecb47 100644
--- a/components/libc/compilers/dlib/syscall_open.c
+++ b/components/libc/compilers/dlib/syscall_open.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c
index e248211486..afb661bd93 100644
--- a/components/libc/compilers/dlib/syscall_read.c
+++ b/components/libc/compilers/dlib/syscall_read.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/dlib/syscall_remove.c b/components/libc/compilers/dlib/syscall_remove.c
index f7e64d1997..7d74236f4c 100644
--- a/components/libc/compilers/dlib/syscall_remove.c
+++ b/components/libc/compilers/dlib/syscall_remove.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c
index 85c0da22c3..de464530b8 100644
--- a/components/libc/compilers/dlib/syscall_write.c
+++ b/components/libc/compilers/dlib/syscall_write.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/dlib/syscalls.c b/components/libc/compilers/dlib/syscalls.c
index 10155948ba..e1c9562b3a 100644
--- a/components/libc/compilers/dlib/syscalls.c
+++ b/components/libc/compilers/dlib/syscalls.c
@@ -1,24 +1,25 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-02-13 Meco Man implement exit() and abort()
+ * 2021-02-20 Meco Man add system()
*/
#include <rtthread.h>
-void exit (int status)
+/* for exit() and abort() */
+void __exit (int status)
{
extern void __rt_libc_exit(int status);
__rt_libc_exit(status);
while(1);
}
-void abort(void)
+int system(const char * string)
{
- extern void __rt_libc_abort(void);
- __rt_libc_abort();
- while(1);
+ extern int __rt_libc_system(const char *string);
+ return __rt_libc_system(string);
}
diff --git a/components/libc/compilers/dlib/unistd.h b/components/libc/compilers/dlib/unistd.h
deleted file mode 100644
index a07d8409c2..0000000000
--- a/components/libc/compilers/dlib/unistd.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef _UNISTD_H_
-#define _UNISTD_H_
-
-# include "sys/unistd.h"
-
-#endif /* _UNISTD_H_ */
diff --git a/components/libc/compilers/minilibc/SConscript b/components/libc/compilers/minilibc/SConscript
deleted file mode 100644
index dec657028f..0000000000
--- a/components/libc/compilers/minilibc/SConscript
+++ /dev/null
@@ -1,15 +0,0 @@
-from building import *
-Import('rtconfig')
-
-src = Glob('*.c') + Glob('*.cpp')
-cwd = GetCurrentDir()
-group = []
-
-CPPPATH = [cwd]
-CPPDEFINES = ['RT_USING_MINILIBC']
-
-if rtconfig.PLATFORM == 'gcc' and rtconfig.ARCH != 'sim' and not GetDepend('RT_USING_LIBC') and GetDepend('RT_USING_MINILIBC'):
- group = DefineGroup('libc', src, depend = [''],
- CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
-
-Return('group')
diff --git a/components/libc/compilers/minilibc/ctype.c b/components/libc/compilers/minilibc/ctype.c
deleted file mode 100644
index b94ff2dae8..0000000000
--- a/components/libc/compilers/minilibc/ctype.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2008-08-14 Bernard the first version
- */
-
-#include <rtthread.h>
-#include <sys/types.h>
-
-#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
-#include "ctype.h"
-
-int isprint (int ch)
-{
- ch&=0x7f;
- return (ch>=32 && ch<127);
-}
-
-int isalpha(int ch)
-{
- return (unsigned int)((ch | 0x20) - 'a') < 26u;
-}
-
-int isdigit (int ch)
-{
- return (unsigned int)(ch - '0') < 10u;
-}
-
-int isspace(int ch)
-{
- switch(ch)
- {
- case ' ':
- case '\n':
- case '\f':
- case '\r':
- case '\t':
- case '\v':
- return 1;
- default:
- return 0;
- }
-}
-
-#endif
diff --git a/components/libc/compilers/minilibc/ctype.h b/components/libc/compilers/minilibc/ctype.h
deleted file mode 100644
index 5f41376ed8..0000000000
--- a/components/libc/compilers/minilibc/ctype.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2008-08-14 Bernard the first version
- */
-#ifndef __CTYPE_H__
-#define __CTYPE_H__
-
-int isprint(int c) __attribute__ ((__const__));
-int isalpha (int c) __attribute__ ((__const__));
-int isdigit (int ch) __attribute__ ((__const__));
-int isspace(int ch) __attribute__ ((__const__));
-
-#endif
diff --git a/components/libc/compilers/minilibc/errno.h b/components/libc/compilers/minilibc/errno.h
deleted file mode 100644
index a7ee380594..0000000000
--- a/components/libc/compilers/minilibc/errno.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __ERRNO_H__
-#define __ERRNO_H__
-
-#include "libc/libc_errno.h"
-/* Others defined in libc/libc_errno.h */
-#define ENSRNOTFOUND 163 /* Domain name not found */
-
-#endif
diff --git a/components/libc/compilers/minilibc/inttypes.h b/components/libc/compilers/minilibc/inttypes.h
deleted file mode 100644
index 8bab743655..0000000000
--- a/components/libc/compilers/minilibc/inttypes.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __INTTYPES_H__
-#define __INTTYPES_H__
-
-#include "stdint.h"
-
-#endif
diff --git a/components/libc/compilers/minilibc/math.c b/components/libc/compilers/minilibc/math.c
deleted file mode 100644
index cd5770178e..0000000000
--- a/components/libc/compilers/minilibc/math.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#include <math.h>
-
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS CRT
- * FILE: lib/crt/math/cos.c
- * PURPOSE: Generic C Implementation of cos
- * PROGRAMMER: Timo Kreuzer ([email protected])
- */
-
-#define PRECISION 9
-
-static double cos_off_tbl[] = {0.0, -M_PI/2., 0, -M_PI/2.};
-static double cos_sign_tbl[] = {1,-1,-1,1};
-
-static double sin_off_tbl[] = {0.0, -M_PI/2., 0, -M_PI/2.};
-static double sin_sign_tbl[] = {1,-1,-1,1};
-
-double sin(double x)
-{
- int quadrant;
- double x2, result;
-
- /* Calculate the quadrant */
- quadrant = x * (2./M_PI);
-
- /* Get offset inside quadrant */
- x = x - quadrant * (M_PI/2.);
-
- /* Normalize quadrant to [0..3] */
- quadrant = (quadrant - 1) & 0x3;
-
- /* Fixup value for the generic function */
- x += sin_off_tbl[quadrant];
-
- /* Calculate the negative of the square of x */
- x2 = - (x * x);
-
- /* This is an unrolled taylor series using <PRECISION> iterations
- * Example with 4 iterations:
- * result = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8!
- * To save multiplications and to keep the precision high, it's performed
- * like this:
- * result = 1 - x^2 * (1/2! - x^2 * (1/4! - x^2 * (1/6! - x^2 * (1/8!))))
- */
-
- /* Start with 0, compiler will optimize this away */
- result = 0;
-
-#if (PRECISION >= 10)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20);
- result *= x2;
-#endif
-#if (PRECISION >= 9)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18);
- result *= x2;
-#endif
-#if (PRECISION >= 8)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16);
- result *= x2;
-#endif
-#if (PRECISION >= 7)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14);
- result *= x2;
-#endif
-#if (PRECISION >= 6)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12);
- result *= x2;
-#endif
-#if (PRECISION >= 5)
- result += 1./(1.*2*3*4*5*6*7*8*9*10);
- result *= x2;
-#endif
- result += 1./(1.*2*3*4*5*6*7*8);
- result *= x2;
-
- result += 1./(1.*2*3*4*5*6);
- result *= x2;
-
- result += 1./(1.*2*3*4);
- result *= x2;
-
- result += 1./(1.*2);
- result *= x2;
-
- result += 1;
-
- /* Apply correct sign */
- result *= sin_sign_tbl[quadrant];
-
- return result;
-}
-
-double cos(double x)
-{
- int quadrant;
- double x2, result;
-
- /* Calculate the quadrant */
- quadrant = x * (2./M_PI);
-
- /* Get offset inside quadrant */
- x = x - quadrant * (M_PI/2.);
-
- /* Normalize quadrant to [0..3] */
- quadrant = quadrant & 0x3;
-
- /* Fixup value for the generic function */
- x += cos_off_tbl[quadrant];
-
- /* Calculate the negative of the square of x */
- x2 = - (x * x);
-
- /* This is an unrolled taylor series using <PRECISION> iterations
- * Example with 4 iterations:
- * result = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8!
- * To save multiplications and to keep the precision high, it's performed
- * like this:
- * result = 1 - x^2 * (1/2! - x^2 * (1/4! - x^2 * (1/6! - x^2 * (1/8!))))
- */
-
- /* Start with 0, compiler will optimize this away */
- result = 0;
-
-#if (PRECISION >= 10)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20);
- result *= x2;
-#endif
-#if (PRECISION >= 9)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18);
- result *= x2;
-#endif
-#if (PRECISION >= 8)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16);
- result *= x2;
-#endif
-#if (PRECISION >= 7)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14);
- result *= x2;
-#endif
-#if (PRECISION >= 6)
- result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12);
- result *= x2;
-#endif
-#if (PRECISION >= 5)
- result += 1./(1.*2*3*4*5*6*7*8*9*10);
- result *= x2;
-#endif
- result += 1./(1.*2*3*4*5*6*7*8);
- result *= x2;
-
- result += 1./(1.*2*3*4*5*6);
- result *= x2;
-
- result += 1./(1.*2*3*4);
- result *= x2;
-
- result += 1./(1.*2);
- result *= x2;
-
- result += 1;
-
- /* Apply correct sign */
- result *= cos_sign_tbl[quadrant];
-
- return result;
-}
-
diff --git a/components/libc/compilers/minilibc/math.h b/components/libc/compilers/minilibc/math.h
deleted file mode 100644
index 49b80d8219..0000000000
--- a/components/libc/compilers/minilibc/math.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __MATH_H__
-#define __MATH_H__
-
-#define M_PI 3.141592653589793238462643
-
-double sin(double x);
-double cos(double x);
-
-typedef float float_t;
-typedef double double_t;
-
-#endif
diff --git a/components/libc/compilers/minilibc/qsort.c b/components/libc/compilers/minilibc/qsort.c
deleted file mode 100644
index 2b97ce763c..0000000000
--- a/components/libc/compilers/minilibc/qsort.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#include <sys/types.h>
-#include <stdlib.h>
-
-static void exch(char* base,size_t size,size_t a,size_t b) {
- char* x=base+a*size;
- char* y=base+b*size;
- while (size) {
- char z=*x;
- *x=*y;
- *y=z;
- --size; ++x; ++y;
- }
-}
-
-/* Quicksort with 3-way partitioning, ala Sedgewick */
-/* Blame him for the scary variable names */
-/* http://www.cs.princeton.edu/~rs/talks/QuicksortIsOptimal.pdf */
-static void quicksort(char* base,size_t size,ssize_t l,ssize_t r,
- int (*compar)(const void*,const void*)) {
- ssize_t i=l-1, j=r, p=l-1, q=r, k;
- char* v=base+r*size;
- if (r<=l) return;
- for (;;) {
- while (++i != r && compar(base+i*size,v)<0) ;
- while (compar(v,base+(--j)*size)<0) if (j == l) break;
- if (i >= j) break;
- exch(base,size,i,j);
- if (compar(base+i*size,v)==0) exch(base,size,++p,i);
- if (compar(v,base+j*size)==0) exch(base,size,j,--q);
- }
- exch(base,size,i,r); j = i-1; ++i;
- for (k=l; k<p; k++, j--) exch(base,size,k,j);
- for (k=r-1; k>q; k--, i++) exch(base,size,i,k);
- quicksort(base,size,l,j,compar);
- quicksort(base,size,i,r,compar);
-}
-
-void qsort(void* base,size_t nmemb,size_t size,int (*compar)(const void*,const void*)) {
- /* check for integer overflows */
- if (nmemb >= (((size_t)-1)>>1) ||
- size >= (((size_t)-1)>>1)) return;
- if (nmemb>1)
- quicksort(base,size,0,nmemb-1,compar);
-}
diff --git a/components/libc/compilers/minilibc/rand.c b/components/libc/compilers/minilibc/rand.c
deleted file mode 100644
index 88603dc808..0000000000
--- a/components/libc/compilers/minilibc/rand.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#include <stdlib.h>
-#include <stdint.h>
-#include <sys/types.h>
-
-static unsigned int _seed=1;
-
-/* Knuth's TAOCP section 3.6 */
-#define M ((1U<<31) -1)
-#define A 48271
-#define Q 44488 // M/A
-#define R 3399 // M%A; R < Q !!!
-
-int rand_r(unsigned int* seed)
-{ int32_t X;
-
- X = *seed;
- X = A*(X%Q) - R * (int32_t) (X/Q);
- if (X < 0)
- X += M;
-
- *seed = X;
- return X;
-}
-
-int rand(void) {
- return rand_r(&_seed);
-}
-
-void srand(unsigned int i)
-{
- _seed=i;
-}
-
-int random(void) __attribute__((alias("rand")));
-void srandom(unsigned int i) __attribute__((alias("srand")));
diff --git a/components/libc/compilers/minilibc/signal.h b/components/libc/compilers/minilibc/signal.h
deleted file mode 100644
index f52f1e1009..0000000000
--- a/components/libc/compilers/minilibc/signal.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017-09-12 Bernard The first version
- */
-
-#ifndef SIGNAL_H__
-#define SIGNAL_H__
-
-#include <libc/libc_signal.h>
-
-#define SIG_DFL ((_sig_func_ptr)0) /* Default action */
-#define SIG_IGN ((_sig_func_ptr)1) /* Ignore action */
-#define SIG_ERR ((_sig_func_ptr)-1) /* Error return */
-
-#endif
diff --git a/components/libc/compilers/minilibc/stddef.h b/components/libc/compilers/minilibc/stddef.h
deleted file mode 100644
index 7353a157cb..0000000000
--- a/components/libc/compilers/minilibc/stddef.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __STDDEF_H__
-#define __STDDEF_H__
-
-#include <sys/types.h>
-typedef signed long ptrdiff_t;
-
-#endif
diff --git a/components/libc/compilers/minilibc/stdint.h b/components/libc/compilers/minilibc/stdint.h
deleted file mode 100644
index bd5fdc83f5..0000000000
--- a/components/libc/compilers/minilibc/stdint.h
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-/*
- * ISO C Standard: 7.18 Integer types <stdint.h>
- */
-
-#ifndef __STDINT_H__
-#define __STDINT_H__
-
-/* 7.8.1.1 Exact-width integer types */
-
-#ifdef __INT8_TYPE__
-typedef __INT8_TYPE__ int8_t;
-#endif
-#ifdef __INT16_TYPE__
-typedef __INT16_TYPE__ int16_t;
-#endif
-#ifdef __INT32_TYPE__
-typedef __INT32_TYPE__ int32_t;
-#endif
-#ifdef __INT64_TYPE__
-typedef __INT64_TYPE__ int64_t;
-#endif
-#ifdef __UINT8_TYPE__
-typedef __UINT8_TYPE__ uint8_t;
-#endif
-#ifdef __UINT16_TYPE__
-typedef __UINT16_TYPE__ uint16_t;
-#endif
-#ifdef __UINT32_TYPE__
-typedef __UINT32_TYPE__ uint32_t;
-#endif
-#ifdef __UINT64_TYPE__
-typedef __UINT64_TYPE__ uint64_t;
-#endif
-
-/* 7.8.1.2 Minimum-width integer types */
-
-typedef __INT_LEAST8_TYPE__ int_least8_t;
-typedef __INT_LEAST16_TYPE__ int_least16_t;
-typedef __INT_LEAST32_TYPE__ int_least32_t;
-typedef __INT_LEAST64_TYPE__ int_least64_t;
-typedef __UINT_LEAST8_TYPE__ uint_least8_t;
-typedef __UINT_LEAST16_TYPE__ uint_least16_t;
-typedef __UINT_LEAST32_TYPE__ uint_least32_t;
-typedef __UINT_LEAST64_TYPE__ uint_least64_t;
-
-/* 7.8.1.3 Fastest minimum-width integer types */
-
-typedef __INT_FAST8_TYPE__ int_fast8_t;
-typedef __INT_FAST16_TYPE__ int_fast16_t;
-typedef __INT_FAST32_TYPE__ int_fast32_t;
-typedef __INT_FAST64_TYPE__ int_fast64_t;
-typedef __UINT_FAST8_TYPE__ uint_fast8_t;
-typedef __UINT_FAST16_TYPE__ uint_fast16_t;
-typedef __UINT_FAST32_TYPE__ uint_fast32_t;
-typedef __UINT_FAST64_TYPE__ uint_fast64_t;
-
-/* 7.8.1.4 Integer types capable of holding object pointers */
-
-#ifdef __INTPTR_TYPE__
-typedef __INTPTR_TYPE__ intptr_t;
-#endif
-#ifdef __UINTPTR_TYPE__
-typedef __UINTPTR_TYPE__ uintptr_t;
-#endif
-
-/* 7.8.1.5 Greatest-width integer types */
-
-typedef __INTMAX_TYPE__ intmax_t;
-typedef __UINTMAX_TYPE__ uintmax_t;
-
-#if (!defined __cplusplus || __cplusplus >= 201103L \
- || defined __STDC_LIMIT_MACROS)
-
-/*
- * 7.18.2 Limits of specified-width integer types.
- *
- * The following object-like macros specify the minimum and maximum limits
- * of integer types corresponding to the typedef names defined above.
- */
-
-/* 7.18.2.1 Limits of exact-width integer types */
-
-#ifdef __INT8_MAX__
-# undef INT8_MAX
-# define INT8_MAX __INT8_MAX__
-# undef INT8_MIN
-# define INT8_MIN (-INT8_MAX - 1)
-#endif
-#ifdef __UINT8_MAX__
-# undef UINT8_MAX
-# define UINT8_MAX __UINT8_MAX__
-#endif
-#ifdef __INT16_MAX__
-# undef INT16_MAX
-# define INT16_MAX __INT16_MAX__
-# undef INT16_MIN
-# define INT16_MIN (-INT16_MAX - 1)
-#endif
-#ifdef __UINT16_MAX__
-# undef UINT16_MAX
-# define UINT16_MAX __UINT16_MAX__
-#endif
-#ifdef __INT32_MAX__
-# undef INT32_MAX
-# define INT32_MAX __INT32_MAX__
-# undef INT32_MIN
-# define INT32_MIN (-INT32_MAX - 1)
-#endif
-#ifdef __UINT32_MAX__
-# undef UINT32_MAX
-# define UINT32_MAX __UINT32_MAX__
-#endif
-#ifdef __INT64_MAX__
-# undef INT64_MAX
-# define INT64_MAX __INT64_MAX__
-# undef INT64_MIN
-# define INT64_MIN (-INT64_MAX - 1)
-#endif
-#ifdef __UINT64_MAX__
-# undef UINT64_MAX
-# define UINT64_MAX __UINT64_MAX__
-#endif
-
-#undef INT_LEAST8_MAX
-#define INT_LEAST8_MAX __INT_LEAST8_MAX__
-#undef INT_LEAST8_MIN
-#define INT_LEAST8_MIN (-INT_LEAST8_MAX - 1)
-#undef UINT_LEAST8_MAX
-#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__
-#undef INT_LEAST16_MAX
-#define INT_LEAST16_MAX __INT_LEAST16_MAX__
-#undef INT_LEAST16_MIN
-#define INT_LEAST16_MIN (-INT_LEAST16_MAX - 1)
-#undef UINT_LEAST16_MAX
-#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
-#undef INT_LEAST32_MAX
-#define INT_LEAST32_MAX __INT_LEAST32_MAX__
-#undef INT_LEAST32_MIN
-#define INT_LEAST32_MIN (-INT_LEAST32_MAX - 1)
-#undef UINT_LEAST32_MAX
-#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
-#undef INT_LEAST64_MAX
-#define INT_LEAST64_MAX __INT_LEAST64_MAX__
-#undef INT_LEAST64_MIN
-#define INT_LEAST64_MIN (-INT_LEAST64_MAX - 1)
-#undef UINT_LEAST64_MAX
-#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__
-
-#undef INT_FAST8_MAX
-#define INT_FAST8_MAX __INT_FAST8_MAX__
-#undef INT_FAST8_MIN
-#define INT_FAST8_MIN (-INT_FAST8_MAX - 1)
-#undef UINT_FAST8_MAX
-#define UINT_FAST8_MAX __UINT_FAST8_MAX__
-#undef INT_FAST16_MAX
-#define INT_FAST16_MAX __INT_FAST16_MAX__
-#undef INT_FAST16_MIN
-#define INT_FAST16_MIN (-INT_FAST16_MAX - 1)
-#undef UINT_FAST16_MAX
-#define UINT_FAST16_MAX __UINT_FAST16_MAX__
-#undef INT_FAST32_MAX
-#define INT_FAST32_MAX __INT_FAST32_MAX__
-#undef INT_FAST32_MIN
-#define INT_FAST32_MIN (-INT_FAST32_MAX - 1)
-#undef UINT_FAST32_MAX
-#define UINT_FAST32_MAX __UINT_FAST32_MAX__
-#undef INT_FAST64_MAX
-#define INT_FAST64_MAX __INT_FAST64_MAX__
-#undef INT_FAST64_MIN
-#define INT_FAST64_MIN (-INT_FAST64_MAX - 1)
-#undef UINT_FAST64_MAX
-#define UINT_FAST64_MAX __UINT_FAST64_MAX__
-
-#ifdef __INTPTR_MAX__
-# undef INTPTR_MAX
-# define INTPTR_MAX __INTPTR_MAX__
-# undef INTPTR_MIN
-# define INTPTR_MIN (-INTPTR_MAX - 1)
-#endif
-#ifdef __UINTPTR_MAX__
-# undef UINTPTR_MAX
-# define UINTPTR_MAX __UINTPTR_MAX__
-#endif
-
-#undef INTMAX_MAX
-#define INTMAX_MAX __INTMAX_MAX__
-#undef INTMAX_MIN
-#define INTMAX_MIN (-INTMAX_MAX - 1)
-#undef UINTMAX_MAX
-#define UINTMAX_MAX __UINTMAX_MAX__
-
-/* 7.18.3 Limits of other integer types */
-
-#undef PTRDIFF_MAX
-#define PTRDIFF_MAX __PTRDIFF_MAX__
-#undef PTRDIFF_MIN
-#define PTRDIFF_MIN (-PTRDIFF_MAX - 1)
-
-#undef SIG_ATOMIC_MAX
-#define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__
-#undef SIG_ATOMIC_MIN
-#define SIG_ATOMIC_MIN __SIG_ATOMIC_MIN__
-
-#undef SIZE_MAX
-#define SIZE_MAX __SIZE_MAX__
-
-#undef WCHAR_MAX
-#define WCHAR_MAX __WCHAR_MAX__
-#undef WCHAR_MIN
-#define WCHAR_MIN __WCHAR_MIN__
-
-#undef WINT_MAX
-#define WINT_MAX __WINT_MAX__
-#undef WINT_MIN
-#define WINT_MIN __WINT_MIN__
-
-#endif /* (!defined __cplusplus || __cplusplus >= 201103L
- || defined __STDC_LIMIT_MACROS) */
-
-#if (!defined __cplusplus || __cplusplus >= 201103L \
- || defined __STDC_CONSTANT_MACROS)
-
-#undef INT8_C
-#define INT8_C(c) __INT8_C(c)
-#undef INT16_C
-#define INT16_C(c) __INT16_C(c)
-#undef INT32_C
-#define INT32_C(c) __INT32_C(c)
-#undef INT64_C
-#define INT64_C(c) __INT64_C(c)
-#undef UINT8_C
-#define UINT8_C(c) __UINT8_C(c)
-#undef UINT16_C
-#define UINT16_C(c) __UINT16_C(c)
-#undef UINT32_C
-#define UINT32_C(c) __UINT32_C(c)
-#undef UINT64_C
-#define UINT64_C(c) __UINT64_C(c)
-#undef INTMAX_C
-#define INTMAX_C(c) __INTMAX_C(c)
-#undef UINTMAX_C
-#define UINTMAX_C(c) __UINTMAX_C(c)
-
-#endif /* (!defined __cplusplus || __cplusplus >= 201103L
- || defined __STDC_CONSTANT_MACROS) */
-
-#ifndef __INT_MAX__
-#define __INT_MAX__ 2147483647
-#endif
-#define INT_MIN (-1 - INT_MAX)
-#define INT_MAX (__INT_MAX__)
-#define UINT_MAX (INT_MAX * 2U + 1U)
-
-#define LONG_MAX ((long)(~0UL>>1))
-#define LONG_MIN (-LONG_MAX - 1)
-#define ULONG_MAX (~0UL)
-
-#endif
diff --git a/components/libc/compilers/minilibc/stdio.h b/components/libc/compilers/minilibc/stdio.h
deleted file mode 100644
index 678682cf5e..0000000000
--- a/components/libc/compilers/minilibc/stdio.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __STDIO_H__
-#define __STDIO_H__
-
-#define BUFSIZ 128
-#define EOF (-1)
-
-#ifndef SEEK_SET
-#define SEEK_SET 0 /* set file offset to offset */
-#endif
-#ifndef SEEK_CUR
-#define SEEK_CUR 1 /* set file offset to current plus offset */
-#endif
-#ifndef SEEK_END
-#define SEEK_END 2 /* set file offset to EOF plus offset */
-#endif
-
-#endif
-
diff --git a/components/libc/compilers/minilibc/stdlib.c b/components/libc/compilers/minilibc/stdlib.c
deleted file mode 100644
index 8154ec5b8b..0000000000
--- a/components/libc/compilers/minilibc/stdlib.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2008-08-14 Bernard the first version
- */
-
-#include <rtthread.h>
-
-#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
-#include "stdlib.h"
-
-int atoi(const char* s)
-{
- long int v=0;
- int sign=1;
- while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) s++;
- switch (*s)
- {
- case '-':
- sign=-1;
- case '+':
- ++s;
- }
- while ((unsigned int) (*s - '0') < 10u)
- {
- v=v*10+*s-'0';
- ++s;
- }
- return sign==-1?-v:v;
-}
-
-long int atol(const char* s)
-{
- long int v=0;
- int sign=0;
- while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) ++s;
- switch (*s)
- {
- case '-': sign=-1;
- case '+': ++s;
- }
- while ((unsigned int) (*s - '0') < 10u)
- {
- v=v*10+*s-'0'; ++s;
- }
- return sign?-v:v;
-}
-
-#ifdef RT_USING_HEAP
-void *malloc(size_t size)
-{
- return rt_malloc(size);
-}
-
-void free(void *ptr)
-{
- rt_free(ptr);
-}
-
-void *realloc(void *ptr, size_t size)
-{
- return rt_realloc(ptr, size);
-}
-
-void *calloc(size_t nelem, size_t elsize)
-{
- return rt_calloc(nelem, elsize);
-}
-#endif
-
-#endif
diff --git a/components/libc/compilers/minilibc/stdlib.h b/components/libc/compilers/minilibc/stdlib.h
deleted file mode 100644
index d57d95b64d..0000000000
--- a/components/libc/compilers/minilibc/stdlib.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2008-08-14 Bernard the first version
- */
-
-#ifndef __STDLIB_H__
-#define __STDLIB_H__
-
-#include <sys/types.h>
-
-#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
-int atoi(const char *nptr);
-long int atol(const char *nptr);
-
-int rand(void);
-int rand_r(unsigned int *seed);
-void srand(unsigned int seed);
-
-void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
-
-void *malloc(size_t size);
-void free(void *ptr);
-void *realloc(void *ptr, size_t size);
-void *calloc(size_t nelem, size_t elsize);
-void abort(void);
-#endif
-
-#endif
diff --git a/components/libc/compilers/minilibc/string.c b/components/libc/compilers/minilibc/string.c
deleted file mode 100644
index 1ab7c0509f..0000000000
--- a/components/libc/compilers/minilibc/string.c
+++ /dev/null
@@ -1,630 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2008-08-14 Bernard the first version
- * 2010-02-15 Gary Lee add strlcpy
- * 2010-03-17 Bernard add strlcpy implementation to this file.
- * fix strlcpy declaration
- * 2010-03-24 Bernard add strchr and strtok implementation.
- */
-
-#include <rtthread.h>
-#include <stdint.h>
-
-#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
-#include "string.h"
-
-/* there is no strcpy and strcmp implementation in RT-Thread */
-char *strcpy(char *dest, const char *src)
-{
- return (char *)rt_strncpy(dest, src, rt_strlen(src) + 1);
-}
-
-char *strncpy(char *dest, const char *src, size_t siz)
-{
- return (char *)rt_strncpy(dest, src, siz);
-}
-
-size_t strlcpy(char *dst, const char *src, size_t siz)
-{
- register char *d = dst;
- register const char *s = src;
- register size_t n = siz;
-
- /* Copy as many bytes as will fit */
- if (n != 0 && --n != 0)
- {
- do
- {
- if ((*d++ = *s++) == 0) break;
- } while (--n != 0);
- }
-
- /* Not enough room in dst, add NUL and traverse rest of src */
- if (n == 0)
- {
- if (siz != 0) *d = '\0'; /* NUL-terminate dst */
- while (*s++) ;
- }
-
- return(s - src - 1); /* count does not include NUL */
-}
-
-int strcmp (const char *s1, const char *s2)
-{
- while (*s1 && *s1 == *s2)
- s1++, s2++;
- return (*s1 - *s2);
-}
-
-/**
- * strncmp - Compare two length-limited strings
- * @cs: One string
- * @ct: Another string
- * @count: The maximum number of bytes to compare
- */
-int strncmp(const char *cs,const char *ct, size_t count)
-{
- register signed char __res = 0;
-
- while (count) {
- if ((__res = *cs - *ct++) != 0 || !*cs++)
- break;
- count--;
- }
-
- return __res;
-}
-
-char *strcat(char * dest, const char * src)
-{
- char *tmp = dest;
-
- while (*dest)
- dest++;
- while ((*dest++ = *src++) != '\0')
- ;
-
- return tmp;
-}
-
-char *strncat(char *dest, const char *src, size_t count)
-{
- char *tmp = dest;
-
- if (count) {
- while (*dest)
- dest++;
- while ((*dest++ = *src++)) {
- if (--count == 0) {
- *dest = '\0';
- break;
- }
- }
- }
-
- return tmp;
-}
-
-char *strrchr(const char *t, int c)
-{
- register char ch;
- register const char *l=0;
-
- ch = c;
- for (;;)
- {
- if (*t == ch) l=t;
- if (!*t) return (char*)l;
- ++t;
- }
-
- return (char*)l;
-}
-
-
-int strncasecmp ( const char* s1, const char* s2, size_t len )
-{
- register unsigned int x2;
- register unsigned int x1;
- register const char* end = s1 + len;
-
- while (1)
- {
- if ((s1 >= end) )
- return 0;
-
- x2 = *s2 - 'A'; if ((x2 < 26u)) x2 += 32;
- x1 = *s1 - 'A'; if ((x1 < 26u)) x1 += 32;
- s1++; s2++;
-
- if (x2 != x1)
- break;
-
- if (x1 == (unsigned int)-'A')
- break;
- }
-
- return x1 - x2;
-}
-
-/* private function */
-#define isdigit(c) ((unsigned)((c) - '0') < 10)
-
-rt_inline int divide(int *n, int base)
-{
- rt_int32_t res;
-
- /* optimized for processor which does not support divide instructions. */
- if (base == 10)
- {
- res = ((int)*n) % 10U;
- *n = ((int)*n) / 10U;
- }
- else
- {
- res = ((int)*n) % 16U;
- *n = ((int)*n) / 16U;
- }
-
- return res;
-}
-
-rt_inline int skip_atoi(const char **s)
-{
- register int i=0;
- while (isdigit(**s)) i = i*10 + *((*s)++) - '0';
-
- return i;
-}
-
-unsigned char _ctype[] = {
-_C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */
-_C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */
-_C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */
-_C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */
-_S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */
-_P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */
-_D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */
-_D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */
-_P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */
-_U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */
-_U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */
-_U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */
-_P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */
-_L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */
-_L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */
-_L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */
-_S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */
-_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */
-_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */
-_U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */
-_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */
-_L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */
-
-#define __ismask(x) (_ctype[(int)(unsigned char)(x)])
-
-#define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0)
-#define isalpha(c) ((__ismask(c)&(_U|_L)) != 0)
-#define iscntrl(c) ((__ismask(c)&(_C)) != 0)
-#define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0)
-#define islower(c) ((__ismask(c)&(_L)) != 0)
-#define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
-#define ispunct(c) ((__ismask(c)&(_P)) != 0)
-#define isspace(c) ((__ismask(c)&(_S)) != 0)
-#define isupper(c) ((__ismask(c)&(_U)) != 0)
-#define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0)
-
-#define isascii(c) (((unsigned char)(c))<=0x7f)
-#define toascii(c) (((unsigned char)(c))&0x7f)
-
-static inline unsigned char __tolower(unsigned char c)
-{
- if (isupper(c))
- c -= 'A'-'a';
- return c;
-}
-
-static inline unsigned char __toupper(unsigned char c)
-{
- if (islower(c))
- c -= 'a'-'A';
- return c;
-}
-
-int tolower(int c)
-{
- return __tolower(c);
-}
-
-int toupper(int c)
-{
- return __toupper(c);
-}
-
-/**
- * simple_strtoul - convert a string to an unsigned long
- * @cp: The start of the string
- * @endp: A pointer to the end of the parsed string will be placed here
- * @base: The number base to use
- */
-unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base)
-{
- unsigned long result = 0,value;
-
- if (!base) {
- base = 10;
- if (*cp == '0') {
- base = 8;
- cp++;
- if ((toupper(*cp) == 'X') && isxdigit(cp[1])) {
- cp++;
- base = 16;
- }
- }
- } else if (base == 16) {
- if (cp[0] == '0' && toupper(cp[1]) == 'X')
- cp += 2;
- }
- while (isxdigit(*cp) &&
- (value = isdigit(*cp) ? *cp-'0' : toupper(*cp)-'A'+10) < base) {
- result = result*base + value;
- cp++;
- }
- if (endp)
- *endp = (char *)cp;
- return result;
-}
-
-/**
- * simple_strtol - convert a string to a signed long
- * @cp: The start of the string
- * @endp: A pointer to the end of the parsed string will be placed here
- * @base: The number base to use
- */
-long simple_strtol(const char *cp,char **endp,unsigned int base)
-{
- if(*cp=='-')
- return -simple_strtoul(cp+1,endp,base);
- return simple_strtoul(cp,endp,base);
-}
-
-/**
- * simple_strtoull - convert a string to an unsigned long long
- * @cp: The start of the string
- * @endp: A pointer to the end of the parsed string will be placed here
- * @base: The number base to use
- */
-unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base)
-{
- unsigned long long result = 0, value;
-
- if (*cp == '0') {
- cp++;
- if ((toupper(*cp) == 'X') && isxdigit (cp[1])) {
- base = 16;
- cp++;
- }
- if (!base) {
- base = 8;
- }
- }
- if (!base) {
- base = 10;
- }
- while (isxdigit (*cp) && (value = isdigit (*cp)
- ? *cp - '0'
- : (islower (*cp) ? toupper (*cp) : *cp) - 'A' + 10) < base) {
- result = result * base + value;
- cp++;
- }
- if (endp)
- *endp = (char *) cp;
- return result;
-}
-
-/**
- * simple_strtoll - convert a string to a signed long long
- * @cp: The start of the string
- * @endp: A pointer to the end of the parsed string will be placed here
- * @base: The number base to use
- */
-long long simple_strtoll(const char *cp,char **endp,unsigned int base)
-{
- if(*cp=='-')
- return -simple_strtoull(cp+1,endp,base);
- return simple_strtoull(cp,endp,base);
-}
-
-/**
- * vsscanf - Unformat a buffer into a list of arguments
- * @buf: input buffer
- * @fmt: format of buffer
- * @args: arguments
- */
-int vsscanf(const char * buf, const char * fmt, va_list args)
-{
- const char *str = buf;
- char *next;
- int num = 0;
- int qualifier;
- int base;
- int field_width = -1;
- int is_sign = 0;
-
- while(*fmt && *str) {
- /* skip any white space in format */
- /* white space in format matchs any amount of
- * white space, including none, in the input.
- */
- if (isspace(*fmt)) {
- while (isspace(*fmt))
- ++fmt;
- while (isspace(*str))
- ++str;
- }
-
- /* anything that is not a conversion must match exactly */
- if (*fmt != '%' && *fmt) {
- if (*fmt++ != *str++)
- break;
- continue;
- }
-
- if (!*fmt)
- break;
- ++fmt;
-
- /* skip this conversion.
- * advance both strings to next white space
- */
- if (*fmt == '*') {
- while (!isspace(*fmt) && *fmt)
- fmt++;
- while (!isspace(*str) && *str)
- str++;
- continue;
- }
-
- /* get field width */
- if (isdigit(*fmt))
- field_width = skip_atoi(&fmt);
-
- /* get conversion qualifier */
- qualifier = -1;
- if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt == 'Z') {
- qualifier = *fmt;
- fmt++;
- }
- base = 10;
- is_sign = 0;
-
- if (!*fmt || !*str)
- break;
-
- switch(*fmt++) {
- case 'c':
- {
- char *s = (char *) va_arg(args,char*);
- if (field_width == -1)
- field_width = 1;
- do {
- *s++ = *str++;
- } while(field_width-- > 0 && *str);
- num++;
- }
- continue;
- case 's':
- {
- char *s = (char *) va_arg(args, char *);
- if(field_width == -1)
- field_width = INT_MAX;
- /* first, skip leading white space in buffer */
- while (isspace(*str))
- str++;
-
- /* now copy until next white space */
- while (*str && !isspace(*str) && field_width--) {
- *s++ = *str++;
- }
- *s = '\0';
- num++;
- }
- continue;
- case 'n':
- /* return number of characters read so far */
- {
- int *i = (int *)va_arg(args,int*);
- *i = str - buf;
- }
- continue;
- case 'o':
- base = 8;
- break;
- case 'x':
- case 'X':
- base = 16;
- break;
- case 'd':
- case 'i':
- is_sign = 1;
- case 'u':
- break;
- case '%':
- /* looking for '%' in str */
- if (*str++ != '%')
- return num;
- continue;
- default:
- /* invalid format; stop here */
- return num;
- }
-
- /* have some sort of integer conversion.
- * first, skip white space in buffer.
- */
- while (isspace(*str))
- str++;
-
- if (!*str || !isdigit(*str))
- break;
-
- switch(qualifier) {
- case 'h':
- if (is_sign) {
- short *s = (short *) va_arg(args,short *);
- *s = (short) simple_strtol(str,&next,base);
- } else {
- unsigned short *s = (unsigned short *) va_arg(args, unsigned short *);
- *s = (unsigned short) simple_strtoul(str, &next, base);
- }
- break;
- case 'l':
- if (is_sign) {
- long *l = (long *) va_arg(args,long *);
- *l = simple_strtol(str,&next,base);
- } else {
- unsigned long *l = (unsigned long*) va_arg(args,unsigned long*);
- *l = simple_strtoul(str,&next,base);
- }
- break;
- case 'L':
- if (is_sign) {
- long long *l = (long long*) va_arg(args,long long *);
- *l = simple_strtoll(str,&next,base);
- } else {
- unsigned long long *l = (unsigned long long*) va_arg(args,unsigned long long*);
- *l = simple_strtoull(str,&next,base);
- }
- break;
- case 'Z':
- {
- unsigned long *s = (unsigned long*) va_arg(args,unsigned long*);
- *s = (unsigned long) simple_strtoul(str,&next,base);
- }
- break;
- default:
- if (is_sign) {
- int *i = (int *) va_arg(args, int*);
- *i = (int) simple_strtol(str,&next,base);
- } else {
- unsigned int *i = (unsigned int*) va_arg(args, unsigned int*);
- *i = (unsigned int) simple_strtoul(str,&next,base);
- }
- break;
- }
- num++;
-
- if (!next)
- break;
- str = next;
- }
- return num;
-}
-
-/**
- * sscanf - Unformat a buffer into a list of arguments
- * @buf: input buffer
- * @fmt: formatting of buffer
- * @...: resulting arguments
- */
-int sscanf(const char * buf, const char * fmt, ...)
-{
- va_list args;
- int i;
-
- va_start(args,fmt);
- i = vsscanf(buf,fmt,args);
- va_end(args);
-
- return i;
-}
-
-size_t strspn(const char *s, const char *accept)
-{
- size_t l=0;
- int a=1,i, al=strlen(accept);
-
- while((a)&&(*s))
- {
- for(a=i=0;(!a)&&(i<al);i++)
- if (*s==accept[i]) a=1;
- if (a) l++;
- s++;
- }
- return l;
-}
-
-size_t strcspn(const char *s, const char *reject)
-{
- size_t l=0;
- int a=1,i,al=strlen(reject);
-
- while((a)&&(*s))
- {
- for(i=0;(a)&&(i<al);i++)
- if (*s==reject[i]) a=0;
- if (a) l++;
- s++;
- }
- return l;
-}
-
-char*strtok_r(char*s,const char*delim,char**ptrptr)
-{
- char*tmp=0;
-
- if (s==0) s=*ptrptr;
- s += strspn(s,delim); /* overread leading delimiter */
- if (*s)
- {
- tmp=s;
- s+=strcspn(s,delim);
-
- if (*s) *s++=0; /* not the end ? => terminate it */
- }
- *ptrptr=s;
- return tmp;
-}
-
-char *strtok(char *s, const char *delim)
-{
- static char *strtok_pos;
- return strtok_r(s,delim,&strtok_pos);
-}
-
-char *strchr(const char *s1, int i)
-{
- const unsigned char *s = (const unsigned char *)s1;
- unsigned char c = (unsigned int)i;
-
- while (*s && *s != c)
- {
- s++;
- }
-
- if (*s != c)
- {
- s = NULL;
- }
-
- return (char *) s;
-}
-
-long strtol(const char *str, char **endptr, int base)
-{
- return simple_strtol(str, endptr, base);
-}
-
-long long strtoll(const char *str, char **endptr, int base)
-{
- return simple_strtoll(str, endptr, base);
-}
-
-#endif
diff --git a/components/libc/compilers/minilibc/string.h b/components/libc/compilers/minilibc/string.h
deleted file mode 100644
index 45524c7764..0000000000
--- a/components/libc/compilers/minilibc/string.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2008-08-14 Bernard the first version
- */
-#ifndef __STRING_H__
-#define __STRING_H__
-
-#include <rtthread.h>
-#include <sys/types.h>
-
-/* replace for standard string library */
-#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
-
-#define ZEROPAD (1 << 0) /* pad with zero */
-#define SIGN (1 << 1) /* unsigned/signed long */
-#define PLUS (1 << 2) /* show plus */
-#define SPACE (1 << 3) /* space if plus */
-#define LEFT (1 << 4) /* left justified */
-#define SPECIAL (1 << 5) /* 0x */
-#define LARGE (1 << 6) /* use 'ABCDEF' instead of 'abcdef' */
-
-#define _U 0x01 /* upper */
-#define _L 0x02 /* lower */
-#define _D 0x04 /* digit */
-#define _C 0x08 /* cntrl */
-#define _P 0x10 /* punct */
-#define _S 0x20 /* white space (space/lf/tab) */
-#define _X 0x40 /* hex digit */
-#define _SP 0x80 /* hard space (0x20) */
-
-void* memset(void *s, int c, size_t n);
-void* memcpy(void *dest, const void *src, size_t n);
-void* memmove(void *dest, const void *src, size_t n);
-int memcmp(const void *s1, const void *s2, size_t n);
-
-int tolower(int c);
-int toupper(int c);
-
-int strcmp (const char *s1, const char *s2);
-int strncmp(const char *cs,const char *ct, size_t count);
-int strcasecmp(const char *a, const char *b);
-int strncasecmp(const char *cs, const char *ct, size_t count);
-int sscanf(const char * buf, const char * fmt, ...);
-size_t strlen(const char *s);
-char *strstr(const char * s1,const char * s2);
-char *strcpy(char *dest, const char *src);
-char *strncpy(char *dest, const char *src, size_t n);
-size_t strlcpy(char *dst, const char *src, size_t siz);
-char *strncat(char *dest, const char *src, size_t count);
-char *strcat(char * dest, const char * src);
-char *strchr(const char *s1, int i);
-char *strrchr(const char *t, int c);
-char *strdup(const char *s);
-char *strtok(char *s, const char *delim);
-char*strtok_r(char*s, const char*delim, char**ptrptr);
-
-size_t strcspn(const char *s, const char *reject);
-size_t strspn (const char *s, const char *accept);
-
-long strtol(const char *str, char **endptr, int base);
-long long strtoll(const char *str, char **endptr, int base);
-#endif
-
-#endif
diff --git a/components/libc/compilers/minilibc/sys/mman.h b/components/libc/compilers/minilibc/sys/mman.h
deleted file mode 100644
index 8c61b32b7c..0000000000
--- a/components/libc/compilers/minilibc/sys/mman.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/11/30 Bernard The first version.
- */
-
-#ifndef _SYS_MMAN_H
-#define _SYS_MMAN_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MAP_FAILED ((void *) -1)
-
-#define MAP_SHARED 0x01
-#define MAP_PRIVATE 0x02
-#define MAP_TYPE 0x0f
-#define MAP_FIXED 0x10
-#define MAP_ANON 0x20
-#define MAP_ANONYMOUS MAP_ANON
-#define MAP_NORESERVE 0x4000
-#define MAP_GROWSDOWN 0x0100
-#define MAP_DENYWRITE 0x0800
-#define MAP_EXECUTABLE 0x1000
-#define MAP_LOCKED 0x2000
-#define MAP_POPULATE 0x8000
-#define MAP_NONBLOCK 0x10000
-#define MAP_STACK 0x20000
-#define MAP_HUGETLB 0x40000
-#define MAP_FILE 0
-
-#define PROT_NONE 0
-#define PROT_READ 1
-#define PROT_WRITE 2
-#define PROT_EXEC 4
-#define PROT_GROWSDOWN 0x01000000
-#define PROT_GROWSUP 0x02000000
-
-#define MS_ASYNC 1
-#define MS_INVALIDATE 2
-#define MS_SYNC 4
-
-#define MCL_CURRENT 1
-#define MCL_FUTURE 2
-#define MCL_ONFAULT 4
-
-void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off);
-int munmap (void *start, size_t len);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/components/libc/compilers/minilibc/sys/stat.h b/components/libc/compilers/minilibc/sys/stat.h
deleted file mode 100644
index 65db477a4a..0000000000
--- a/components/libc/compilers/minilibc/sys/stat.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __STAT_H__
-#define __STAT_H__
-
-#include <rtthread.h>
-
-#ifdef RT_USING_DFS
-#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 */
-
-#define O_RDONLY 0 /* +1 == FREAD */
-#define O_WRONLY 1 /* +1 == FWRITE */
-#define O_RDWR 2 /* +1 == FREAD|FWRITE */
-#define O_APPEND _FAPPEND
-#define O_CREAT _FCREAT
-#define O_TRUNC _FTRUNC
-#define O_EXCL _FEXCL
-#define O_SYNC _FSYNC
-#endif
-
-#endif
diff --git a/components/libc/compilers/minilibc/sys/time.h b/components/libc/compilers/minilibc/sys/time.h
deleted file mode 100644
index 22a93f5c9d..0000000000
--- a/components/libc/compilers/minilibc/sys/time.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef _SYS_TIME_H_
-#define _SYS_TIME_H_
-
-#include <sys/types.h>
-typedef long time_t;
-
-/*
- * Structure returned by gettimeofday(2) system call,
- * and used in other calls.
- */
-struct timeval {
- long tv_sec; /* seconds */
- long tv_usec; /* and microseconds */
-};
-
-/*
- * Structure defined by POSIX.1b to be like a timeval.
- */
-struct timespec {
- time_t tv_sec; /* seconds */
- long tv_nsec; /* and nanoseconds */
-};
-
-struct timezone {
- int tz_minuteswest; /* minutes west of Greenwich */
- int tz_dsttime; /* type of dst correction */
-};
-
-struct tm {
- int tm_sec; /* Seconds. [0-60] (1 leap second) */
- int tm_min; /* Minutes. [0-59] */
- int tm_hour; /* Hours. [0-23] */
- int tm_mday; /* Day. [1-31] */
- int tm_mon; /* Month. [0-11] */
- int tm_year; /* Year - 1900. */
- int tm_wday; /* Day of week. [0-6] */
- int tm_yday; /* Days in year.[0-365] */
- int tm_isdst; /* DST. [-1/0/1]*/
-
- long int tm_gmtoff; /* Seconds east of UTC. */
- const char *tm_zone; /* Timezone abbreviation. */
-};
-
-int gettimeofday(struct timeval *tp, void *ignore);
-
-#endif
diff --git a/components/libc/compilers/minilibc/sys/types.h b/components/libc/compilers/minilibc/sys/types.h
deleted file mode 100644
index 746235273c..0000000000
--- a/components/libc/compilers/minilibc/sys/types.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __TYPES_H__
-#define __TYPES_H__
-#include <rtconfig.h>
-
-typedef long off_t;
-
-#ifndef ARCH_CPU_64BIT
-typedef unsigned int size_t;
-typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */
-#else
-typedef long unsigned int size_t;
-typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */
-#endif
-
-typedef unsigned char u_char;
-typedef unsigned short u_short;
-typedef unsigned int u_int;
-typedef unsigned long u_long;
-
-typedef unsigned long clockid_t;
-typedef int pid_t;
-
-typedef int gid_t;
-typedef int uid_t;
-typedef int dev_t;
-typedef int ino_t;
-typedef int mode_t;
-typedef int caddr_t;
-
-typedef unsigned int wint_t;
-typedef unsigned long useconds_t;
-
-typedef unsigned long clock_t; /* clock() */
-
-#ifndef NULL
-#define NULL (0)
-#endif
-
-#define __u_char_defined
-
-#endif
-
diff --git a/components/libc/compilers/minilibc/time.c b/components/libc/compilers/minilibc/time.c
deleted file mode 100644
index 25e8f0e310..0000000000
--- a/components/libc/compilers/minilibc/time.c
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#include <time.h>
-#include <rtthread.h>
-
-/* days per month -- nonleap! */
-const short __spm[13] =
-{ 0,
- (31),
- (31 + 28),
- (31 + 28 + 31),
- (31 + 28 + 31 + 30),
- (31 + 28 + 31 + 30 + 31),
- (31 + 28 + 31 + 30 + 31 + 30),
- (31 + 28 + 31 + 30 + 31 + 30 + 31),
- (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31),
- (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30),
- (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31),
- (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30),
- (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31),
-};
-static long int timezone;
-static const char days[] = "Sun Mon Tue Wed Thu Fri Sat ";
-static const char months[] = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
-
-/* seconds per day */
-#define SPD 24*60*60
-
-int __isleap(int year)
-{
- /* every fourth year is a leap year except for century years that are
- * not divisible by 400. */
- /* return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); */
- return (!(year % 4) && ((year % 100) || !(year % 400)));
-}
-
-struct tm *gmtime_r(const time_t *timep, struct tm *r)
-{
- time_t i;
- register time_t work = *timep % (SPD);
- r->tm_sec = work % 60;
- work /= 60;
- r->tm_min = work % 60;
- r->tm_hour = work / 60;
- work = *timep / (SPD);
- r->tm_wday = (4 + work) % 7;
- for (i = 1970;; ++i)
- {
- register time_t k = __isleap(i) ? 366 : 365;
- if (work >= k)
- work -= k;
- else
- break;
- }
- r->tm_year = i - 1900;
- r->tm_yday = work;
-
- r->tm_mday = 1;
- if (__isleap(i) && (work > 58))
- {
- if (work == 59)
- r->tm_mday = 2; /* 29.2. */
- work -= 1;
- }
-
- for (i = 11; i && (__spm[i] > work); --i)
- ;
- r->tm_mon = i;
- r->tm_mday += work - __spm[i];
- return r;
-}
-
-struct tm* localtime_r(const time_t* t, struct tm* r)
-{
- time_t tmp;
- struct timezone tz = {0};
- gettimeofday(0, &tz);
- timezone = tz.tz_minuteswest * 60L;
- tmp = *t + timezone;
- return gmtime_r(&tmp, r);
-}
-
-struct tm* localtime(const time_t* t)
-{
- static struct tm tmp;
- return localtime_r(t, &tmp);
-}
-
-time_t mktime(struct tm * const t)
-{
- register time_t day;
- register time_t i;
- register time_t years = t->tm_year - 70;
-
- if (t->tm_sec > 60)
- {
- t->tm_min += t->tm_sec / 60;
- t->tm_sec %= 60;
- }
- if (t->tm_min > 60)
- {
- t->tm_hour += t->tm_min / 60;
- t->tm_min %= 60;
- }
- if (t->tm_hour > 24)
- {
- t->tm_mday += t->tm_hour / 24;
- t->tm_hour %= 24;
- }
- if (t->tm_mon > 12)
- {
- t->tm_year += t->tm_mon / 12;
- t->tm_mon %= 12;
- }
- while (t->tm_mday > __spm[1 + t->tm_mon])
- {
- if (t->tm_mon == 1 && __isleap(t->tm_year + 1900))
- {
- --t->tm_mday;
- }
- t->tm_mday -= __spm[t->tm_mon];
- ++t->tm_mon;
- if (t->tm_mon > 11)
- {
- t->tm_mon = 0;
- ++t->tm_year;
- }
- }
-
- if (t->tm_year < 70)
- return (time_t) - 1;
-
- /* Days since 1970 is 365 * number of years + number of leap years since 1970 */
- day = years * 365 + (years + 1) / 4;
-
- /* After 2100 we have to substract 3 leap years for every 400 years
- This is not intuitive. Most mktime implementations do not support
- dates after 2059, anyway, so we might leave this out for it's
- bloat. */
- if (years >= 131)
- {
- years -= 131;
- years /= 100;
- day -= (years >> 2) * 3 + 1;
- if ((years &= 3) == 3)
- years--;
- day -= years;
- }
-
- day += t->tm_yday = __spm[t->tm_mon] + t->tm_mday - 1 +
- (__isleap(t->tm_year + 1900) & (t->tm_mon > 1));
-
- /* day is now the number of days since 'Jan 1 1970' */
- i = 7;
- t->tm_wday = (day + 4) % i; /* Sunday=0, Monday=1, ..., Saturday=6 */
-
- i = 24;
- day *= i;
- i = 60;
- return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec;
-}
-
-static void num2str(char *c, int i)
-{
- c[0] = i / 10 + '0';
- c[1] = i % 10 + '0';
-}
-
-char *asctime_r(const struct tm *t, char *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));
- 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, (t->tm_year + 1900) / 100);
- num2str(buf + 22, (t->tm_year + 1900) % 100);
- buf[24] = '\n';
- return buf;
-}
-
-char *asctime(const struct tm *timeptr)
-{
- static char buf[25];
- return asctime_r(timeptr, buf);
-}
-
-char *ctime(const time_t *timep)
-{
- return asctime(localtime(timep));
-}
-
-#ifdef RT_USING_DEVICE
-int gettimeofday(struct timeval *tp, void *ignore)
-{
- time_t time;
- rt_device_t device;
-
- device = rt_device_find("rtc");
- RT_ASSERT(device != RT_NULL);
-
- rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
- if (tp != RT_NULL)
- {
- tp->tv_sec = time;
- tp->tv_usec = 0;
- }
-
- return time;
-}
-#endif
-
-#ifndef _gettimeofday
-/* Dummy function when hardware do not have RTC */
-int _gettimeofday( struct timeval *tv, void *ignore)
-{
- tv->tv_sec = 0; // convert to seconds
- tv->tv_usec = 0; // get remaining microseconds
- return 0; // return non-zero for error
-}
-#endif
-
-/**
- * Returns the current time.
- *
- * @param time_t * t the timestamp pointer, if not used, keep NULL.
- *
- * @return time_t return timestamp current.
- *
- */
-/* for IAR 6.2 later Compiler */
-#if defined (__IAR_SYSTEMS_ICC__) && (__VER__) >= 6020000
-#pragma module_name = "?time"
-time_t (__time32)(time_t *t) /* Only supports 32-bit timestamp */
-#else
-time_t time(time_t *t)
-#endif
-{
- time_t time_now = 0;
-
-#ifdef RT_USING_RTC
- static rt_device_t device = RT_NULL;
-
- /* optimization: find rtc device only first. */
- if (device == RT_NULL)
- {
- device = rt_device_find("rtc");
- }
-
- /* read timestamp from RTC device. */
- if (device != RT_NULL)
- {
- if (rt_device_open(device, 0) == RT_EOK)
- {
- rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now);
- rt_device_close(device);
- }
- }
-#endif /* RT_USING_RTC */
-
- /* if t is not NULL, write timestamp to *t */
- if (t != RT_NULL)
- {
- *t = time_now;
- }
-
- return time_now;
-}
-
-RT_WEAK clock_t clock(void)
-{
- return rt_tick_get();
-}
diff --git a/components/libc/compilers/minilibc/time.h b/components/libc/compilers/minilibc/time.h
deleted file mode 100644
index 09fc7d2e67..0000000000
--- a/components/libc/compilers/minilibc/time.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __TIME_H__
-#define __TIME_H__
-
-#include <sys/time.h>
-
-time_t mktime(struct tm * const t);
-
-char *asctime(const struct tm *timeptr);
-char *ctime(const time_t *timep);
-struct tm* localtime(const time_t* t);
-
-char *asctime_r(const struct tm *t, char *buf);
-struct tm *gmtime_r(const time_t *timep, struct tm *r);
-struct tm* localtime_r(const time_t* t, struct tm* r);
-
-#endif
diff --git a/components/libc/compilers/newlib/SConscript b/components/libc/compilers/newlib/SConscript
index d0868bbdea..542cdecd40 100644
--- a/components/libc/compilers/newlib/SConscript
+++ b/components/libc/compilers/newlib/SConscript
@@ -1,21 +1,29 @@
from building import *
Import('rtconfig')
-src = Glob('*.c')
+src = []
cwd = GetCurrentDir()
group = []
-
+LIBS = []
+CPPDEFINES = []
CPPPATH = [cwd]
-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']
if rtconfig.PLATFORM == 'gcc':
- group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'],
- CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
+ 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
index 2234c36f98..9834a9a015 100644
--- a/components/libc/compilers/newlib/libc.c
+++ b/components/libc/compilers/newlib/libc.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -19,7 +19,7 @@
#include <pthread.h>
#endif
-int _EXFUN(putenv,(char *__string));
+int _EXFUN(putenv,(char *__string));
int libc_system_init(void)
{
diff --git a/components/libc/compilers/newlib/libc.h b/components/libc/compilers/newlib/libc.h
index 9a76ffb79f..c1f76d7605 100644
--- a/components/libc/compilers/newlib/libc.h
+++ b/components/libc/compilers/newlib/libc.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/newlib/libc_syms.c b/components/libc/compilers/newlib/libc_syms.c
index b150c10fd6..aaf6980d6b 100644
--- a/components/libc/compilers/newlib/libc_syms.c
+++ b/components/libc/compilers/newlib/libc_syms.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -39,10 +39,6 @@ RTM_EXPORT(snprintf);
RTM_EXPORT(fwrite);
-#include <time.h>
-RTM_EXPORT(localtime);
-RTM_EXPORT(time);
-
#include <setjmp.h>
RTM_EXPORT(longjmp);
RTM_EXPORT(setjmp);
diff --git a/components/libc/compilers/newlib/machine/time.h b/components/libc/compilers/newlib/machine/time.h
index d46533eb39..ff754d2473 100644
--- a/components/libc/compilers/newlib/machine/time.h
+++ b/components/libc/compilers/newlib/machine/time.h
@@ -9,4 +9,4 @@
int nanosleep (const struct timespec *, struct timespec *);
#endif
-#endif /* _MACHTIME_H_ */
+#endif /* _MACHTIME_H_ */
diff --git a/components/libc/compilers/newlib/minilib.c b/components/libc/compilers/newlib/minilib.c
new file mode 100644
index 0000000000..f6df38f67b
--- /dev/null
+++ b/components/libc/compilers/newlib/minilib.c
@@ -0,0 +1,68 @@
+/*
+ * 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 */
+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
index 233a447396..ce5bdb75cb 100644
--- a/components/libc/compilers/newlib/stdio.c
+++ b/components/libc/compilers/newlib/stdio.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -15,7 +15,7 @@
#define STDIO_DEVICE_NAME_MAX 32
-int _EXFUN(fileno, (FILE *));
+int _EXFUN(fileno, (FILE *));
static FILE* std_console = NULL;
@@ -48,7 +48,7 @@ int libc_stdio_set_console(const char* device_name, int mode)
{
_GLOBAL_REENT->_stdin = std_console;
}
- else
+ else
{
_GLOBAL_REENT->_stdin = NULL;
}
diff --git a/components/libc/compilers/newlib/sys/dirent.h b/components/libc/compilers/newlib/sys/dirent.h
deleted file mode 100644
index db8c0655a1..0000000000
--- a/components/libc/compilers/newlib/sys/dirent.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __RTT_DIRENT_H__
-#define __RTT_DIRENT_H__
-
-#include <rtthread.h>
-
-/*
-* dirent.h - format of directory entries
- * Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html
- */
-
-/* File types */
-#define FT_REGULAR 0 /* regular file */
-#define FT_SOCKET 1 /* socket file */
-#define FT_DIRECTORY 2 /* directory */
-#define FT_USER 3 /* user defined */
-
-#define DT_UNKNOWN 0x00
-#define DT_REG 0x01
-#define DT_DIR 0x02
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef HAVE_DIR_STRUCTURE
-typedef struct
-{
- int fd; /* directory file */
- char buf[512];
- int num;
- int cur;
-} DIR;
-#endif
-
-#ifndef HAVE_DIRENT_STRUCTURE
-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 */
-};
-#endif
-
-int closedir(DIR *);
-DIR *opendir(const char *);
-struct dirent *readdir(DIR *);
-int readdir_r(DIR *, struct dirent *, struct dirent **);
-void rewinddir(DIR *);
-void seekdir(DIR *, long int);
-long telldir(DIR *);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/components/libc/compilers/newlib/sys/statfs.h b/components/libc/compilers/newlib/sys/statfs.h
deleted file mode 100644
index 3c923a21f9..0000000000
--- a/components/libc/compilers/newlib/sys/statfs.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __RTT_STATFS_H__
-#define __RTT_STATFS_H__
-
-#include <rtthread.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 */
-};
-
-#endif
diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c
index 76300f76b2..7c5d51eca6 100644
--- a/components/libc/compilers/newlib/syscalls.c
+++ b/components/libc/compilers/newlib/syscalls.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -7,12 +7,14 @@
* Date Author Notes
* 2021-02-11 Meco Man remove _gettimeofday_r() and _times_r()
* 2020-02-13 Meco Man re-implement exit() and abort()
+ * 2020-02-21 Meco Man improve and beautify syscalls
+ * 2020-02-24 Meco Man fix bug of _isatty_r()
*/
#include <reent.h>
-#include <sys/errno.h>
-#include <sys/time.h>
+#include <errno.h>
#include <stdio.h>
+#include <sys/time.h>
#include <rtthread.h>
@@ -35,10 +37,18 @@ __errno ()
#endif
int
+_getpid_r(struct _reent *ptr)
+{
+ return 0;
+}
+
+int
_close_r(struct _reent *ptr, int fd)
{
#ifndef RT_USING_DFS
- return 0;
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
+ return -1;
#else
return close(fd);
#endif
@@ -77,19 +87,16 @@ _fstat_r(struct _reent *ptr, int fd, struct stat *pstat)
}
int
-_getpid_r(struct _reent *ptr)
-{
- return 0;
-}
-
-int
_isatty_r(struct _reent *ptr, int fd)
{
- if (fd >=0 && fd < 3) return 1;
-
- /* return "not supported" */
- ptr->_errno = ENOTSUP;
- return -1;
+ if (fd >=0 && fd < 3)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
}
int
@@ -112,7 +119,9 @@ _off_t
_lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
{
#ifndef RT_USING_DFS
- return 0;
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
+ return -1;
#else
_off_t rc;
@@ -125,7 +134,9 @@ int
_mkdir_r(struct _reent *ptr, const char *name, int mode)
{
#ifndef RT_USING_DFS
- return 0;
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
+ return -1;
#else
int rc;
@@ -138,7 +149,9 @@ int
_open_r(struct _reent *ptr, const char *file, int flags, int mode)
{
#ifndef RT_USING_DFS
- return 0;
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
+ return -1;
#else
int rc;
@@ -151,7 +164,9 @@ _ssize_t
_read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
{
#ifndef RT_USING_DFS
- return 0;
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
+ return -1;
#else
_ssize_t rc;
@@ -164,7 +179,9 @@ int
_rename_r(struct _reent *ptr, const char *old, const char *new)
{
#ifndef RT_USING_DFS
- return 0;
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
+ return -1;
#else
int rc;
@@ -173,18 +190,13 @@ _rename_r(struct _reent *ptr, const char *old, const char *new)
#endif
}
-void *
-_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
-{
- /* no use this routine to get memory */
- return RT_NULL;
-}
-
int
_stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
{
#ifndef RT_USING_DFS
- return 0;
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
+ return -1;
#else
int rc;
@@ -197,6 +209,8 @@ int
_unlink_r(struct _reent *ptr, const char *file)
{
#ifndef RT_USING_DFS
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
return -1;
#else
return unlink(file);
@@ -211,11 +225,11 @@ _wait_r(struct _reent *ptr, int *status)
return -1;
}
-#ifdef RT_USING_DEVICE
_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)
{
rt_device_t console;
@@ -225,7 +239,11 @@ _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
}
return 0;
-
+#else
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
+ return -1;
+#endif /*RT_USING_DEVICE*/
#else
_ssize_t rc;
@@ -233,9 +251,8 @@ _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
return rc;
#endif
}
-#endif
-/* Memory routine */
+#ifdef RT_USING_HEAP /* Memory routine */
void *
_malloc_r (struct _reent *ptr, size_t size)
{
@@ -283,8 +300,17 @@ _free_r (struct _reent *ptr, void *addr)
rt_free (addr);
}
-void
-exit (int status)
+#else
+void *
+_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
+{
+ return RT_NULL;
+}
+#endif /*RT_USING_HEAP*/
+
+/* for exit() and abort() */
+__attribute__ ((noreturn)) void
+_exit (int status)
{
extern void __rt_libc_exit(int status);
__rt_libc_exit(status);
@@ -303,18 +329,6 @@ void __libc_init_array(void)
/* we not use __libc init_aray to initialize C++ objects */
}
-void abort(void)
-{
- extern void __rt_libc_abort(void);
- __rt_libc_abort();
- while(1);
-}
-
-uid_t getuid(void)
-{
- return 0;
-}
-
mode_t umask(mode_t mask)
{
return 022;
@@ -326,7 +340,7 @@ int flock(int fd, int operation)
}
/*
-These functions will be implemented and replaced by the 'common/time.c' file
+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);
*/
diff --git a/components/libc/getline/README.md b/components/libc/getline/README.md
index 0b279755d3..ef3c19deae 100644
--- a/components/libc/getline/README.md
+++ b/components/libc/getline/README.md
@@ -18,13 +18,3 @@ For more details, see [Open Group Base Specification for getdelim/getline][openg
This code is unlicensed -- free and released into the public domain. See `UNLICENSE` file for more information.
[opengroup-spec]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getline.html
-
-
-
-
-## 联系&维护
-Meco Man
-
-
-https://github.com/mysterywolf/getline
diff --git a/components/libc/getline/posix_getline.c b/components/libc/getline/posix_getline.c
index e2ac278242..794ac3a07d 100644
--- a/components/libc/getline/posix_getline.c
+++ b/components/libc/getline/posix_getline.c
@@ -1,13 +1,12 @@
/* posix_getline.c
* RT-Thread POSIX
* getdelim(), getline() - read a delimited record from stream, ersatz implementation
- * This code is unlicensed -- free and released into the public domain.
+ * This code is unlicensed -- free and released into the public domain.
* https://man7.org/linux/man-pages/man3/getline.3.html
* Authors:
* https://github.com/ivanrad/getline
- * https://github.com/mysterywolf/getline/
- *
- * Meco Man 2020-09-03 First Version
+ *
+ * Meco Man 2020-09-03 porting to RT-Thread
*/
#include "posix_getline.h"
diff --git a/components/libc/getline/posix_getline.h b/components/libc/getline/posix_getline.h
index c7d6021af3..13a4487d7f 100644
--- a/components/libc/getline/posix_getline.h
+++ b/components/libc/getline/posix_getline.h
@@ -1,13 +1,12 @@
/* posix_getline.h
* RT-Thread POSIX
* getdelim(), getline() - read a delimited record from stream, ersatz implementation
- * This code is unlicensed -- free and released into the public domain.
+ * This code is unlicensed -- free and released into the public domain.
* https://man7.org/linux/man-pages/man3/getline.3.html
* Authors:
* https://github.com/ivanrad/getline
- * https://github.com/mysterywolf/getline/
*
- * Meco Man 2020-09-03 First Version
+ * Meco Man 2020-09-03 porting to RT-Thread
*/
diff --git a/components/libc/libdl/arch/arm.c b/components/libc/libdl/arch/arm.c
index a53c04f0bc..6a884bdb54 100644
--- a/components/libc/libdl/arch/arm.c
+++ b/components/libc/libdl/arch/arm.c
@@ -1,8 +1,8 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
- *
+ *
* Change Logs:
* Date Author Notes
* 2018/08/29 Bernard first version
diff --git a/components/libc/libdl/arch/riscv.c b/components/libc/libdl/arch/riscv.c
new file mode 100644
index 0000000000..33cae28d16
--- /dev/null
+++ b/components/libc/libdl/arch/riscv.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021/04/23 chunyexixiaoyu first version
+
+ */
+
+#include "../dlmodule.h"
+#include "../dlelf.h"
+
+#if (__riscv_xlen == 64)
+#define R_RISCV_NONE 0
+#define R_RISCV_32 1
+#define R_RISCV_64 2
+#define R_RISCV_RELATIVE 3
+#define R_RISCV_COPY 4
+#define R_RISCV_JUMP_SLOT 5
+#define R_RISCV_TLS_DTPMOD32 6
+#define R_RISCV_TLS_DTPMOD64 7
+#define R_RISCV_TLS_DTPREL32 8
+#define R_RISCV_TLS_DTPREL64 9
+#define R_RISCV_TLS_TPREL32 10
+#define R_RISCV_TLS_TPREL64 11
+
+int dlmodule_relocate(struct rt_dlmodule *module, Elf_Rel *rel, Elf_Addr sym_val)
+{
+ Elf64_Addr *where, tmp;
+ Elf64_Sword addend, offset;
+ rt_uint64_t upper, lower, sign, j1, j2;
+
+ where = (Elf64_Addr *)((rt_uint8_t *)module->mem_space
+ + rel->r_offset
+ - module->vstart_addr);
+ switch (ELF64_R_TYPE(rel->r_info))
+ {
+ case R_RISCV_NONE:
+ break;
+ case R_RISCV_64:
+ *where = (Elf64_Addr)(sym_val + rel->r_addend);
+ RT_DEBUG_LOG(RT_DEBUG_MODULE, ("R_RISCV_64: %x -> %x\n",where, *where));
+ break;
+ case R_RISCV_RELATIVE:
+ *where = (Elf64_Addr)((rt_uint8_t *)module->mem_space - module->vstart_addr + rel->r_addend);
+ RT_DEBUG_LOG(RT_DEBUG_MODULE, ("R_RISCV_RELATIVE: %x -> %x\n",where, *where));
+ break;
+ case R_RISCV_JUMP_SLOT:
+ *where = (Elf64_Addr)sym_val;
+ RT_DEBUG_LOG(RT_DEBUG_MODULE, ("R_RISCV_JUMP_SLOT: %x -> %x\n",where, *where));
+ break;
+ default:
+ RT_DEBUG_LOG(RT_DEBUG_MODULE, ("__riscv__ELF: invalid relocate TYPE %d\n", ELF64_R_TYPE(rel->r_info)));
+ return -1;
+ }
+ return 0;
+}
+#endif
diff --git a/components/libc/libdl/arch/x86.c b/components/libc/libdl/arch/x86.c
index 16f2322fb4..e7ad714a03 100644
--- a/components/libc/libdl/arch/x86.c
+++ b/components/libc/libdl/arch/x86.c
@@ -1,8 +1,8 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
- *
+ *
* Change Logs:
* Date Author Notes
* 2018/09/15 parai first version
@@ -13,9 +13,9 @@
#ifdef __i386__
-#define R_X86_64_GLOB_DAT 6 /* Create GOT entry */
-#define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */
-#define R_X86_64_RELATIVE 8 /* Adjust by program base */
+#define R_X86_64_GLOB_DAT 6 /* Create GOT entry */
+#define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */
+#define R_X86_64_RELATIVE 8 /* Adjust by program base */
int dlmodule_relocate(struct rt_dlmodule *module, Elf32_Rel *rel, Elf32_Addr sym_val)
{
Elf32_Addr *where, tmp;
diff --git a/components/libc/libdl/dlclose.c b/components/libc/libdl/dlclose.c
index 1202e13f2c..876a1576c8 100644
--- a/components/libc/libdl/dlclose.c
+++ b/components/libc/libdl/dlclose.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/libdl/dlelf.c b/components/libc/libdl/dlelf.c
index 55ef0d8951..418ad7539a 100644
--- a/components/libc/libdl/dlelf.c
+++ b/components/libc/libdl/dlelf.c
@@ -1,11 +1,12 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018/08/29 Bernard first version
+ * 2021/04/23 chunyexixiaoyu distinguish 32-bit and 64-bit
*/
#include "dlmodule.h"
@@ -18,8 +19,8 @@
rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_ptr)
{
rt_bool_t linked = RT_FALSE;
- rt_uint32_t index, module_size = 0;
- Elf32_Addr vstart_addr, vend_addr;
+ rt_ubase_t index, module_size = 0;
+ Elf_Addr vstart_addr, vend_addr;
rt_bool_t has_vstart;
RT_ASSERT(module_ptr != RT_NULL);
@@ -53,7 +54,7 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
has_vstart = RT_TRUE;
if (vend_addr < vstart_addr)
{
- rt_kprintf("invalid elf: segment %d: p_vaddr: %d, p_memsz: %d\n",
+ LOG_E("invalid elf: segment %d: p_vaddr: %d, p_memsz: %d\n",
index, phdr[index].p_vaddr, phdr[index].p_memsz);
return RT_NULL;
}
@@ -62,7 +63,7 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
{
if (phdr[index].p_vaddr < vend_addr)
{
- rt_kprintf("invalid elf: segment should be sorted and not overlapped\n");
+ LOG_E("invalid elf: segment should be sorted and not overlapped\n");
return RT_NULL;
}
if (phdr[index].p_vaddr > vend_addr + 16)
@@ -74,7 +75,7 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
vend_addr = phdr[index].p_vaddr + phdr[index].p_memsz;
if (vend_addr < phdr[index].p_vaddr)
{
- rt_kprintf("invalid elf: "
+ LOG_E("invalid elf: "
"segment %d address overflow\n", index);
return RT_NULL;
}
@@ -85,7 +86,7 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
LOG_D("module size: %d, vstart_addr: 0x%p", module_size, vstart_addr);
if (module_size == 0)
{
- rt_kprintf("Module: size error\n");
+ LOG_E("Module: size error\n");
return -RT_ERROR;
}
@@ -96,7 +97,7 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
module->mem_space = rt_malloc(module_size);
if (module->mem_space == RT_NULL)
{
- rt_kprintf("Module: allocate space failed.\n");
+ LOG_E("Module: allocate space failed.\n");
return -RT_ERROR;
}
module->mem_size = module_size;
@@ -119,42 +120,49 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
/* handle relocation section */
for (index = 0; index < elf_module->e_shnum; index ++)
{
- rt_uint32_t i, nr_reloc;
- Elf32_Sym *symtab;
- Elf32_Rel *rel;
+ rt_ubase_t i, nr_reloc;
+ Elf_Sym *symtab;
+ Elf_Rel *rel;
rt_uint8_t *strtab;
static rt_bool_t unsolved = RT_FALSE;
-
+ #if (defined(__arm__) || defined(__i386__) || (__riscv_xlen == 32))
if (!IS_REL(shdr[index]))
continue;
+ #elif (defined(__aarch64__) || defined(__x86_64__) || (__riscv_xlen == 64))
+ if (!IS_RELA(shdr[index]))
+ continue;
+ #endif
/* get relocate item */
- rel = (Elf32_Rel *)((rt_uint8_t *)module_ptr + shdr[index].sh_offset);
+ rel = (Elf_Rel *)((rt_uint8_t *)module_ptr + shdr[index].sh_offset);
/* locate .rel.plt and .rel.dyn section */
- symtab = (Elf32_Sym *)((rt_uint8_t *)module_ptr +
+ symtab = (Elf_Sym *)((rt_uint8_t *)module_ptr +
shdr[shdr[index].sh_link].sh_offset);
strtab = (rt_uint8_t *)module_ptr +
shdr[shdr[shdr[index].sh_link].sh_link].sh_offset;
- nr_reloc = (rt_uint32_t)(shdr[index].sh_size / sizeof(Elf32_Rel));
+ nr_reloc = (rt_ubase_t)(shdr[index].sh_size / sizeof(Elf_Rel));
/* relocate every items */
for (i = 0; i < nr_reloc; i ++)
{
- Elf32_Sym *sym = &symtab[ELF32_R_SYM(rel->r_info)];
-
+ #if (defined(__arm__) || defined(__i386__) || (__riscv_xlen == 32))
+ Elf_Sym *sym = &symtab[ELF32_R_SYM(rel->r_info)];
+ #elif (defined(__aarch64__) || defined(__x86_64__) || (__riscv_xlen == 64))
+ Elf_Sym *sym = &symtab[ELF64_R_SYM(rel->r_info)];
+ #endif
LOG_D("relocate symbol %s shndx %d", strtab + sym->st_name, sym->st_shndx);
if ((sym->st_shndx != SHT_NULL) ||(ELF_ST_BIND(sym->st_info) == STB_LOCAL))
{
- Elf32_Addr addr;
+ Elf_Addr addr;
- addr = (Elf32_Addr)(module->mem_space + sym->st_value - vstart_addr);
+ addr = (Elf_Addr)(module->mem_space + sym->st_value - vstart_addr);
dlmodule_relocate(module, rel, addr);
}
else if (!linked)
{
- Elf32_Addr addr;
+ Elf_Addr addr;
LOG_D("relocate symbol: %s", strtab + sym->st_name);
/* need to resolve symbol in kernel symbol table */
@@ -172,7 +180,7 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
rel ++;
}
- if (unsolved)
+ if (unsolved)
return -RT_ERROR;
}
@@ -191,13 +199,13 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
if (index != elf_module->e_shnum)
{
int i, count = 0;
- Elf32_Sym *symtab = RT_NULL;
+ Elf_Sym *symtab = RT_NULL;
rt_uint8_t *strtab = RT_NULL;
- symtab = (Elf32_Sym *)((rt_uint8_t *)module_ptr + shdr[index].sh_offset);
+ symtab = (Elf_Sym *)((rt_uint8_t *)module_ptr + shdr[index].sh_offset);
strtab = (rt_uint8_t *)module_ptr + shdr[shdr[index].sh_link].sh_offset;
- for (i = 0; i < shdr[index].sh_size / sizeof(Elf32_Sym); i++)
+ for (i = 0; i < shdr[index].sh_size / sizeof(Elf_Sym); i++)
{
if ((ELF_ST_BIND(symtab[i].st_info) == STB_GLOBAL) &&
(ELF_ST_TYPE(symtab[i].st_info) == STT_FUNC))
@@ -207,7 +215,7 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
module->symtab = (struct rt_module_symtab *)rt_malloc
(count * sizeof(struct rt_module_symtab));
module->nsym = count;
- for (i = 0, count = 0; i < shdr[index].sh_size / sizeof(Elf32_Sym); i++)
+ for (i = 0, count = 0; i < shdr[index].sh_size / sizeof(Elf_Sym); i++)
{
rt_size_t length;
@@ -231,7 +239,7 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
rt_uint32_t flag = 0;
rt_uint16_t priority;
rt_uint32_t stacksize;
- for (i = 0; i < shdr[index].sh_size / sizeof(Elf32_Sym); i++)
+ for (i = 0; i < shdr[index].sh_size / sizeof(Elf_Sym); i++)
{
if (((flag & 0x01) == 0) &&
(rt_strcmp((const char *)(strtab + symtab[i].st_name), "dlmodule_thread_priority") == 0))
@@ -267,8 +275,8 @@ rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_pt
rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module_ptr)
{
- rt_uint32_t index, rodata_addr = 0, bss_addr = 0, data_addr = 0;
- rt_uint32_t module_addr = 0, module_size = 0;
+ rt_ubase_t index, rodata_addr = 0, bss_addr = 0, data_addr = 0;
+ rt_ubase_t module_addr = 0, module_size = 0;
rt_uint8_t *ptr, *strtab, *shstrab;
/* get the ELF image size */
@@ -306,7 +314,7 @@ rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module
module->mem_space = rt_malloc(module_size);
if (module->mem_space == RT_NULL)
{
- rt_kprintf("Module: allocate space failed.\n");
+ LOG_E("Module: allocate space failed.\n");
return -RT_ERROR;
}
module->mem_size = module_size;
@@ -335,7 +343,7 @@ rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module
(rt_uint8_t *)elf_module + shdr[index].sh_offset,
shdr[index].sh_size);
rodata_addr = (rt_uint32_t)ptr;
- LOG_D("load rodata 0x%x, size %d, rodata 0x%x", ptr,
+ LOG_D("load rodata 0x%x, size %d, rodata 0x%x", ptr,
shdr[index].sh_size, *(rt_uint32_t *)data_addr);
ptr += shdr[index].sh_size;
}
@@ -347,7 +355,7 @@ rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module
(rt_uint8_t *)elf_module + shdr[index].sh_offset,
shdr[index].sh_size);
data_addr = (rt_uint32_t)ptr;
- LOG_D("load data 0x%x, size %d, data 0x%x", ptr,
+ LOG_D("load data 0x%x, size %d, data 0x%x", ptr,
shdr[index].sh_size, *(rt_uint32_t *)data_addr);
ptr += shdr[index].sh_size;
}
@@ -367,36 +375,46 @@ rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module
/* handle relocation section */
for (index = 0; index < elf_module->e_shnum; index ++)
{
- rt_uint32_t i, nr_reloc;
- Elf32_Sym *symtab;
- Elf32_Rel *rel;
+ rt_ubase_t i, nr_reloc;
+ Elf_Sym *symtab;
+ Elf_Rel *rel;
+ #if (defined(__arm__) || defined(__i386__) || (__riscv_xlen == 32))
if (!IS_REL(shdr[index]))
continue;
+ #elif (defined(__aarch64__) || defined(__x86_64__) || (__riscv_xlen == 64))
+ if (!IS_RELA(shdr[index]))
+ continue;
+ #endif
+
/* get relocate item */
- rel = (Elf32_Rel *)((rt_uint8_t *)module_ptr + shdr[index].sh_offset);
+ rel = (Elf_Rel *)((rt_uint8_t *)module_ptr + shdr[index].sh_offset);
/* locate .dynsym and .dynstr */
- symtab = (Elf32_Sym *)((rt_uint8_t *)module_ptr +
+ symtab = (Elf_Sym *)((rt_uint8_t *)module_ptr +
shdr[shdr[index].sh_link].sh_offset);
strtab = (rt_uint8_t *)module_ptr +
shdr[shdr[shdr[index].sh_link].sh_link].sh_offset;
shstrab = (rt_uint8_t *)module_ptr +
shdr[elf_module->e_shstrndx].sh_offset;
- nr_reloc = (rt_uint32_t)(shdr[index].sh_size / sizeof(Elf32_Rel));
+ nr_reloc = (rt_uint32_t)(shdr[index].sh_size / sizeof(Elf_Rel));
/* relocate every items */
for (i = 0; i < nr_reloc; i ++)
{
- Elf32_Sym *sym = &symtab[ELF32_R_SYM(rel->r_info)];
+ #if (defined(__arm__) || defined(__i386__) || (__riscv_xlen == 32))
+ Elf_Sym *sym = &symtab[ELF32_R_SYM(rel->r_info)];
+ #elif (defined(__aarch64__) || defined(__x86_64__) || (__riscv_xlen == 64))
+ Elf_Sym *sym = &symtab[ELF64_R_SYM(rel->r_info)];
+ #endif
LOG_D("relocate symbol: %s", strtab + sym->st_name);
if (sym->st_shndx != STN_UNDEF)
{
- Elf32_Addr addr = 0;
-
+ Elf_Addr addr = 0;
+
if ((ELF_ST_TYPE(sym->st_info) == STT_SECTION) ||
(ELF_ST_TYPE(sym->st_info) == STT_OBJECT))
{
@@ -405,28 +423,28 @@ rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module
{
/* relocate rodata section */
LOG_D("rodata");
- addr = (Elf32_Addr)(rodata_addr + sym->st_value);
+ addr = (Elf_Addr)(rodata_addr + sym->st_value);
}
else if (rt_strncmp((const char *)
(shstrab + shdr[sym->st_shndx].sh_name), ELF_BSS, 5) == 0)
{
/* relocate bss section */
LOG_D("bss");
- addr = (Elf32_Addr)bss_addr + sym->st_value;
+ addr = (Elf_Addr)bss_addr + sym->st_value;
}
else if (rt_strncmp((const char *)(shstrab + shdr[sym->st_shndx].sh_name),
ELF_DATA, 6) == 0)
{
/* relocate data section */
LOG_D("data");
- addr = (Elf32_Addr)data_addr + sym->st_value;
+ addr = (Elf_Addr)data_addr + sym->st_value;
}
if (addr != 0) dlmodule_relocate(module, rel, addr);
}
else if (ELF_ST_TYPE(sym->st_info) == STT_FUNC)
{
- addr = (Elf32_Addr)((rt_uint8_t *) module->mem_space - module_addr + sym->st_value);
+ addr = (Elf_Addr)((rt_uint8_t *) module->mem_space - module_addr + sym->st_value);
/* relocate function */
dlmodule_relocate(module, rel, addr);
@@ -436,14 +454,14 @@ rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module
{
/* relocate function */
dlmodule_relocate(module, rel,
- (Elf32_Addr)((rt_uint8_t *)
+ (Elf_Addr)((rt_uint8_t *)
module->mem_space
- module_addr
+ sym->st_value));
}
else
{
- Elf32_Addr addr;
+ Elf_Addr addr;
if (ELF32_R_TYPE(rel->r_info) != R_ARM_V4BX)
{
@@ -451,7 +469,7 @@ rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module
/* need to resolve symbol in kernel symbol table */
addr = dlmodule_symbol_find((const char *)(strtab + sym->st_name));
- if (addr != (Elf32_Addr)RT_NULL)
+ if (addr != (Elf_Addr)RT_NULL)
{
dlmodule_relocate(module, rel, addr);
LOG_D("symbol addr 0x%x", addr);
@@ -462,7 +480,7 @@ rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module
}
else
{
- addr = (Elf32_Addr)((rt_uint8_t *) module->mem_space - module_addr + sym->st_value);
+ addr = (Elf_Addr)((rt_uint8_t *) module->mem_space - module_addr + sym->st_value);
dlmodule_relocate(module, rel, addr);
}
}
diff --git a/components/libc/libdl/dlelf.h b/components/libc/libdl/dlelf.h
index 014ebe85c8..540fe2c8aa 100644
--- a/components/libc/libdl/dlelf.h
+++ b/components/libc/libdl/dlelf.h
@@ -1,11 +1,12 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
- *
+ *
* Change Logs:
* Date Author Notes
* 2018/08/29 Bernard first version
+ * 2021/04/23 chunyexixiaoyu distinguish 32-bit and 64-bit
*/
#ifndef DL_ELF_H__
@@ -19,6 +20,21 @@ typedef rt_int32_t Elf32_Sword; /* Signed large integer */
typedef rt_uint32_t Elf32_Word; /* Unsigned large integer */
typedef rt_uint16_t Elf32_Half; /* Unsigned medium integer */
+typedef rt_uint64_t Elf64_Addr;
+typedef rt_uint16_t Elf64_Half;
+typedef rt_int16_t Elf64_SHalf;
+typedef rt_uint64_t Elf64_Off;
+typedef rt_int32_t Elf64_Sword;
+typedef rt_uint32_t Elf64_Word;
+typedef rt_uint64_t Elf64_Xword;
+typedef rt_int64_t Elf64_Sxword;
+typedef uint16_t Elf64_Section;
+
+
+
+
+
+
/* e_ident[] magic number */
#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
#define ELFMAG1 'E' /* e_ident[EI_MAG1] */
@@ -75,6 +91,25 @@ typedef struct elfhdr
header string table" entry offset */
} Elf32_Ehdr;
+
+typedef struct elf64_hdr {
+ unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
+ Elf64_Half e_type; /* object file type */
+ Elf64_Half e_machine; /* machine */
+ Elf64_Word e_version; /* object file version */
+ Elf64_Addr e_entry; /* virtual entry point */
+ Elf64_Off e_phoff; /* program header table offset */
+ Elf64_Off e_shoff; /* section header table offset */
+ Elf64_Word e_flags; /* processor-specific flags */
+ Elf64_Half e_ehsize; /* ELF header size */
+ Elf64_Half e_phentsize; /* program header entry size */
+ Elf64_Half e_phnum; /* number of program header entries */
+ Elf64_Half e_shentsize; /* section header entry size */
+ Elf64_Half e_shnum; /* number of section header entries */
+ Elf64_Half e_shstrndx; /* section header table's "section
+ header string table" entry offset */
+} Elf64_Ehdr;
+
/* Section Header */
typedef struct
{
@@ -91,6 +126,21 @@ typedef struct
Elf32_Word sh_entsize; /* section entry size */
} Elf32_Shdr;
+typedef struct
+{
+ Elf64_Word sh_name; /* Section name (string tbl index) */
+ Elf64_Word sh_type; /* Section type */
+ Elf64_Xword sh_flags; /* Section flags */
+ Elf64_Addr sh_addr; /* Section virtual addr at execution */
+ Elf64_Off sh_offset; /* Section file offset */
+ Elf64_Xword sh_size; /* Section size in bytes */
+ Elf64_Word sh_link; /* Link to another section */
+ Elf64_Word sh_info; /* Additional section information */
+ Elf64_Xword sh_addralign; /* Section alignment */
+ Elf64_Xword sh_entsize; /* Entry size if section holds table */
+} Elf64_Shdr;
+
+
/* Section names */
#define ELF_BSS ".bss" /* uninitialized data */
#define ELF_DATA ".data" /* initialized data */
@@ -126,6 +176,19 @@ typedef struct elf32_sym
Elf32_Half st_shndx; /* section header index */
} Elf32_Sym;
+
+typedef struct
+{
+ Elf64_Word st_name; /* Symbol name (string tbl index) */
+ unsigned char st_info; /* Symbol type and binding */
+ unsigned char st_other; /* Symbol visibility */
+ Elf64_Section st_shndx; /* Section index */
+ Elf64_Addr st_value; /* Symbol value */
+ Elf64_Xword st_size; /* Symbol size */
+} Elf64_Sym;
+
+
+
#define STB_LOCAL 0 /* BIND */
#define STB_GLOBAL 1
#define STB_WEAK 2
@@ -160,6 +223,12 @@ typedef struct
Elf32_Word r_info; /* symbol table index and type */
} Elf32_Rel;
+typedef struct
+{
+ Elf64_Addr r_offset; /* Address */
+ Elf64_Xword r_info; /* Relocation type and symbol index */
+} Elf64_Rel;
+
/* Relocation entry with explicit addend */
typedef struct
{
@@ -168,11 +237,24 @@ typedef struct
Elf32_Sword r_addend;
} Elf32_Rela;
+typedef struct
+{
+ Elf64_Addr r_offset; /* Address */
+ Elf64_Xword r_info; /* Relocation type and symbol index */
+ Elf64_Sxword r_addend; /* Addend */
+} Elf64_Rela;
+
/* Extract relocation info - r_info */
#define ELF32_R_SYM(i) ((i) >> 8)
#define ELF32_R_TYPE(i) ((unsigned char) (i))
#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
+
+
+#define ELF64_R_SYM(i) ((i) >> 32)
+#define ELF64_R_TYPE(i) ((i) & 0xffffffff)
+#define ELF64_R_INFO(sym,type) ((((Elf64_Xword) (sym)) << 32) + (type))
+
/*
* Relocation type for arm
*/
@@ -219,6 +301,23 @@ typedef struct
Elf32_Word p_align; /* memory alignment */
} Elf32_Phdr;
+
+typedef struct
+{
+ Elf64_Word p_type; /* Segment type */
+ Elf64_Word p_flags; /* Segment flags */
+ Elf64_Off p_offset; /* Segment file offset */
+ Elf64_Addr p_vaddr; /* Segment virtual address */
+ Elf64_Addr p_paddr; /* Segment physical address */
+ Elf64_Xword p_filesz; /* Segment size in file */
+ Elf64_Xword p_memsz; /* Segment size in memory */
+ Elf64_Xword p_align; /* Segment alignment */
+} Elf64_Phdr;
+
+
+
+
+
/* p_type */
#define PT_NULL 0
#define PT_LOAD 1
@@ -273,13 +372,27 @@ typedef struct
#define IS_AX(s) ((s.sh_flags & SHF_ALLOC) && (s.sh_flags & SHF_EXECINSTR))
#define IS_AW(s) ((s.sh_flags & SHF_ALLOC) && (s.sh_flags & SHF_WRITE))
+#if (defined(__arm__) || defined(__i386__) || (__riscv_xlen == 32))
#define elf_module ((Elf32_Ehdr *)module_ptr)
#define shdr ((Elf32_Shdr *)((rt_uint8_t *)module_ptr + elf_module->e_shoff))
#define phdr ((Elf32_Phdr *)((rt_uint8_t *)module_ptr + elf_module->e_phoff))
+typedef Elf32_Sym Elf_Sym;
+typedef Elf32_Rel Elf_Rel;
+typedef Elf32_Addr Elf_Addr;
+#elif (defined(__aarch64__) || defined(__x86_64__) || (__riscv_xlen == 64))
+#define elf_module ((Elf64_Ehdr *)module_ptr)
+#define shdr ((Elf64_Shdr *)((rt_uint8_t *)module_ptr + elf_module->e_shoff))
+#define phdr ((Elf64_Phdr *)((rt_uint8_t *)module_ptr + elf_module->e_phoff))
+
+typedef Elf64_Sym Elf_Sym;
+typedef Elf64_Rela Elf_Rel;
+typedef Elf64_Addr Elf_Addr;
+#endif
+int dlmodule_relocate(struct rt_dlmodule *module, Elf_Rel *rel, Elf_Addr sym_val);
rt_err_t dlmodule_load_shared_object(struct rt_dlmodule* module, void *module_ptr);
rt_err_t dlmodule_load_relocated_object(struct rt_dlmodule* module, void *module_ptr);
-int dlmodule_relocate(struct rt_dlmodule *module, Elf32_Rel *rel, Elf32_Addr sym_val);
+
#endif
diff --git a/components/libc/libdl/dlerror.c b/components/libc/libdl/dlerror.c
index ad9b630e4c..de948eb16b 100644
--- a/components/libc/libdl/dlerror.c
+++ b/components/libc/libdl/dlerror.c
@@ -1,8 +1,8 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
- *
+ *
* Change Logs:
* Date Author Notes
* 2010-11-17 yi.qiu first version
@@ -13,6 +13,6 @@
const char *dlerror(void)
{
- return "TODO";
+ return "TODO";
}
RTM_EXPORT(dlerror)
diff --git a/components/libc/libdl/dlfcn.h b/components/libc/libdl/dlfcn.h
index 55273a41eb..f5c9063f2f 100644
--- a/components/libc/libdl/dlfcn.h
+++ b/components/libc/libdl/dlfcn.h
@@ -1,8 +1,8 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
- *
+ *
* Change Logs:
* Date Author Notes
* 2010-11-17 yi.qiu first version
diff --git a/components/libc/libdl/dlmodule.c b/components/libc/libdl/dlmodule.c
index 314cf52709..044c05a994 100644
--- a/components/libc/libdl/dlmodule.c
+++ b/components/libc/libdl/dlmodule.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -464,7 +464,7 @@ struct rt_dlmodule* dlmodule_load(const char* filename)
}
/* check ELF class */
- if (elf_module->e_ident[EI_CLASS] != ELFCLASS32)
+ if ((elf_module->e_ident[EI_CLASS] != ELFCLASS32)&&(elf_module->e_ident[EI_CLASS] != ELFCLASS64))
{
rt_kprintf("Module: ELF class error\n");
goto __exit;
@@ -547,7 +547,7 @@ struct rt_dlmodule* dlmodule_exec(const char* pgname, const char* cmd, int cmd_s
if (module->priority > RT_THREAD_PRIORITY_MAX) module->priority = RT_THREAD_PRIORITY_MAX - 1;
if (module->stack_size < 2048 || module->stack_size > (1024 * 32)) module->stack_size = 2048;
- tid = rt_thread_create(module->parent.name, _dlmodule_thread_entry, (void*)module,
+ tid = rt_thread_create(module->parent.name, _dlmodule_thread_entry, (void*)module,
module->stack_size, module->priority, 10);
if (tid)
{
@@ -724,7 +724,7 @@ struct rt_dlmodule* dlmodule_exec_custom(const char* pgname, const char* cmd, in
if (module->priority > RT_THREAD_PRIORITY_MAX) module->priority = RT_THREAD_PRIORITY_MAX - 1;
if (module->stack_size < 2048 || module->stack_size > (1024 * 32)) module->stack_size = 2048;
- tid = rt_thread_create(module->parent.name, _dlmodule_thread_entry, (void*)module,
+ tid = rt_thread_create(module->parent.name, _dlmodule_thread_entry, (void*)module,
module->stack_size, module->priority, 10);
if (tid)
{
@@ -758,7 +758,7 @@ void dlmodule_exit(int ret_code)
rt_enter_critical();
/* module is not running */
- if (module->stat != RT_DLMODULE_STAT_RUNNING)
+ if (module->stat != RT_DLMODULE_STAT_RUNNING)
{
/* restore scheduling */
rt_exit_critical();
diff --git a/components/libc/libdl/dlmodule.h b/components/libc/libdl/dlmodule.h
index b366c7603e..183faca159 100644
--- a/components/libc/libdl/dlmodule.h
+++ b/components/libc/libdl/dlmodule.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/libdl/dlopen.c b/components/libc/libdl/dlopen.c
index a8202ec607..bcb57d78f0 100644
--- a/components/libc/libdl/dlopen.c
+++ b/components/libc/libdl/dlopen.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -43,12 +43,12 @@ void* dlopen(const char *filename, int flags)
/* find in module list */
module = dlmodule_find(fullpath);
- if(module != RT_NULL)
+ if(module != RT_NULL)
{
rt_exit_critical();
module->nref++;
}
- else
+ else
{
rt_exit_critical();
module = dlmodule_load(fullpath);
diff --git a/components/libc/libdl/dlsym.c b/components/libc/libdl/dlsym.c
index ed0f183d83..f7c1c901fd 100644
--- a/components/libc/libdl/dlsym.c
+++ b/components/libc/libdl/dlsym.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -17,7 +17,7 @@ void* dlsym(void *handle, const char* symbol)
{
int i;
struct rt_dlmodule *module;
-
+
RT_ASSERT(handle != RT_NULL);
module = (struct rt_dlmodule *)handle;
diff --git a/components/libc/mmap/posix_mmap.c b/components/libc/mmap/posix_mmap.c
index a16ace8306..e68b82e640 100644
--- a/components/libc/mmap/posix_mmap.c
+++ b/components/libc/mmap/posix_mmap.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/pthreads/mqueue.c b/components/libc/pthreads/mqueue.c
index 003b49b9a0..1af0ab2919 100644
--- a/components/libc/pthreads/mqueue.c
+++ b/components/libc/pthreads/mqueue.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/pthreads/mqueue.h b/components/libc/pthreads/mqueue.h
index 5cadde3ae8..5152bfad29 100644
--- a/components/libc/pthreads/mqueue.h
+++ b/components/libc/pthreads/mqueue.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/pthreads/posix_types.h b/components/libc/pthreads/posix_types.h
index ca20464bb5..942657ef39 100644
--- a/components/libc/pthreads/posix_types.h
+++ b/components/libc/pthreads/posix_types.h
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
- * 2013-12-23 Bernard Add the checking for ESHUTDOWN
+ * 2013-12-23 Bernard Add the checking for ESHUTDOWN
*/
#ifndef __POSIX_TYPES_H__
@@ -19,16 +19,9 @@
#include <sys/types.h>
#include <sys/time.h>
-
-/* errno for Keil MDK */
-#if defined(__CC_ARM) || defined(__IAR_SYSTEMS_ICC__)
-#include <sys/errno.h>
-#include <sys/unistd.h>
-#else
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
-#endif
#endif
diff --git a/components/libc/pthreads/pthread.c b/components/libc/pthreads/pthread.c
index 19a511b45b..79104d1fd5 100644
--- a/components/libc/pthreads/pthread.c
+++ b/components/libc/pthreads/pthread.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -13,6 +13,7 @@
#include <rthw.h>
#include <pthread.h>
#include <sched.h>
+#include <sys/time.h>
#include "pthread_internal.h"
RT_DEFINE_SPINLOCK(pth_lock);
@@ -200,7 +201,7 @@ int pthread_create(pthread_t *pid,
/* allocate posix thread data */
pth_id = _pthread_data_create();
- if (pth_id == PTHREAD_NUM_MAX)
+ if (pth_id == PTHREAD_NUM_MAX)
{
ret = ENOMEM;
goto __exit;
@@ -208,6 +209,8 @@ int pthread_create(pthread_t *pid,
/* get pthread data */
ptd = _pthread_get_data(pth_id);
+ RT_ASSERT(ptd != RT_NULL);
+
if (attr != RT_NULL)
{
ptd->attr = *attr;
@@ -298,6 +301,12 @@ int pthread_detach(pthread_t thread)
{
int ret = 0;
_pthread_data_t *ptd = _pthread_get_data(thread);
+ if (ptd == RT_NULL)
+ {
+ /* invalid pthread id */
+ ret = EINVAL;
+ goto __exit;
+ }
rt_enter_critical();
if (ptd->attr.detachstate == PTHREAD_CREATE_DETACHED)
@@ -359,6 +368,12 @@ int pthread_join(pthread_t thread, void **value_ptr)
rt_err_t result;
ptd = _pthread_get_data(thread);
+
+ if (ptd == RT_NULL)
+ {
+ return EINVAL; /* invalid pthread id */
+ }
+
if (ptd && ptd->tid == rt_thread_self())
{
/* join self */
@@ -366,7 +381,9 @@ int pthread_join(pthread_t thread, void **value_ptr)
}
if (ptd->attr.detachstate == PTHREAD_CREATE_DETACHED)
+ {
return EINVAL; /* join on a detached pthread */
+ }
result = rt_sem_take(ptd->joinable_sem, RT_WAITING_FOREVER);
if (result == RT_EOK)
@@ -661,7 +678,10 @@ int pthread_cancel(pthread_t thread)
/* get posix thread data */
ptd = _pthread_get_data(thread);
- RT_ASSERT(ptd != RT_NULL);
+ if (ptd == RT_NULL)
+ {
+ return EINVAL;
+ }
/* cancel self */
if (ptd->tid == rt_thread_self())
@@ -687,4 +707,3 @@ int pthread_cancel(pthread_t thread)
return 0;
}
RTM_EXPORT(pthread_cancel);
-
diff --git a/components/libc/pthreads/pthread.h b/components/libc/pthreads/pthread.h
index 7bb72b726c..8639c1604b 100644
--- a/components/libc/pthreads/pthread.h
+++ b/components/libc/pthreads/pthread.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -161,7 +161,7 @@ int pthread_attr_getguardsize(pthread_attr_t const *attr, size_t *guard_size);
int pthread_attr_setscope(pthread_attr_t *attr, int scope);
int pthread_attr_getscope(pthread_attr_t const *attr);
int pthread_system_init(void);
-int pthread_create (pthread_t *tid, const pthread_attr_t *attr,
+int pthread_create (pthread_t *tid, const pthread_attr_t *attr,
void *(*start) (void *), void *arg);
int pthread_detach (pthread_t thread);
diff --git a/components/libc/pthreads/pthread_attr.c b/components/libc/pthreads/pthread_attr.c
index 2294599bf3..4aedf5a90d 100644
--- a/components/libc/pthreads/pthread_attr.c
+++ b/components/libc/pthreads/pthread_attr.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -16,7 +16,7 @@
#define DEFAULT_STACK_SIZE 2048
#define DEFAULT_PRIORITY (RT_THREAD_PRIORITY_MAX/2 + RT_THREAD_PRIORITY_MAX/4)
-const pthread_attr_t pthread_default_attr =
+const pthread_attr_t pthread_default_attr =
{
0, /* stack base */
DEFAULT_STACK_SIZE, /* stack size */
diff --git a/components/libc/pthreads/pthread_barrier.c b/components/libc/pthreads/pthread_barrier.c
index d76fe7f13f..1a5b7fa3f9 100644
--- a/components/libc/pthreads/pthread_barrier.c
+++ b/components/libc/pthreads/pthread_barrier.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/pthreads/pthread_cond.c b/components/libc/pthreads/pthread_cond.c
index 38dc697469..59c271bf6e 100644
--- a/components/libc/pthreads/pthread_cond.c
+++ b/components/libc/pthreads/pthread_cond.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -84,10 +84,10 @@ int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
rt_snprintf(cond_name, sizeof(cond_name), "cond%02d", cond_num++);
- if (attr == RT_NULL) /* use default value */
- cond->attr = PTHREAD_PROCESS_PRIVATE;
- else
- cond->attr = *attr;
+ if (attr == RT_NULL) /* use default value */
+ cond->attr = PTHREAD_PROCESS_PRIVATE;
+ else
+ cond->attr = *attr;
result = rt_sem_init(&cond->sem, cond_name, 0, RT_IPC_FLAG_FIFO);
if (result != RT_EOK)
diff --git a/components/libc/pthreads/pthread_internal.h b/components/libc/pthreads/pthread_internal.h
index a6706ca091..1fce29f636 100644
--- a/components/libc/pthreads/pthread_internal.h
+++ b/components/libc/pthreads/pthread_internal.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -13,6 +13,7 @@
#include <rtthread.h>
#include <pthread.h>
+#include <sys/time.h>
struct _pthread_cleanup
{
@@ -62,8 +63,6 @@ typedef struct _pthread_data _pthread_data_t;
_pthread_data_t *_pthread_get_data(pthread_t thread);
-int clock_time_to_tick(const struct timespec *time);
-
void posix_mq_system_init(void);
void posix_sem_system_init(void);
void pthread_key_system_init(void);
diff --git a/components/libc/pthreads/pthread_mutex.c b/components/libc/pthreads/pthread_mutex.c
index 8f96531782..a681380b11 100644
--- a/components/libc/pthreads/pthread_mutex.c
+++ b/components/libc/pthreads/pthread_mutex.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -211,7 +211,7 @@ int pthread_mutex_unlock(pthread_mutex_t *mutex)
result = rt_mutex_release(&(mutex->lock));
if (result == RT_EOK)
return 0;
-
+
return EINVAL;
}
RTM_EXPORT(pthread_mutex_unlock);
diff --git a/components/libc/pthreads/pthread_rwlock.c b/components/libc/pthreads/pthread_rwlock.c
index 64a0e221b4..1c2fe19f5f 100644
--- a/components/libc/pthreads/pthread_rwlock.c
+++ b/components/libc/pthreads/pthread_rwlock.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -60,7 +60,7 @@ int pthread_rwlock_init(pthread_rwlock_t *rwlock,
pthread_mutex_init(&(rwlock->rw_mutex), NULL);
pthread_cond_init(&(rwlock->rw_condreaders), NULL);
pthread_cond_init(&(rwlock->rw_condwriters), NULL);
-
+
rwlock->rw_nwaitwriters = 0;
rwlock->rw_nwaitreaders = 0;
rwlock->rw_refcount = 0;
@@ -117,7 +117,7 @@ int pthread_rwlock_destroy (pthread_rwlock_t *rwlock)
pthread_mutex_unlock(&rwlock->rw_mutex);
if (result == 0)
pthread_mutex_destroy(&rwlock->rw_mutex);
-
+
return result;
}
RTM_EXPORT(pthread_rwlock_destroy);
@@ -234,7 +234,7 @@ int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock,
result = pthread_cond_timedwait(&rwlock->rw_condwriters, &rwlock->rw_mutex, abstime);
/* rw_mutex should have been taken again when returned from waiting */
rwlock->rw_nwaitwriters--;
-
+
if (result != 0)
break;
}
@@ -324,7 +324,7 @@ int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
result = pthread_cond_wait(&rwlock->rw_condwriters, &rwlock->rw_mutex);
/* rw_mutex should have been taken again when returned from waiting */
rwlock->rw_nwaitwriters--;
-
+
if (result != 0)
break;
}
diff --git a/components/libc/pthreads/pthread_spin.c b/components/libc/pthreads/pthread_spin.c
index b31f4f6393..3f3dc1593c 100644
--- a/components/libc/pthreads/pthread_spin.c
+++ b/components/libc/pthreads/pthread_spin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/pthreads/pthread_tls.c b/components/libc/pthreads/pthread_tls.c
index 4b97d796d9..d48df7f2dd 100644
--- a/components/libc/pthreads/pthread_tls.c
+++ b/components/libc/pthreads/pthread_tls.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/pthreads/sched.c b/components/libc/pthreads/sched.c
index a1bf50985e..5f2a53c01f 100644
--- a/components/libc/pthreads/sched.c
+++ b/components/libc/pthreads/sched.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/pthreads/sched.h b/components/libc/pthreads/sched.h
index dbaf66edc2..07e2c0c6a8 100644
--- a/components/libc/pthreads/sched.h
+++ b/components/libc/pthreads/sched.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/pthreads/semaphore.c b/components/libc/pthreads/semaphore.c
index 2ed93e99b6..398cdf1f49 100644
--- a/components/libc/pthreads/semaphore.c
+++ b/components/libc/pthreads/semaphore.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/pthreads/semaphore.h b/components/libc/pthreads/semaphore.h
index d135ae9261..872226e385 100644
--- a/components/libc/pthreads/semaphore.h
+++ b/components/libc/pthreads/semaphore.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/signal/posix_signal.c b/components/libc/signal/posix_signal.c
index c0dd90e637..b06fe12685 100644
--- a/components/libc/signal/posix_signal.c
+++ b/components/libc/signal/posix_signal.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/signal/posix_signal.h b/components/libc/signal/posix_signal.h
index 896d6b6da4..fa8ad38fa6 100644
--- a/components/libc/signal/posix_signal.h
+++ b/components/libc/signal/posix_signal.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/termios/posix_termios.c b/components/libc/termios/posix_termios.c
index 9c736c3184..01ba010c86 100644
--- a/components/libc/termios/posix_termios.c
+++ b/components/libc/termios/posix_termios.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/termios/posix_termios.h b/components/libc/termios/posix_termios.h
index c61191b7dc..5bd1999b0a 100644
--- a/components/libc/termios/posix_termios.h
+++ b/components/libc/termios/posix_termios.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/time/SConscript b/components/libc/time/SConscript
deleted file mode 100644
index f7e6f7e8e9..0000000000
--- a/components/libc/time/SConscript
+++ /dev/null
@@ -1,12 +0,0 @@
-# RT-Thread building script for component
-
-from building import *
-
-cwd = GetCurrentDir()
-src = Glob('*.c') + Glob('*.cpp')
-CPPPATH = [cwd]
-
-group = DefineGroup('libc', src,
- depend = ['RT_USING_PTHREADS'], CPPPATH = CPPPATH)
-
-Return('group')
diff --git a/components/libc/time/clock_time.c b/components/libc/time/clock_time.c
deleted file mode 100644
index 83b3b916ca..0000000000
--- a/components/libc/time/clock_time.c
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2012-12-08 Bernard fix the issue of _timevalue.tv_usec initialization,
- * which found by Rob <[email protected]>
- */
-
-#include <rtthread.h>
-#include <pthread.h>
-
-#include "clock_time.h"
-
-static struct timeval _timevalue;
-int clock_time_system_init()
-{
- time_t time;
- rt_tick_t tick;
- rt_device_t device;
-
- time = 0;
- device = rt_device_find("rtc");
- if (device != RT_NULL)
- {
- /* get realtime seconds */
- rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
- }
-
- /* get tick */
- tick = rt_tick_get();
-
- _timevalue.tv_usec = (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK;
- _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1;
-
- return 0;
-}
-INIT_COMPONENT_EXPORT(clock_time_system_init);
-
-int clock_time_to_tick(const struct timespec *time)
-{
- int tick;
- int nsecond, second;
- struct timespec tp;
-
- RT_ASSERT(time != RT_NULL);
-
- tick = RT_WAITING_FOREVER;
- if (time != NULL)
- {
- /* get current tp */
- clock_gettime(CLOCK_REALTIME, &tp);
-
- if ((time->tv_nsec - tp.tv_nsec) < 0)
- {
- nsecond = NANOSECOND_PER_SECOND - (tp.tv_nsec - time->tv_nsec);
- second = time->tv_sec - tp.tv_sec - 1;
- }
- else
- {
- nsecond = time->tv_nsec - tp.tv_nsec;
- second = time->tv_sec - tp.tv_sec;
- }
-
- tick = second * RT_TICK_PER_SECOND + nsecond * RT_TICK_PER_SECOND / NANOSECOND_PER_SECOND;
- if (tick < 0) tick = 0;
- }
-
- return tick;
-}
-RTM_EXPORT(clock_time_to_tick);
-
-int clock_getres(clockid_t clockid, struct timespec *res)
-{
- int ret = 0;
-
- if (res == RT_NULL)
- {
- rt_set_errno(EINVAL);
- return -1;
- }
-
- switch (clockid)
- {
- case CLOCK_REALTIME:
- res->tv_sec = 0;
- res->tv_nsec = NANOSECOND_PER_SECOND/RT_TICK_PER_SECOND;
- break;
-
-#ifdef RT_USING_CPUTIME
- case CLOCK_CPUTIME_ID:
- res->tv_sec = 0;
- res->tv_nsec = clock_cpu_getres();
- break;
-#endif
-
- default:
- ret = -1;
- rt_set_errno(EINVAL);
- break;
- }
-
- return ret;
-}
-RTM_EXPORT(clock_getres);
-
-int clock_gettime(clockid_t clockid, struct timespec *tp)
-{
- int ret = 0;
-
- if (tp == RT_NULL)
- {
- rt_set_errno(EINVAL);
- return -1;
- }
-
- switch (clockid)
- {
- case CLOCK_REALTIME:
- {
- /* get tick */
- int tick = rt_tick_get();
-
- 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;
- }
- break;
-
-#ifdef RT_USING_CPUTIME
- case CLOCK_CPUTIME_ID:
- {
- float unit = 0;
- long long cpu_tick;
-
- unit = clock_cpu_getres();
- cpu_tick = clock_cpu_gettime();
-
- tp->tv_sec = ((int)(cpu_tick * unit)) / NANOSECOND_PER_SECOND;
- tp->tv_nsec = ((int)(cpu_tick * unit)) % NANOSECOND_PER_SECOND;
- }
- break;
-#endif
- default:
- rt_set_errno(EINVAL);
- ret = -1;
- }
-
- return ret;
-}
-RTM_EXPORT(clock_gettime);
-
-int clock_settime(clockid_t clockid, const struct timespec *tp)
-{
- int second;
- rt_tick_t tick;
- rt_device_t device;
-
- 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();
-
- /* 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;
-
- /* 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);
- }
- else
- return -1;
-
- return 0;
-}
-RTM_EXPORT(clock_settime);
diff --git a/components/libc/time/clock_time.h b/components/libc/time/clock_time.h
deleted file mode 100644
index 16b2306f4b..0000000000
--- a/components/libc/time/clock_time.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017-12-31 Bernard the first version
- */
-
-#ifndef CLOCK_TIME_H__
-#define CLOCK_TIME_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* posix clock and timer */
-#define MILLISECOND_PER_SECOND 1000UL
-#define MICROSECOND_PER_SECOND 1000000UL
-#define NANOSECOND_PER_SECOND 1000000000UL
-
-#define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND)
-#define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND)
-#define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND)
-
-#ifndef CLOCK_REALTIME
-#define CLOCK_REALTIME 1
-#endif
-
-#define CLOCK_CPUTIME_ID 2
-
-#ifndef CLOCK_PROCESS_CPUTIME_ID
-#define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID
-#endif
-#ifndef CLOCK_THREAD_CPUTIME_ID
-#define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID
-#endif
-
-#ifndef CLOCK_MONOTONIC
-#define CLOCK_MONOTONIC 4
-#endif
-
-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);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/components/libc/time/posix_sleep.c b/components/libc/time/posix_sleep.c
deleted file mode 100644
index e50bda7d4a..0000000000
--- a/components/libc/time/posix_sleep.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2020-12-16 Meco Man add usleep
- */
-#include <rtthread.h>
-#include <rthw.h>
-#include <unistd.h>
-
-unsigned int sleep(unsigned int seconds)
-{
- rt_tick_t delta_tick;
-
- delta_tick = rt_tick_get();
- rt_thread_delay(seconds * RT_TICK_PER_SECOND);
- delta_tick = rt_tick_get() - delta_tick;
-
- return seconds - delta_tick/RT_TICK_PER_SECOND;
-}
-
-int usleep(useconds_t usec)
-{
- rt_thread_mdelay(usec / 1000u);
- rt_hw_us_delay(usec % 1000u);
- return 0;
-}