diff options
| author | 192.168.1.134 <[email protected]> | 2021-12-09 19:18:24 +0800 |
|---|---|---|
| committer | 192.168.1.134 <[email protected]> | 2021-12-09 19:18:24 +0800 |
| commit | 6378f95f00fd51410d2715da55d728d4a40494de (patch) | |
| tree | bb46a565875d538189e1c1dfc9b1cfddf6862a92 /components/libc/compilers | |
| parent | d6b05287bbeaf9369546009e5af445f350b97fe9 (diff) | |
| parent | 462f093cbd7531098de3b7aadb5f8d5f1b99b4a9 (diff) | |
Merge branch 'master' of https://github.com/RT-Thread/rt-thread
Diffstat (limited to 'components/libc/compilers')
20 files changed, 325 insertions, 234 deletions
diff --git a/components/libc/compilers/armlibc/mem_std.c b/components/libc/compilers/armlibc/mem_std.c index fbfd17eee1..f8a81c7873 100644 --- a/components/libc/compilers/armlibc/mem_std.c +++ b/components/libc/compilers/armlibc/mem_std.c @@ -4,40 +4,68 @@ * SPDX-License-Identifier: Apache-2.0 * * Change Logs: - * 2014-08-03 bernard Add file header. + * Date Author Notes + * 2014-08-03 bernard Add file header + * 2021-11-13 Meco Man implement no-heap warning */ #include <rtthread.h> #include <stddef.h> -#ifdef RT_USING_HEAP +#ifndef RT_USING_HEAP +#define DBG_TAG "armlibc.mem" +#define DBG_LVL DBG_INFO +#include <rtdbg.h> + +#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\ + RT_ASSERT(0);\ + }while(0) +#endif /* RT_USING_HEAP */ #ifdef __CC_ARM /* avoid the heap and heap-using library functions supplied by arm */ #pragma import(__use_no_heap) -#endif +#endif /* __CC_ARM */ void *malloc(size_t n) { +#ifdef RT_USING_HEAP return rt_malloc(n); +#else + _NO_HEAP_ERROR(); + return RT_NULL; +#endif } RTM_EXPORT(malloc); void *realloc(void *rmem, size_t newsize) { +#ifdef RT_USING_HEAP return rt_realloc(rmem, newsize); +#else + _NO_HEAP_ERROR(); + return RT_NULL; +#endif } RTM_EXPORT(realloc); void *calloc(size_t nelem, size_t elsize) { +#ifdef RT_USING_HEAP return rt_calloc(nelem, elsize); +#else + _NO_HEAP_ERROR(); + return RT_NULL; +#endif } RTM_EXPORT(calloc); void free(void *rmem) { +#ifdef RT_USING_HEAP rt_free(rmem); +#else + _NO_HEAP_ERROR(); +#endif } RTM_EXPORT(free); -#endif diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index 62657a4b64..0e965d62af 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -21,9 +21,9 @@ #include <fcntl.h> #include <unistd.h> #include <sys/stat.h> -#ifdef RT_USING_POSIX_STDIO +#ifdef RT_USING_POSIX_DEVIO #include "libc.h" -#endif +#endif /* RT_USING_POSIX_DEVIO */ #define DBG_TAG "armlibc.syscalls" #define DBG_LVL DBG_INFO @@ -33,7 +33,7 @@ __asm(".global __use_no_semihosting\n\t"); #else #pragma import(__use_no_semihosting_swi) -#endif +#endif /* __CLANG_ARM */ /* Standard IO device handles. */ #define STDIN 0 @@ -55,10 +55,10 @@ const char __stderr_name[] = "STDERR"; */ FILEHANDLE _sys_open(const char *name, int openmode) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int fd; int mode = O_RDONLY; -#endif +#endif /* DFS_USING_POSIX */ /* Register standard Input Output devices. */ if (strcmp(name, __stdin_name) == 0) @@ -68,7 +68,7 @@ FILEHANDLE _sys_open(const char *name, int openmode) if (strcmp(name, __stderr_name) == 0) return (STDERR); -#ifndef RT_USING_POSIX +#ifndef DFS_USING_POSIX return 0; /* error */ #else /* Correct openmode from fopen to open */ @@ -102,19 +102,19 @@ FILEHANDLE _sys_open(const char *name, int openmode) return 0; /* error */ else return fd; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } int _sys_close(FILEHANDLE fh) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX if (fh <= STDERR) return 0; /* error */ return close(fh); #else return 0; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } /* @@ -144,78 +144,93 @@ int _sys_close(FILEHANDLE fh) */ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) { -#ifdef RT_USING_POSIX_STDIO +#ifdef DFS_USING_POSIX int size; if (fh == STDIN) { +#ifdef RT_USING_POSIX_DEVIO if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard output before initializing libc"); - return 0; + return 0; /* error, but keep going */ } size = read(STDIN_FILENO, buf, len); - return len - size; + return len - size; /* success */ +#else + return 0; /* error */ +#endif /* RT_USING_POSIX_DEVIO */ } - else if ((fh == STDOUT) || (fh == STDERR)) + else if (fh == STDOUT || fh == STDERR) { - return 0; /* error */ + return -1; /* 100% error */ } - - size = read(fh, buf, len); - if (size >= 0) - return len - size; else - return 0; /* error */ + { + size = read(fh, buf, len); + if (size >= 0) + { + return len - size; /* success */ + } + else + { + return 0; /* error */ + } + } #else return 0; /* error */ -#endif /* RT_USING_POSIX_STDIO */ +#endif /* DFS_USING_POSIX */ } /* * Write to a file. Returns 0 on success, negative on error, and * the number of characters _not_ written on partial success. * `mode' exists for historical reasons and must be ignored. + * The return value is either: + * A positive number representing the number of characters not written + * (so any nonzero return value denotes a failure of some sort). + * A negative number indicating an error. */ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int size; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ - if ((fh == STDOUT) || (fh == STDERR)) + if (fh == STDOUT || fh == STDERR) { -#ifdef RT_USING_POSIX_STDIO - if (libc_stdio_get_console() < 0) - { - LOG_W("Do not invoke standard input before initializing libc"); - return 0; - } - size = write(STDOUT_FILENO, buf, len); - return len - size; -#elif defined(RT_USING_CONSOLE) - if (rt_console_get_device()) +#ifdef RT_USING_CONSOLE + rt_device_t console; + console = rt_console_get_device(); + if (console) { - rt_device_write(rt_console_get_device(), -1, buf, len); + rt_device_write(console, -1, buf, len); } - + return 0; /* success */ +#else return 0; /* error */ -#endif /* RT_USING_POSIX_STDIO */ +#endif /* RT_USING_CONSOLE */ } else if (fh == STDIN) { - return 0; /* error */ + return -1; /* 100% error */ } - -#ifdef RT_USING_POSIX - size = write(fh, buf, len); - if (size >= 0) - return len - size; else - return 0; /* error */ + { +#ifdef DFS_USING_POSIX + size = write(fh, buf, len); + if (size >= 0) + { + return len - size; /* success */ + } + else + { + return 0; /* error */ + } #else - return 0; -#endif /* RT_USING_POSIX */ + return 0; /* error */ +#endif /* DFS_USING_POSIX */ + } } /* @@ -224,7 +239,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) */ int _sys_seek(FILEHANDLE fh, long pos) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX if (fh < STDERR) return 0; /* error */ @@ -232,7 +247,7 @@ int _sys_seek(FILEHANDLE fh, long pos) return lseek(fh, pos, 0); #else return 0; /* error */ -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } /** @@ -277,7 +292,7 @@ RT_WEAK void _sys_exit(int return_code) */ long _sys_flen(FILEHANDLE fh) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX struct stat stat; if (fh < STDERR) @@ -287,7 +302,7 @@ long _sys_flen(FILEHANDLE fh) return stat.st_size; #else return 0; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } int _sys_istty(FILEHANDLE fh) @@ -300,11 +315,11 @@ int _sys_istty(FILEHANDLE fh) int remove(const char *filename) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX return unlink(filename); #else return 0; /* error */ -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } #ifdef __MICROLIB @@ -325,7 +340,7 @@ int fputc(int c, FILE *f) int fgetc(FILE *f) { -#ifdef RT_USING_POSIX_STDIO +#ifdef RT_USING_POSIX_DEVIO char ch; if (libc_stdio_get_console() < 0) @@ -336,7 +351,7 @@ int fgetc(FILE *f) if(read(STDIN_FILENO, &ch, 1) == 1) return ch; -#endif /* RT_USING_POSIX_STDIO */ +#endif /* RT_USING_POSIX_DEVIO */ return 0; /* error */ } diff --git a/components/libc/compilers/common/fcntl.h b/components/libc/compilers/common/nogcc/fcntl.h index 3460926708..51ee1024a8 100644 --- a/components/libc/compilers/common/fcntl.h +++ b/components/libc/compilers/common/nogcc/fcntl.h @@ -12,10 +12,9 @@ #include <sys/types.h> -#define O_RDONLY 0x0000 /* open for reading only */ -#define O_WRONLY 0x0001 /* open for writing only */ -#define O_RDWR 0x0002 /* open for reading and writing */ -#define O_ACCMODE 0x0003 /* mask for above modes */ +#define O_RDONLY 00 +#define O_WRONLY 01 +#define O_RDWR 02 #define O_CREAT 0100 #define O_EXCL 0200 @@ -30,6 +29,7 @@ #define O_DIRECTORY 0200000 #define O_NOFOLLOW 0400000 #define O_CLOEXEC 02000000 + #define O_ASYNC 020000 #define O_DIRECT 040000 #define O_LARGEFILE 0100000 @@ -37,9 +37,12 @@ #define O_PATH 010000000 #define O_TMPFILE 020200000 #define O_NDELAY O_NONBLOCK + #define O_SEARCH O_PATH #define O_EXEC O_PATH +#define O_ACCMODE (03|O_SEARCH) + #define F_DUPFD 0 #define F_GETFD 1 #define F_SETFD 2 diff --git a/components/libc/compilers/common/nogcc/unistd.h b/components/libc/compilers/common/nogcc/unistd.h index cd77a12e3b..9b96d45adb 100644 --- a/components/libc/compilers/common/nogcc/unistd.h +++ b/components/libc/compilers/common/nogcc/unistd.h @@ -7,4 +7,3 @@ * Date Author Notes */ #include "sys/unistd.h" - diff --git a/components/libc/compilers/common/poll.h b/components/libc/compilers/common/poll.h deleted file mode 100644 index aea73d6eaf..0000000000 --- a/components/libc/compilers/common/poll.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2021-09-11 Meco Man First version - */ -#ifndef __POLL_H__ -#define __POLL_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#if !defined(POLLIN) && !defined(POLLOUT) -#define POLLIN (0x01) -#define POLLRDNORM (0x01) -#define POLLRDBAND (0x01) -#define POLLPRI (0x01) - -#define POLLOUT (0x02) -#define POLLWRNORM (0x02) -#define POLLWRBAND (0x02) - -#define POLLERR (0x04) -#define POLLHUP (0x08) -#define POLLNVAL (0x10) - -typedef unsigned int nfds_t; - -struct pollfd -{ - int fd; - short events; - short revents; -}; -#endif /* !defined(POLLIN) && !defined(POLLOUT) */ - -#define POLLMASK_DEFAULT (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM) - -int poll(struct pollfd *fds, nfds_t nfds, int timeout); - -#ifdef __cplusplus -} -#endif - -#endif /* __POLL_H__ */ diff --git a/components/libc/compilers/common/sys/ioctl.h b/components/libc/compilers/common/sys/ioctl.h index 04f73837bc..29ed3a8b84 100644 --- a/components/libc/compilers/common/sys/ioctl.h +++ b/components/libc/compilers/common/sys/ioctl.h @@ -11,9 +11,7 @@ #define _SYS_IOCTL_H #include <rtconfig.h> -#ifdef RT_USING_POSIX #include <dfs_posix.h> -#endif #ifdef _WIN32 #include <winsock.h> diff --git a/components/libc/compilers/common/sys/termios.h b/components/libc/compilers/common/sys/termios.h deleted file mode 100644 index c4b42083c4..0000000000 --- a/components/libc/compilers/common/sys/termios.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index d14905ebfb..93e3bb7ba4 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -72,7 +72,6 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz); struct tm *gmtime_r(const time_t *timep, struct tm *r); #endif -#ifdef RT_USING_POSIX /* POSIX clock and timer */ #define MILLISECOND_PER_SECOND 1000UL #define MICROSECOND_PER_SECOND 1000000UL @@ -103,8 +102,8 @@ 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 rt_timespec_to_tick(const struct timespec *time); -#endif /* RT_USING_POSIX */ +/* timezone */ void tz_set(int8_t tz); int8_t tz_get(void); int8_t tz_is_dst(void); diff --git a/components/libc/compilers/common/termios.h b/components/libc/compilers/common/termios.h deleted file mode 100644 index 2960d52c58..0000000000 --- a/components/libc/compilers/common/termios.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef _TERMIOS_H__ -#define _TERMIOS_H__ - -#include <rtconfig.h> - -#ifdef RT_USING_POSIX_TERMIOS -#include <sys/types.h> -#include <posix_termios.h> -#endif - -#endif diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 5bfff15914..73b6d76352 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -486,8 +486,6 @@ RTM_EXPORT(settimeofday); RTM_EXPORT(difftime); RTM_EXPORT(strftime); -#ifdef RT_USING_POSIX - #ifdef RT_USING_RTC static volatile struct timeval _timevalue; static int _rt_clock_time_system_init() @@ -690,9 +688,6 @@ int rt_timespec_to_tick(const struct timespec *time) } RTM_EXPORT(rt_timespec_to_tick); -#endif /* RT_USING_POSIX */ - - /* timezone */ #ifndef RT_LIBC_DEFAULT_TIMEZONE #define RT_LIBC_DEFAULT_TIMEZONE 8 diff --git a/components/libc/compilers/dlib/SConscript b/components/libc/compilers/dlib/SConscript index 39707abc61..f685873e16 100644 --- a/components/libc/compilers/dlib/SConscript +++ b/components/libc/compilers/dlib/SConscript @@ -7,7 +7,7 @@ group = [] CPPDEFINES = ['RT_USING_DLIBC'] if rtconfig.PLATFORM == 'iar': - if GetDepend('RT_USING_POSIX'): + if GetDepend('DFS_USING_POSIX'): from distutils.version import LooseVersion from iar import IARVersion diff --git a/components/libc/compilers/dlib/syscall_close.c b/components/libc/compilers/dlib/syscall_close.c index 2897c2418a..30ee6f2388 100644 --- a/components/libc/compilers/dlib/syscall_close.c +++ b/components/libc/compilers/dlib/syscall_close.c @@ -8,19 +8,25 @@ * 2015-01-28 Bernard first version */ #include <rtthread.h> -#include <yfuns.h> +#include <LowLevelIOInterface.h> #include <unistd.h> +/* + * The "__close" function should close the file corresponding to + * "handle". It should return 0 on success and nonzero on failure. + */ + #pragma module_name = "?__close" + int __close(int handle) { if (handle == _LLIO_STDOUT || handle == _LLIO_STDERR || handle == _LLIO_STDIN) return _LLIO_ERROR; -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX return close(handle); #else return _LLIO_ERROR; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_lseek.c b/components/libc/compilers/dlib/syscall_lseek.c index 4ea55ef1c3..622f613c51 100644 --- a/components/libc/compilers/dlib/syscall_lseek.c +++ b/components/libc/compilers/dlib/syscall_lseek.c @@ -8,19 +8,34 @@ * 2015-01-28 Bernard first version */ #include <rtthread.h> -#include <yfuns.h> +#include <LowLevelIOInterface.h> #include <unistd.h> +/* + * The "__lseek" function makes the next file operation (__read or + * __write) act on a new location. The parameter "whence" specifies + * how the "offset" parameter should be interpreted according to the + * following table: + * + * 0 (=SEEK_SET) - Goto location "offset". + * 1 (=SEEK_CUR) - Go "offset" bytes from the current location. + * 2 (=SEEK_END) - Go to "offset" bytes from the end. + * + * This function should return the current file position, or -1 on + * failure. + */ + #pragma module_name = "?__lseek" + long __lseek(int handle, long offset, int whence) { if (handle == _LLIO_STDOUT || handle == _LLIO_STDERR || handle == _LLIO_STDIN) return _LLIO_ERROR; -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX return lseek(handle, offset, whence); #else return _LLIO_ERROR; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_mem.c b/components/libc/compilers/dlib/syscall_mem.c index 9c6de64455..74b960f0b9 100644 --- a/components/libc/compilers/dlib/syscall_mem.c +++ b/components/libc/compilers/dlib/syscall_mem.c @@ -6,27 +6,55 @@ * Change Logs: * Date Author Notes * 2015-01-28 Bernard first version + * 2021-11-13 Meco Man implement no-heap warning */ #include <rtthread.h> +#include <stddef.h> -#ifdef RT_USING_HEAP -void *malloc(rt_size_t n) +#ifndef RT_USING_HEAP +#define DBG_TAG "dlib.syscall_mem" +#define DBG_LVL DBG_INFO +#include <rtdbg.h> +#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\ + RT_ASSERT(0);\ + }while(0) +#endif /* RT_USING_HEAP */ + +void *malloc(size_t n) { +#ifdef RT_USING_HEAP return rt_malloc(n); +#else + _NO_HEAP_ERROR(); + return RT_NULL; +#endif } -void *realloc(void *rmem, rt_size_t newsize) +void *realloc(void *rmem, size_t newsize) { +#ifdef RT_USING_HEAP return rt_realloc(rmem, newsize); +#else + _NO_HEAP_ERROR(); + return RT_NULL; +#endif } -void *calloc(rt_size_t nelem, rt_size_t elsize) +void *calloc(size_t nelem, size_t elsize) { +#ifdef RT_USING_HEAP return rt_calloc(nelem, elsize); +#else + _NO_HEAP_ERROR(); + return RT_NULL; +#endif } void free(void *rmem) { +#ifdef RT_USING_HEAP rt_free(rmem); -} +#else + _NO_HEAP_ERROR(); #endif +} diff --git a/components/libc/compilers/dlib/syscall_open.c b/components/libc/compilers/dlib/syscall_open.c index 8fb3c3a11f..66cddc83c1 100644 --- a/components/libc/compilers/dlib/syscall_open.c +++ b/components/libc/compilers/dlib/syscall_open.c @@ -9,14 +9,19 @@ */ #include <rtthread.h> -#include <yfuns.h> +#include <LowLevelIOInterface.h> #include <fcntl.h> +/* + * The "__open" function opens the file named "filename" as specified + * by "mode". + */ + #pragma module_name = "?__open" int __open(const char *filename, int mode) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int handle; int open_mode = O_RDONLY; @@ -68,5 +73,5 @@ int __open(const char *filename, int mode) return handle; #else return _LLIO_ERROR; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c index c926c577b5..62bc05d243 100644 --- a/components/libc/compilers/dlib/syscall_read.c +++ b/components/libc/compilers/dlib/syscall_read.c @@ -9,30 +9,46 @@ */ #include <rtthread.h> -#include <yfuns.h> +#include <LowLevelIOInterface.h> #include <unistd.h> -#ifdef RT_USING_POSIX_STDIO +#ifdef RT_USING_POSIX_DEVIO #include "libc.h" -#endif +#endif /* RT_USING_POSIX_DEVIO */ #define DBG_TAG "dlib.syscall_read" #define DBG_LVL DBG_INFO #include <rtdbg.h> +/* + * The "__read" function reads a number of bytes, at most "size" into + * the memory area pointed to by "buffer". It returns the number of + * bytes read, 0 at the end of the file, or _LLIO_ERROR if failure + * occurs. + * + * The template implementation below assumes that the application + * provides the function "MyLowLevelGetchar". It should return a + * character value, or -1 on failure. + */ + #pragma module_name = "?__read" + size_t __read(int handle, unsigned char *buf, size_t len) { -#ifdef RT_USING_POSIX_STDIO +#ifdef DFS_USING_POSIX int size; if (handle == _LLIO_STDIN) { +#ifdef RT_USING_POSIX_DEVIO if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard input before initializing libc"); - return 0; + return 0; /* error, but keep going */ } - return read(STDIN_FILENO, buf, len); + return read(STDIN_FILENO, buf, len); /* return the length of the data read */ +#else + return _LLIO_ERROR; +#endif /* RT_USING_POSIX_DEVIO */ } else if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR)) { @@ -40,8 +56,8 @@ size_t __read(int handle, unsigned char *buf, size_t len) } size = read(handle, buf, len); - return size; + return size; /* return the length of the data read */ #else return _LLIO_ERROR; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_remove.c b/components/libc/compilers/dlib/syscall_remove.c index 05bfbb67ae..870f91b8c1 100644 --- a/components/libc/compilers/dlib/syscall_remove.c +++ b/components/libc/compilers/dlib/syscall_remove.c @@ -8,15 +8,21 @@ * 2015-01-28 Bernard first version */ #include <rtthread.h> -#include <yfuns.h> +#include <LowLevelIOInterface.h> #include <unistd.h> +/* + * The "remove" function should remove the file named "filename". It + * should return 0 on success and nonzero on failure. + */ + #pragma module_name = "?remove" -int remove(const char *val) + +int remove(const char *filename) { -#ifdef RT_USING_POSIX - return unlink(val); +#ifdef DFS_USING_POSIX + return unlink(filename); #else - return -1; -#endif /* RT_USING_POSIX */ + return _LLIO_ERROR; +#endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c index 72bac6ba49..2bc5863d8a 100644 --- a/components/libc/compilers/dlib/syscall_write.c +++ b/components/libc/compilers/dlib/syscall_write.c @@ -9,56 +9,61 @@ */ #include <rtthread.h> -#include <yfuns.h> +#include <LowLevelIOInterface.h> #include <unistd.h> -#ifdef RT_USING_POSIX_STDIO -#include "libc.h" -#endif - #define DBG_TAG "dlib.syscall_write" #define DBG_LVL DBG_INFO #include <rtdbg.h> +/* + * The "__write" function should output "size" number of bytes from + * "buffer" in some application-specific way. It should return the + * number of characters written, or _LLIO_ERROR on failure. + * + * If "buffer" is zero then __write should perform flushing of + * internal buffers, if any. In this case "handle" can be -1 to + * indicate that all handles should be flushed. + * + * The template implementation below assumes that the application + * provides the function "MyLowLevelPutchar". It should return the + * character written, or -1 on failure. + */ + #pragma module_name = "?__write" size_t __write(int handle, const unsigned char *buf, size_t len) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int size; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR)) { -#ifdef RT_USING_POSIX_STDIO - if (libc_stdio_get_console() < 0) - { - LOG_W("Do not invoke standard output before initializing libc"); - return 0; - } - return write(STDOUT_FILENO, (void*)buf, len); -#elif defined(RT_USING_CONSOLE) +#ifdef RT_USING_CONSOLE rt_device_t console_device; console_device = rt_console_get_device(); - if (console_device != 0) + if (console_device) { rt_device_write(console_device, 0, buf, len); } - return len; + return len; /* return the length of the data written */ #else return _LLIO_ERROR; -#endif /* RT_USING_POSIX */ +#endif /* RT_USING_CONSOLE */ } else if (handle == _LLIO_STDIN) { return _LLIO_ERROR; } - -#ifdef RT_USING_POSIX - size = write(handle, buf, len); - return size; + else + { +#ifdef DFS_USING_POSIX + size = write(handle, buf, len); + return size; /* return the length of the data written */ #else - return _LLIO_ERROR; -#endif /* RT_USING_POSIX */ + return _LLIO_ERROR; +#endif /* DFS_USING_POSIX */ + } } diff --git a/components/libc/compilers/gcc/newlib/fcntl.h b/components/libc/compilers/gcc/newlib/fcntl.h new file mode 100644 index 0000000000..239eaaef0d --- /dev/null +++ b/components/libc/compilers/gcc/newlib/fcntl.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-09-02 Meco Man First version + */ +#ifndef __FCNTL_H__ +#define __FCNTL_H__ + +#include <sys/_default_fcntl.h> + +#ifndef O_DIRECTORY +#define O_DIRECTORY 0x200000 +#endif + +#ifndef O_BINARY +#define O_BINARY 0x10000 +#endif + +#endif diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c index e957aaf003..8fe8c5be4b 100644 --- a/components/libc/compilers/gcc/newlib/syscalls.c +++ b/components/libc/compilers/gcc/newlib/syscalls.c @@ -20,12 +20,12 @@ #include <unistd.h> #include <sys/errno.h> #include <sys/stat.h> -#ifdef RT_USING_POSIX_STDIO +#ifdef RT_USING_POSIX_DEVIO #include "libc.h" -#endif +#endif /* RT_USING_POSIX_DEVIO */ #ifdef RT_USING_MODULE #include <dlmodule.h> -#endif +#endif /* RT_USING_MODULE */ #define DBG_TAG "newlib.syscalls" #define DBG_LVL DBG_INFO @@ -80,7 +80,7 @@ void _free_r (struct _reent *ptr, void *addr) void * _sbrk_r(struct _reent *ptr, ptrdiff_t incr) { - LOG_E("Please enable RT_USING_HEAP or RT_USING_LIBC"); + LOG_E("Please enable RT_USING_HEAP"); RT_ASSERT(0); return RT_NULL; } @@ -109,7 +109,12 @@ int _getpid_r(struct _reent *ptr) int _close_r(struct _reent *ptr, int fd) { +#ifdef DFS_USING_POSIX return close(fd); +#else + ptr->_errno = ENOTSUP; + return -1; +#endif /* DFS_USING_POSIX */ } int _execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env) @@ -178,7 +183,7 @@ int flock(int fd, int operation) _off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX _off_t rc; rc = lseek(fd, pos, whence); @@ -186,12 +191,12 @@ _off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } int _mkdir_r(struct _reent *ptr, const char *name, int mode) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int rc; rc = mkdir(name, mode); @@ -199,41 +204,55 @@ int _mkdir_r(struct _reent *ptr, const char *name, int mode) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } int _open_r(struct _reent *ptr, const char *file, int flags, int mode) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int rc; rc = open(file, flags, mode); return rc; #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) { -#ifdef RT_USING_POSIX_STDIO +#ifdef DFS_USING_POSIX _ssize_t rc; - if (libc_stdio_get_console() < 0 && fd == STDIN_FILENO) + if (fd == STDIN_FILENO) { - LOG_W("Do not invoke standard input before initializing libc"); - return 0; +#ifdef RT_USING_POSIX_DEVIO + if (libc_stdio_get_console() < 0) + { + LOG_W("Do not invoke standard input before initializing libc"); + return 0; + } +#else + ptr->_errno = ENOTSUP; + return -1; +#endif /* RT_USING_POSIX_DEVIO */ + } + else if (fd == STDOUT_FILENO || fd == STDERR_FILENO) + { + ptr->_errno = ENOTSUP; + return -1; } + rc = read(fd, buf, nbytes); return rc; #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } int _rename_r(struct _reent *ptr, const char *old, const char *new) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int rc; rc = rename(old, new); @@ -241,12 +260,12 @@ int _rename_r(struct _reent *ptr, const char *old, const char *new) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int rc; rc = stat(file, pstat); @@ -254,44 +273,51 @@ int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } int _unlink_r(struct _reent *ptr, const char *file) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX return unlink(file); #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX _ssize_t rc; -#ifdef RT_USING_POSIX_STDIO - if (libc_stdio_get_console() < 0 && fd == STDOUT_FILENO) - { - LOG_W("Do not invoke standard output before initializing libc"); - return 0; - } -#endif /* RT_USING_POSIX_STDIO */ - rc = write(fd, buf, nbytes); - return rc; -#elif defined(RT_USING_CONSOLE) - if (STDOUT_FILENO == fd) +#endif /* DFS_USING_POSIX */ + + if (fd == STDOUT_FILENO || fd == STDERR_FILENO) { +#ifdef RT_USING_CONSOLE rt_device_t console; console = rt_console_get_device(); if (console) return rt_device_write(console, -1, buf, nbytes); +#else + ptr->_errno = ENOTSUP; + return -1; +#endif /* RT_USING_CONSOLE */ } -#endif /* RT_USING_POSIX */ + else if (fd == STDIN_FILENO) + { + ptr->_errno = ENOTSUP; + return -1; + } + +#ifdef DFS_USING_POSIX + rc = write(fd, buf, nbytes); + return rc; +#else ptr->_errno = ENOTSUP; return -1; +#endif /* DFS_USING_POSIX */ } /* for exit() and abort() */ |
