From ed50f7e373906203c989e0d1b5bb4b6dbedc9969 Mon Sep 17 00:00:00 2001 From: arvinzzz Date: Sat, 7 Jan 2023 16:50:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=8D=E5=90=8Clibc=E4=B8=8Bgettimeof?= =?UTF-8?q?day=E7=89=B9=E6=80=A7=E8=A7=84=E6=A0=BC=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: arvinzzz Change-Id: Iaaf1fed24101f43c636737294dbe870d2f467b0a --- components/fs/vfs/vfs_fs.c | 10 +---- kal/libc/newlib/BUILD.gn | 3 +- kal/libc/newlib/porting/src/other_adapt.c | 7 ++- kal/libc/newlib/porting/src/time.c | 54 ----------------------- kal/posix/src/time.c | 36 +++++++-------- utils/los_compiler.h | 7 ++- 6 files changed, 30 insertions(+), 87 deletions(-) delete mode 100644 kal/libc/newlib/porting/src/time.c diff --git a/components/fs/vfs/vfs_fs.c b/components/fs/vfs/vfs_fs.c index 9606c024..6d929249 100644 --- a/components/fs/vfs/vfs_fs.c +++ b/components/fs/vfs/vfs_fs.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -50,14 +50,6 @@ #include "vfs_mount.h" #include "vfs_operations.h" -#if (LOSCFG_LIBC_NEWLIB == 1) -#define ALIAS_OF(of) __attribute__((alias(#of))) -#define FUNC_ALIAS(real_func, new_alias, args_list, return_type) \ - return_type new_alias args_list ALIAS_OF(real_func) -#else -#define FUNC_ALIAS(real_func, new_alias, args_list, return_type) -#endif - #ifdef LOSCFG_NET_LWIP_SACK #include "lwipopts.h" #include "lwip/sockets.h" diff --git a/kal/libc/newlib/BUILD.gn b/kal/libc/newlib/BUILD.gn index cfcf75a9..cd8f1133 100644 --- a/kal/libc/newlib/BUILD.gn +++ b/kal/libc/newlib/BUILD.gn @@ -1,5 +1,5 @@ # Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. -# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -39,7 +39,6 @@ kernel_module(module_name) { "porting/src/network/ntohl.c", "porting/src/network/ntohs.c", "porting/src/other_adapt.c", - "porting/src/time.c", ] configs += [ "$LITEOSTOPDIR:warn_config" ] diff --git a/kal/libc/newlib/porting/src/other_adapt.c b/kal/libc/newlib/porting/src/other_adapt.c index 547aab44..d7ee0d58 100644 --- a/kal/libc/newlib/porting/src/other_adapt.c +++ b/kal/libc/newlib/porting/src/other_adapt.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -35,6 +35,11 @@ #include #include +/* + * fs adapter interface, such as _read, see component/fs + * time adapter interface, such as _gettimeofday, see posix/src/time.c + */ + int _isatty(int file) { return (int)(file <= 2); // 2: stderr diff --git a/kal/libc/newlib/porting/src/time.c b/kal/libc/newlib/porting/src/time.c deleted file mode 100644 index 7213fce1..00000000 --- a/kal/libc/newlib/porting/src/time.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "los_tick.h" -#include -#include - -#define SECS_PER_MIN 60 - -int _gettimeofday(struct timeval *__tp, void *__tzp) -{ - struct timespec ts; - struct timezone *tz = (struct timezone *)__tzp; - - if (__tp != NULL) { - if (-1 == clock_gettime(CLOCK_REALTIME, &ts)) { - return -1; - } - __tp->tv_sec = ts.tv_sec; - __tp->tv_usec = ts.tv_nsec / OS_SYS_NS_PER_US; - } - if (tz != NULL) { - tz->tz_minuteswest = _timezone / SECS_PER_MIN; - tz->tz_dsttime = 0; - } - return 0; -} \ No newline at end of file diff --git a/kal/posix/src/time.c b/kal/posix/src/time.c index 97e93764..f9fc0c8b 100644 --- a/kal/posix/src/time.c +++ b/kal/posix/src/time.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -50,7 +50,6 @@ /* accumulative time delta from discontinuous modify */ STATIC struct timespec g_accDeltaFromSet; -#ifndef __USE_NEWLIB__ STATIC const UINT16 g_daysInMonth[2][13] = { /* Normal years. */ { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, @@ -59,20 +58,18 @@ STATIC const UINT16 g_daysInMonth[2][13] = { }; STATIC const UINT8 g_montbl[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; -#endif -#ifndef __USE_NEWLIB__ -#define g_timezone timezone +#if (LOSCFG_LIBC_NEWLIB == 1) +#define TIMEZONE _timezone #else -#define g_Timezone _timezone -#endif - +#define TIMEZONE timezone /* * Time zone information, stored in seconds, * negative values indicate the east of UTC, * positive values indicate the west of UTC. */ -long g_timezone = -8 * 60 * 60; // set default to CST(UTC+8) +long TIMEZONE = -8 * 60 * 60; // set default to CST(UTC+8) +#endif /* * store register rtc func @@ -529,7 +526,6 @@ time_t time(time_t *timer) } } -#ifndef __USE_NEWLIB__ /* * Compute the `struct tm' representation of T, * offset OFFSET seconds east of UTC, @@ -621,7 +617,7 @@ struct tm *localtime_r(const time_t *timep, struct tm *result) errno = EFAULT; return NULL; } - if (!ConvertSecs2Utc(*timep, -g_timezone, result)) { + if (!ConvertSecs2Utc(*timep, -TIMEZONE, result)) { errno = EINVAL; return NULL; } @@ -664,7 +660,7 @@ static time_t ConvertUtc2Secs(struct tm *tm) seconds += (tm->tm_mday - 1) * SECS_PER_DAY; seconds += tm->tm_hour * SECS_PER_HOUR + tm->tm_min * SECS_PER_MIN + tm->tm_sec; - seconds += g_timezone; + seconds += TIMEZONE; return seconds; } @@ -690,7 +686,7 @@ time_t mktime(struct tm *tmptr) } timeInSeconds = ConvertUtc2Secs(tmptr); /* normalize tm_wday and tm_yday */ - ConvertSecs2Utc(timeInSeconds, -g_timezone, tmptr); + ConvertSecs2Utc(timeInSeconds, -TIMEZONE, tmptr); return timeInSeconds; } @@ -724,19 +720,19 @@ int gettimeofday(struct timeval *tv, void *ptz) } if (tz != NULL) { - INT32 timeZone = 0; if (g_rtcTimeFunc.RtcGetTimezoneHook != NULL) { - g_rtcTimeFunc.RtcGetTimezoneHook(&timeZone); - tz->tz_minuteswest = timezone / SECS_PER_MIN; + INT32 tempTimezone = 0; + g_rtcTimeFunc.RtcGetTimezoneHook(&tempTimezone); + tz->tz_minuteswest = tempTimezone / SECS_PER_MIN; } else { - tz->tz_minuteswest = g_timezone / SECS_PER_MIN; + tz->tz_minuteswest = TIMEZONE / SECS_PER_MIN; } tz->tz_dsttime = 0; } return 0; } -#endif +FUNC_ALIAS(gettimeofday, _gettimeofday, (struct timeval *tv, void *ptz), int); int settimeofday(const struct timeval *tv, const struct timezone *tz) { @@ -755,14 +751,14 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz) if (tz != NULL) { if ((tz->tz_minuteswest >= TIME_ZONE_MIN) && (tz->tz_minuteswest <= TIME_ZONE_MAX)) { - g_timezone = tz->tz_minuteswest * SECS_PER_MIN; + TIMEZONE = tz->tz_minuteswest * SECS_PER_MIN; } else { errno = EINVAL; return -1; } if (g_rtcTimeFunc.RtcSetTimezoneHook != NULL) { - g_rtcTimeFunc.RtcSetTimezoneHook(g_timezone); + g_rtcTimeFunc.RtcSetTimezoneHook(TIMEZONE); } } diff --git a/utils/los_compiler.h b/utils/los_compiler.h index 820be684..d41cb3df 100644 --- a/utils/los_compiler.h +++ b/utils/los_compiler.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -526,6 +526,11 @@ static inline UINT64 __atomic_exchange_8(volatile void *mem, UINT64 val, int mod return ret; } #endif + +#define ALIAS_OF(of) __attribute__((alias(#of))) +#define FUNC_ALIAS(real_func, new_alias, args_list, return_type) \ + return_type new_alias args_list ALIAS_OF(real_func) + #endif #ifdef __cplusplus