diff options
| author | guo <[email protected]> | 2021-10-27 12:22:35 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-10-27 12:22:35 +0800 |
| commit | 4d256eb308f4e9f7abc1644dda3fd675e560d518 (patch) | |
| tree | 4da0b0458ca8749c4fcee2ede8681304641ba89d /components/libc/compilers/armlibc | |
| parent | 31bf735d2159995358315036be1529523ac96d7d (diff) | |
| parent | a9910a780edc43df6b64bcd13c37785a15ec3428 (diff) | |
Merge pull request #5228 from mysterywolf/posix
Diffstat (limited to 'components/libc/compilers/armlibc')
| -rw-r--r-- | components/libc/compilers/armlibc/SConscript | 3 | ||||
| -rw-r--r-- | components/libc/compilers/armlibc/libc.c | 11 | ||||
| -rw-r--r-- | components/libc/compilers/armlibc/libc.h | 4 | ||||
| -rw-r--r-- | components/libc/compilers/armlibc/stdio.c | 9 | ||||
| -rw-r--r-- | components/libc/compilers/armlibc/syscalls.c | 121 |
5 files changed, 68 insertions, 80 deletions
diff --git a/components/libc/compilers/armlibc/SConscript b/components/libc/compilers/armlibc/SConscript index 52f7a6d93a..d77a7c69d5 100644 --- a/components/libc/compilers/armlibc/SConscript +++ b/components/libc/compilers/armlibc/SConscript @@ -8,9 +8,6 @@ group = [] CPPPATH = [cwd] CPPDEFINES = ['RT_USING_ARM_LIBC'] -if GetDepend('RT_USING_DFS') == False: - SrcRemove(src, ['stdio.c']) - if GetDepend('RT_USING_MODULE') == False: SrcRemove(src, ['libc_syms.c']) diff --git a/components/libc/compilers/armlibc/libc.c b/components/libc/compilers/armlibc/libc.c index 889c687309..bc09759fef 100644 --- a/components/libc/compilers/armlibc/libc.c +++ b/components/libc/compilers/armlibc/libc.c @@ -7,29 +7,24 @@ * Date Author Notes * 2017/10/15 bernard the first version */ -#include <fcntl.h> #include <rtthread.h> +#include <fcntl.h> #include "libc.h" - #ifdef RT_USING_PTHREADS #include <pthread.h> #endif int libc_system_init(void) { -#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS) +#ifdef RT_USING_POSIX rt_device_t dev_console; dev_console = rt_console_get_device(); if (dev_console) { - #if defined(RT_USING_POSIX) libc_stdio_set_console(dev_console->parent.name, O_RDWR); - #else - libc_stdio_set_console(dev_console->parent.name, O_WRONLY); - #endif } -#endif +#endif /* RT_USING_POSIX */ #if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT pthread_system_init(); diff --git a/components/libc/compilers/armlibc/libc.h b/components/libc/compilers/armlibc/libc.h index 5c1613728e..f81380bf78 100644 --- a/components/libc/compilers/armlibc/libc.h +++ b/components/libc/compilers/armlibc/libc.h @@ -10,13 +10,17 @@ #ifndef __RTT_LIBC_H__ #define __RTT_LIBC_H__ +#include <rtconfig.h> + #ifdef __cplusplus extern "C" { #endif int libc_system_init(void); +#ifdef RT_USING_POSIX int libc_stdio_get_console(void); int libc_stdio_set_console(const char* device_name, int mode); +#endif /* RT_USING_POSIX */ #ifdef __cplusplus } diff --git a/components/libc/compilers/armlibc/stdio.c b/components/libc/compilers/armlibc/stdio.c index 7dd9dbfe3f..e5db167ea4 100644 --- a/components/libc/compilers/armlibc/stdio.c +++ b/components/libc/compilers/armlibc/stdio.c @@ -7,16 +7,17 @@ * Date Author Notes * 2017/10/15 bernard implement stdio for armcc. */ +#include <rtthread.h> +#ifdef RT_USING_POSIX #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <rtthread.h> #include "libc.h" -#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS) -#include <dfs_posix.h> +#include <fcntl.h> +#include <unistd.h> #define STDIO_DEVICE_NAME_MAX 32 @@ -48,4 +49,4 @@ int libc_stdio_get_console(void) return std_fd; } -#endif +#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index ccdcfc86ea..ecb1a9da5a 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -14,16 +14,15 @@ * 2020-02-13 Meco Man re-implement exit() and abort() * 2020-02-14 Meco Man implement _sys_tmpnam() */ - #include <string.h> #include <rt_sys.h> #include <rtthread.h> #include "libc.h" -#ifdef RT_USING_DFS -#include <dfs_posix.h> -#endif +#include <fcntl.h> +#include <unistd.h> +#include <sys/stat.h> #define DBG_TAG "armlibc.syscalls" #define DBG_LVL DBG_INFO @@ -55,7 +54,7 @@ const char __stderr_name[] = "STDERR"; */ FILEHANDLE _sys_open(const char *name, int openmode) { -#ifdef RT_USING_DFS +#ifdef RT_LIBC_USING_FILEIO int fd; int mode = O_RDONLY; #endif @@ -68,8 +67,8 @@ FILEHANDLE _sys_open(const char *name, int openmode) if (strcmp(name, __stderr_name) == 0) return (STDERR); -#ifndef RT_USING_DFS - return -1; +#ifndef RT_LIBC_USING_FILEIO + return 0; /* error */ #else /* Correct openmode from fopen to open */ if (openmode & OPEN_PLUS) @@ -99,21 +98,22 @@ FILEHANDLE _sys_open(const char *name, int openmode) fd = open(name, mode, 0); if (fd < 0) - return -1; + return 0; /* error */ else return fd; -#endif +#endif /* RT_LIBC_USING_FILEIO */ } int _sys_close(FILEHANDLE fh) { -#ifndef RT_USING_DFS - return 0; -#else - if (fh <= STDERR) return 0; +#ifdef RT_LIBC_USING_FILEIO + if (fh <= STDERR) + return 0; /* error */ return close(fh); -#endif +#else + return 0; +#endif /* RT_LIBC_USING_FILEIO */ } /* @@ -143,13 +143,11 @@ int _sys_close(FILEHANDLE fh) */ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) { -#ifdef RT_USING_DFS +#ifdef RT_LIBC_USING_FILEIO int size; -#endif if (fh == STDIN) { -#ifdef RT_USING_POSIX if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard output before initializing libc"); @@ -157,25 +155,20 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) } size = read(STDIN_FILENO, buf, len); return len - size; -#else - /* no stdin */ - return -1; -#endif } else if ((fh == STDOUT) || (fh == STDERR)) { - return -1; + return 0; /* error */ } -#ifndef RT_USING_DFS - return 0; -#else size = read(fh, buf, len); if (size >= 0) return len - size; else - return -1; -#endif + return 0; /* error */ +#else + return 0; /* error */ +#endif /* RT_LIBC_USING_FILEIO */ } /* @@ -185,16 +178,13 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) */ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) { -#ifdef RT_USING_DFS +#ifdef RT_LIBC_USING_FILEIO int size; -#endif +#endif /* RT_LIBC_USING_FILEIO */ if ((fh == STDOUT) || (fh == STDERR)) { -#if !defined(RT_USING_CONSOLE) || !defined(RT_USING_DEVICE) - return 0; -#else -#ifdef RT_USING_POSIX +#ifdef RT_LIBC_USING_FILEIO if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard input before initializing libc"); @@ -202,31 +192,29 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) } size = write(STDOUT_FILENO, buf, len); return len - size; -#else +#elif defined(RT_USING_CONSOLE) if (rt_console_get_device()) { rt_device_write(rt_console_get_device(), -1, buf, len); - return 0; } - return -1; -#endif -#endif + return 0; /* error */ +#endif /* RT_LIBC_USING_FILEIO */ } else if (fh == STDIN) { - return -1; + return 0; /* error */ } -#ifndef RT_USING_DFS - return 0; -#else +#ifdef RT_LIBC_USING_FILEIO size = write(fh, buf, len); if (size >= 0) return len - size; else - return -1; -#endif + return 0; /* error */ +#else + return 0; +#endif /* RT_LIBC_USING_FILEIO */ } /* @@ -235,16 +223,15 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) */ int _sys_seek(FILEHANDLE fh, long pos) { +#ifdef RT_LIBC_USING_FILEIO if (fh < STDERR) - return -1; - -#ifndef RT_USING_DFS - return -1; -#else + return 0; /* error */ /* position is relative to the start of file fh */ return lseek(fh, pos, 0); -#endif +#else + return 0; /* error */ +#endif /* RT_LIBC_USING_FILEIO */ } /** @@ -270,7 +257,7 @@ void _ttywrch(int ch) c = (char)ch; rt_kprintf(&c); -#endif +#endif /* RT_USING_CONSOLE */ } /* for exit() and abort() */ @@ -289,17 +276,17 @@ RT_WEAK void _sys_exit(int return_code) */ long _sys_flen(FILEHANDLE fh) { -#ifdef RT_USING_DFS +#ifdef RT_LIBC_USING_FILEIO struct stat stat; if (fh < STDERR) - return -1; + return 0; /* error */ fstat(fh, &stat); return stat.st_size; #else - return -1; -#endif + return 0; +#endif /* RT_LIBC_USING_FILEIO */ } int _sys_istty(FILEHANDLE fh) @@ -312,11 +299,11 @@ int _sys_istty(FILEHANDLE fh) int remove(const char *filename) { -#ifndef RT_USING_DFS - return -1; -#else +#ifdef RT_LIBC_USING_FILEIO return unlink(filename); -#endif +#else + return 0; /* error */ +#endif /* RT_LIBC_USING_FILEIO */ } #ifdef __MICROLIB @@ -324,28 +311,32 @@ int remove(const char *filename) int fputc(int c, FILE *f) { +#ifdef RT_USING_CONSOLE char ch[2] = {0}; ch[0] = c; rt_kprintf(&ch[0]); return 1; +#else + return 0; /* error */ +#endif /* RT_USING_CONSOLE */ } int fgetc(FILE *f) { -#ifdef RT_USING_POSIX +#ifdef RT_LIBC_USING_FILEIO char ch; if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard output before initializing libc"); - return -1; + return 0; } if(read(STDIN_FILENO, &ch, 1) == 1) return ch; -#endif - - return -1; +#endif /* RT_LIBC_USING_FILEIO */ + return 0; /* error */ } -#endif + +#endif /* __MICROLIB */ |
