fix: 不同libc下gettimeofday特性规格统一
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com> Change-Id: Iaaf1fed24101f43c636737294dbe870d2f467b0a
This commit is contained in:
parent
733b6e6c6c
commit
ed50f7e373
|
@ -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"
|
||||
|
|
|
@ -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" ]
|
||||
|
||||
|
|
|
@ -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 <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
|
|
@ -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 <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#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;
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue