From 85276f453578e0ea74f39cfcc609f867f919f059 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 29 Dec 2021 07:48:36 -0500 Subject: [PATCH] =?UTF-8?q?[libc]=20=E5=88=A0=E9=99=A4compiler=5Fprivate.c?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/armlibc/syscalls.c | 18 ++++++++--------- .../libc/compilers/common/compiler_private.c | 13 ------------ .../libc/compilers/common/compiler_private.h | 4 ++-- components/libc/compilers/common/time.c | 16 +++++++-------- .../libc/compilers/dlib/syscall_close.c | 2 +- .../libc/compilers/dlib/syscall_lseek.c | 2 +- components/libc/compilers/dlib/syscall_open.c | 2 +- components/libc/compilers/dlib/syscall_read.c | 4 ++-- .../libc/compilers/dlib/syscall_remove.c | 2 +- .../libc/compilers/dlib/syscall_write.c | 2 +- .../libc/compilers/gcc/newlib/syscalls.c | 20 +++++++++---------- 11 files changed, 36 insertions(+), 49 deletions(-) delete mode 100644 components/libc/compilers/common/compiler_private.c diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index e9318c5fc4..54d8b40bf6 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -70,7 +70,7 @@ FILEHANDLE _sys_open(const char *name, int openmode) return (STDERR); #ifndef DFS_USING_POSIX - LOG_W("%s: %s", __func__, warning_without_fs); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); return 0; /* error */ #else /* Correct openmode from fopen to open */ @@ -115,7 +115,7 @@ int _sys_close(FILEHANDLE fh) return close(fh); #else - LOG_W("%s: %s", __func__, warning_without_fs); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); return 0; #endif /* DFS_USING_POSIX */ } @@ -161,7 +161,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) size = read(STDIN_FILENO, buf, len); return len - size; /* success */ #else - LOG_W("%s: %s", __func__, warning_without_devio); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_DEVIO); return 0; /* error */ #endif /* RT_USING_POSIX_DEVIO */ } @@ -182,7 +182,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) } } #else - LOG_W("%s: %s", __func__, warning_without_fs); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); return 0; /* error */ #endif /* DFS_USING_POSIX */ } @@ -233,7 +233,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) return 0; /* error */ } #else - LOG_W("%s: %s", __func__, warning_without_fs); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); return 0; /* error */ #endif /* DFS_USING_POSIX */ } @@ -252,7 +252,7 @@ int _sys_seek(FILEHANDLE fh, long pos) /* position is relative to the start of file fh */ return lseek(fh, pos, 0); #else - LOG_W("%s: %s", __func__, warning_without_fs); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); return 0; /* error */ #endif /* DFS_USING_POSIX */ } @@ -308,7 +308,7 @@ long _sys_flen(FILEHANDLE fh) fstat(fh, &stat); return stat.st_size; #else - LOG_W("%s: %s", __func__, warning_without_fs); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); return 0; #endif /* DFS_USING_POSIX */ } @@ -326,7 +326,7 @@ int remove(const char *filename) #ifdef DFS_USING_POSIX return unlink(filename); #else - LOG_W("%s: %s", __func__, warning_without_fs); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); return 0; /* error */ #endif /* DFS_USING_POSIX */ } @@ -361,7 +361,7 @@ int fgetc(FILE *f) if(read(STDIN_FILENO, &ch, 1) == 1) return ch; #endif /* RT_USING_POSIX_DEVIO */ - LOG_W("%s: %s", __func__, warning_without_devio); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_DEVIO); return 0; /* error */ } diff --git a/components/libc/compilers/common/compiler_private.c b/components/libc/compilers/common/compiler_private.c deleted file mode 100644 index 6e9a6001f0..0000000000 --- a/components/libc/compilers/common/compiler_private.c +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2021-12-26 Meco Man First Version - */ -#include "compiler_private.h" - -const char *warning_without_fs = "Please enable RT_USING_POSIX_FS"; -const char *warning_without_devio = "Please enable RT_USING_POSIX_FS and RT_USING_POSIX_DEVIO"; diff --git a/components/libc/compilers/common/compiler_private.h b/components/libc/compilers/common/compiler_private.h index 79bac3b787..ed29b8c333 100644 --- a/components/libc/compilers/common/compiler_private.h +++ b/components/libc/compilers/common/compiler_private.h @@ -12,7 +12,7 @@ #include -extern const char *warning_without_fs; -extern const char *warning_without_devio; +#define _WARNING_WITHOUT_FS "Please enable RT_USING_POSIX_FS" +#define _WARNING_WITHOUT_DEVIO "Please enable RT_USING_POSIX_FS and RT_USING_POSIX_DEVIO" #endif /* __COMPILER_PRIVATE_H__ */ diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 1fe11561f7..8890a3e830 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -33,7 +33,7 @@ #define DBG_LVL DBG_INFO #include -#define WARNING_NO_RTC "Cannot find a RTC device!" +#define _WARNING_NO_RTC "Cannot find a RTC device!" /* seconds per day */ #define SPD 24*60*60 @@ -110,7 +110,7 @@ static rt_err_t get_timeval(struct timeval *tv) else { /* LOG_W will cause a recursive printing if ulog timestamp function is enabled */ - rt_kprintf(WARNING_NO_RTC); + rt_kprintf(_WARNING_NO_RTC); return -RT_ENOSYS; } @@ -118,7 +118,7 @@ static rt_err_t get_timeval(struct timeval *tv) #else /* LOG_W will cause a recursive printing if ulog timestamp function is enabled */ - rt_kprintf(WARNING_NO_RTC); + rt_kprintf(_WARNING_NO_RTC); return -RT_ENOSYS; #endif /* RT_USING_RTC */ } @@ -155,14 +155,14 @@ static int set_timeval(struct timeval *tv) } else { - LOG_W(WARNING_NO_RTC); + LOG_W(_WARNING_NO_RTC); return -RT_ENOSYS; } return rst; #else - LOG_W(WARNING_NO_RTC); + LOG_W(_WARNING_NO_RTC); return -RT_ENOSYS; #endif /* RT_USING_RTC */ } @@ -527,7 +527,7 @@ INIT_COMPONENT_EXPORT(_rt_clock_time_system_init); int clock_getres(clockid_t clockid, struct timespec *res) { #ifndef RT_USING_RTC - LOG_W(WARNING_NO_RTC); + LOG_W(_WARNING_NO_RTC); return -1; #else int ret = 0; @@ -566,7 +566,7 @@ RTM_EXPORT(clock_getres); int clock_gettime(clockid_t clockid, struct timespec *tp) { #ifndef RT_USING_RTC - LOG_W(WARNING_NO_RTC); + LOG_W(_WARNING_NO_RTC); return -1; #else int ret = 0; @@ -630,7 +630,7 @@ int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, s int clock_settime(clockid_t clockid, const struct timespec *tp) { #ifndef RT_USING_RTC - LOG_W(WARNING_NO_RTC); + LOG_W(_WARNING_NO_RTC); return -1; #else register rt_base_t level; diff --git a/components/libc/compilers/dlib/syscall_close.c b/components/libc/compilers/dlib/syscall_close.c index 9ac60076f4..294c81f6c0 100644 --- a/components/libc/compilers/dlib/syscall_close.c +++ b/components/libc/compilers/dlib/syscall_close.c @@ -31,7 +31,7 @@ int __close(int handle) #ifdef DFS_USING_POSIX return close(handle); #else - LOG_W(warning_without_fs); + LOG_W(_WARNING_WITHOUT_FS); return _LLIO_ERROR; #endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_lseek.c b/components/libc/compilers/dlib/syscall_lseek.c index b7ec0fa7a9..3bfec38998 100644 --- a/components/libc/compilers/dlib/syscall_lseek.c +++ b/components/libc/compilers/dlib/syscall_lseek.c @@ -40,7 +40,7 @@ long __lseek(int handle, long offset, int whence) #ifdef DFS_USING_POSIX return lseek(handle, offset, whence); #else - LOG_W(warning_without_fs); + LOG_W(_WARNING_WITHOUT_FS); return _LLIO_ERROR; #endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_open.c b/components/libc/compilers/dlib/syscall_open.c index 3d31f0cf69..4d557db4b0 100644 --- a/components/libc/compilers/dlib/syscall_open.c +++ b/components/libc/compilers/dlib/syscall_open.c @@ -77,7 +77,7 @@ int __open(const char *filename, int mode) } return handle; #else - LOG_W(warning_without_fs); + LOG_W(_WARNING_WITHOUT_FS); return _LLIO_ERROR; #endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c index 525db3c98f..db523cc0a6 100644 --- a/components/libc/compilers/dlib/syscall_read.c +++ b/components/libc/compilers/dlib/syscall_read.c @@ -47,7 +47,7 @@ size_t __read(int handle, unsigned char *buf, size_t len) } return read(STDIN_FILENO, buf, len); /* return the length of the data read */ #else - LOG_W(warning_without_devio); + LOG_W(_WARNING_WITHOUT_DEVIO); return _LLIO_ERROR; #endif /* RT_USING_POSIX_DEVIO */ } @@ -59,7 +59,7 @@ size_t __read(int handle, unsigned char *buf, size_t len) size = read(handle, buf, len); return size; /* return the length of the data read */ #else - LOG_W(warning_without_fs); + LOG_W(_WARNING_WITHOUT_FS); return _LLIO_ERROR; #endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_remove.c b/components/libc/compilers/dlib/syscall_remove.c index 9b5d596eb5..40c51164a9 100644 --- a/components/libc/compilers/dlib/syscall_remove.c +++ b/components/libc/compilers/dlib/syscall_remove.c @@ -27,7 +27,7 @@ int remove(const char *filename) #ifdef DFS_USING_POSIX return unlink(filename); #else - LOG_W(warning_without_fs); + LOG_W(_WARNING_WITHOUT_FS); 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 11a6f9cca5..3af08daba9 100644 --- a/components/libc/compilers/dlib/syscall_write.c +++ b/components/libc/compilers/dlib/syscall_write.c @@ -64,7 +64,7 @@ size_t __write(int handle, const unsigned char *buf, size_t len) size = write(handle, buf, len); return size; /* return the length of the data written */ #else - LOG_W(warning_without_fs); + LOG_W(_WARNING_WITHOUT_FS); return _LLIO_ERROR; #endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c index 6a2e99d512..da0e4dc16f 100644 --- a/components/libc/compilers/gcc/newlib/syscalls.c +++ b/components/libc/compilers/gcc/newlib/syscalls.c @@ -110,7 +110,7 @@ int _close_r(struct _reent *ptr, int fd) #ifdef DFS_USING_POSIX return close(fd); #else - LOG_W("%s: %s", __func__, warning_without_fs); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -187,7 +187,7 @@ _off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) rc = lseek(fd, pos, whence); return rc; #else - LOG_W("%s: %s", __func__, warning_without_fs); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -200,7 +200,7 @@ int _mkdir_r(struct _reent *ptr, const char *name, int mode) rc = mkdir(name, mode); return rc; #else - LOG_W("%s: %s", __func__, warning_without_fs); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -213,7 +213,7 @@ int _open_r(struct _reent *ptr, const char *file, int flags, int mode) rc = open(file, flags, mode); return rc; #else - LOG_W("%s: %s", __func__, warning_without_fs); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -232,7 +232,7 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) return 0; } #else - LOG_W("%s: %s", __func__, warning_without_devio); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_DEVIO); ptr->_errno = ENOTSUP; return -1; #endif /* RT_USING_POSIX_DEVIO */ @@ -246,7 +246,7 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) rc = read(fd, buf, nbytes); return rc; #else - LOG_W("%s: %s", __func__, warning_without_fs); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -259,7 +259,7 @@ int _rename_r(struct _reent *ptr, const char *old, const char *new) rc = rename(old, new); return rc; #else - LOG_W("%s: %s", __func__, warning_without_fs); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -272,7 +272,7 @@ int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) rc = stat(file, pstat); return rc; #else - LOG_W("%s: %s", __func__, warning_without_fs); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -283,7 +283,7 @@ int _unlink_r(struct _reent *ptr, const char *file) #ifdef DFS_USING_POSIX return unlink(file); #else - LOG_W("%s: %s", __func__, warning_without_fs); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -318,7 +318,7 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) rc = write(fd, buf, nbytes); return rc; #else - LOG_W("%s: %s", __func__, warning_without_fs); + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */