Compare commits
6 Commits
monthly_20
...
OpenHarmon
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1125b1c18d | ||
|
|
9603f02f6a | ||
|
|
7bae14ff6e | ||
|
|
0f1ee8fdf2 | ||
|
|
9c79993721 | ||
|
|
a8141a7b92 |
@@ -35,6 +35,7 @@ kernel_module(module_name) {
|
||||
sources = [
|
||||
"src/errno.c",
|
||||
"src/libc.c",
|
||||
"src/map_error.c",
|
||||
]
|
||||
configs += [ "$LITEOSTOPDIR:warn_config" ]
|
||||
|
||||
|
||||
100
kal/posix/src/map_error.c
Normal file
100
kal/posix/src/map_error.c
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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_mux.h"
|
||||
#include "los_queue.h"
|
||||
#include "los_sem.h"
|
||||
#include "los_task.h"
|
||||
#include <errno.h>
|
||||
|
||||
INT32 map_errno(UINT32 err)
|
||||
{
|
||||
if (err == LOS_OK) {
|
||||
return 0;
|
||||
}
|
||||
switch (err) {
|
||||
case LOS_ERRNO_QUEUE_INVALID:
|
||||
case LOS_ERRNO_QUEUE_WRITE_PTR_NULL:
|
||||
case LOS_ERRNO_QUEUE_WRITESIZE_ISZERO:
|
||||
case LOS_ERRNO_QUEUE_SIZE_TOO_BIG:
|
||||
case LOS_ERRNO_QUEUE_CREAT_PTR_NULL:
|
||||
case LOS_ERRNO_QUEUE_PARA_ISZERO:
|
||||
case LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG:
|
||||
case LOS_ERRNO_TSK_ID_INVALID:
|
||||
case LOS_ERRNO_TSK_PTR_NULL:
|
||||
case LOS_ERRNO_TSK_NAME_EMPTY:
|
||||
case LOS_ERRNO_TSK_ENTRY_NULL:
|
||||
case LOS_ERRNO_TSK_PRIOR_ERROR:
|
||||
case LOS_ERRNO_TSK_STKSZ_TOO_LARGE:
|
||||
case LOS_ERRNO_TSK_STKSZ_TOO_SMALL:
|
||||
case LOS_ERRNO_TSK_NOT_CREATED:
|
||||
case OS_ERROR:
|
||||
case LOS_ERRNO_SEM_INVALID:
|
||||
case LOS_ERRNO_SEM_UNAVAILABLE:
|
||||
errno = EINVAL;
|
||||
break;
|
||||
case LOS_ERRNO_QUEUE_ISFULL:
|
||||
case LOS_ERRNO_QUEUE_ISEMPTY:
|
||||
errno = EAGAIN;
|
||||
break;
|
||||
case LOS_ERRNO_QUEUE_CREATE_NO_MEMORY:
|
||||
case LOS_ERRNO_TSK_TCB_UNAVAILABLE:
|
||||
case LOS_ERRNO_SEM_ALL_BUSY:
|
||||
errno = ENOSPC;
|
||||
break;
|
||||
case LOS_ERRNO_QUEUE_TIMEOUT:
|
||||
case LOS_ERRNO_SEM_TIMEOUT:
|
||||
errno = ETIMEDOUT;
|
||||
break;
|
||||
case LOS_ERRNO_QUEUE_CB_UNAVAILABLE:
|
||||
errno = ENFILE;
|
||||
break;
|
||||
case LOS_ERRNO_QUEUE_READ_IN_INTERRUPT:
|
||||
case LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT:
|
||||
case LOS_ERRNO_SEM_PEND_INTERR:
|
||||
errno = EINTR;
|
||||
break;
|
||||
case LOS_ERRNO_TSK_NO_MEMORY:
|
||||
case LOS_ERRNO_SEM_OVERFLOW:
|
||||
errno = ENOMEM;
|
||||
break;
|
||||
case LOS_ERRNO_SEM_PENDED:
|
||||
errno = EBUSY;
|
||||
break;
|
||||
case LOS_ERRNO_SEM_PEND_IN_LOCK:
|
||||
errno = EPERM;
|
||||
break;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
break;
|
||||
}
|
||||
return errno;
|
||||
}
|
||||
|
||||
48
kal/posix/src/map_error.h
Normal file
48
kal/posix/src/map_error.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _POSIX_MAP_ERROR_H
|
||||
#define _POSIX_MAP_ERROR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
INT32 map_errno(UINT32 err);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "los_config.h"
|
||||
#include "los_task.h"
|
||||
#include "los_debug.h"
|
||||
#include "map_error.h"
|
||||
|
||||
#define PTHREAD_DEFAULT_NAME "pthread"
|
||||
#define PTHREAD_DEFAULT_NAME_LEN 8
|
||||
@@ -207,9 +208,10 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (LOS_TaskCreateOnly(&taskID, &taskInitParam) != LOS_OK) {
|
||||
ret = LOS_TaskCreateOnly(&taskID, &taskInitParam);
|
||||
if (ret != LOS_OK) {
|
||||
free((VOID *)(UINTPTR)taskInitParam.uwArg);
|
||||
return EINVAL;
|
||||
return map_errno(ret);
|
||||
}
|
||||
|
||||
PthreadData *pthreadData = (PthreadData *)taskInitParam.uwArg;
|
||||
|
||||
@@ -303,7 +303,6 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
|
||||
PRINT_ERR("%s: %d failed\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
(VOID)LOS_EventClear(&(cond->event), 0);
|
||||
ret = (INT32)LOS_EventRead(&(cond->event), 0x0f, LOS_WAITMODE_OR | LOS_WAITMODE_CLR, (UINT32)absTicks);
|
||||
|
||||
if (pthread_mutex_lock(mutex) != 0) {
|
||||
|
||||
@@ -617,11 +617,22 @@ struct tm *gmtime(const time_t *timer)
|
||||
|
||||
struct tm *localtime_r(const time_t *timep, struct tm *result)
|
||||
{
|
||||
INT32 ret;
|
||||
|
||||
if ((timep == NULL) || (result == NULL)) {
|
||||
errno = EFAULT;
|
||||
return NULL;
|
||||
}
|
||||
if (!ConvertSecs2Utc(*timep, -g_timezone, result)) {
|
||||
|
||||
if (g_rtcTimeFunc.RtcGetTimezoneHook != NULL) {
|
||||
INT32 tempTimezone = 0;
|
||||
g_rtcTimeFunc.RtcGetTimezoneHook(&tempTimezone);
|
||||
ret = ConvertSecs2Utc(*timep, -tempTimezone, result);
|
||||
} else {
|
||||
ret = ConvertSecs2Utc(*timep, -g_timezone, result);
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
@@ -664,7 +675,14 @@ 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;
|
||||
if (g_rtcTimeFunc.RtcGetTimezoneHook != NULL) {
|
||||
INT32 tempTimezone = 0;
|
||||
g_rtcTimeFunc.RtcGetTimezoneHook(&tempTimezone);
|
||||
seconds += tempTimezone;
|
||||
} else {
|
||||
seconds += g_timezone;
|
||||
}
|
||||
|
||||
return seconds;
|
||||
}
|
||||
|
||||
@@ -690,7 +708,14 @@ time_t mktime(struct tm *tmptr)
|
||||
}
|
||||
timeInSeconds = ConvertUtc2Secs(tmptr);
|
||||
/* normalize tm_wday and tm_yday */
|
||||
ConvertSecs2Utc(timeInSeconds, -g_timezone, tmptr);
|
||||
if (g_rtcTimeFunc.RtcGetTimezoneHook != NULL) {
|
||||
INT32 tempTimezone = 0;
|
||||
g_rtcTimeFunc.RtcGetTimezoneHook(&tempTimezone);
|
||||
ConvertSecs2Utc(timeInSeconds, -tempTimezone, tmptr);
|
||||
} else {
|
||||
ConvertSecs2Utc(timeInSeconds, -g_timezone, tmptr);
|
||||
}
|
||||
|
||||
return timeInSeconds;
|
||||
}
|
||||
|
||||
@@ -722,7 +747,7 @@ int gettimeofday(struct timeval *tv, void *ptz)
|
||||
tv->tv_usec = ts.tv_nsec / OS_SYS_NS_PER_US;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (tz != NULL) {
|
||||
INT32 timeZone = 0;
|
||||
if (g_rtcTimeFunc.RtcGetTimezoneHook != NULL) {
|
||||
@@ -742,12 +767,12 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
|
||||
{
|
||||
struct timespec ts;
|
||||
|
||||
if (tv == NULL) {
|
||||
if ((tv == NULL) && (tz == NULL)) {
|
||||
errno = EFAULT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tv->tv_usec >= OS_SYS_US_PER_SECOND) {
|
||||
if ((tv != NULL) && (tv->tv_usec >= OS_SYS_US_PER_SECOND)) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
@@ -766,18 +791,20 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
|
||||
}
|
||||
}
|
||||
|
||||
if (g_rtcTimeFunc.RtcSetTimeHook != NULL) {
|
||||
UINT64 usec;
|
||||
g_rtcTimeBase = tv->tv_sec * OS_SYS_MS_PER_SECOND + tv->tv_usec / OS_SYS_MS_PER_SECOND;
|
||||
usec = tv->tv_sec * OS_SYS_US_PER_SECOND + tv->tv_usec;
|
||||
if (-1 == g_rtcTimeFunc.RtcSetTimeHook(g_rtcTimeBase, &usec)) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
ts.tv_sec = tv->tv_sec;
|
||||
ts.tv_nsec = tv->tv_usec * OS_SYS_NS_PER_US;
|
||||
if (-1 == clock_settime(CLOCK_REALTIME, &ts)) {
|
||||
return -1;
|
||||
if (tv != NULL) {
|
||||
if (g_rtcTimeFunc.RtcSetTimeHook != NULL) {
|
||||
UINT64 usec;
|
||||
g_rtcTimeBase = tv->tv_sec * OS_SYS_MS_PER_SECOND + tv->tv_usec / OS_SYS_MS_PER_SECOND;
|
||||
usec = tv->tv_sec * OS_SYS_US_PER_SECOND + tv->tv_usec;
|
||||
if (g_rtcTimeFunc.RtcSetTimeHook(g_rtcTimeBase, &usec) < 0) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
ts.tv_sec = tv->tv_sec;
|
||||
ts.tv_nsec = tv->tv_usec * OS_SYS_NS_PER_US;
|
||||
if (clock_settime(CLOCK_REALTIME, &ts) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -288,6 +288,42 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltime002, Function | MediumTe
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_TIME_LOCALTIME_003
|
||||
* @tc.name test settimeofday api
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltime003, Function | MediumTest | Level1)
|
||||
{
|
||||
char cTime[32]; /* 32, no special meaning */
|
||||
time_t tStart;
|
||||
time_t tEnd;
|
||||
struct timezone tz;
|
||||
struct timeval timeSet = {
|
||||
.tv_sec = 86399, /* 86399, no special meaning */
|
||||
.tv_usec = 0
|
||||
};
|
||||
|
||||
int ret = gettimeofday(NULL, &tz);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = settimeofday(&timeSet, &tz);
|
||||
time(&tStart);
|
||||
sleep(2); /* 2, no special meaning */
|
||||
time(&tEnd);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
struct tm *tmStart = localtime(&tStart);
|
||||
strftime(cTime, sizeof(cTime), "%H:%M:%S", tmStart);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(cTime, "07:59:59", 0);
|
||||
LOG("\n time_t=%lld, first time:%s", tStart, cTime);
|
||||
struct tm *tmEnd = localtime(&tEnd);
|
||||
strftime(cTime, sizeof(cTime), "%H:%M:%S", tmEnd);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(cTime, "08:00:01", 0);
|
||||
LOG("\n time_t=%lld, first time:%s", tEnd, cTime);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_TIME_LOCALTIMER_001
|
||||
* @tc.name localtime_r api base test
|
||||
@@ -579,6 +615,7 @@ void PosixTimeFuncTest(void)
|
||||
#if (LOSCFG_LIBC_MUSL == 1)
|
||||
RUN_ONE_TESTCASE(testTimeLocaltime001);
|
||||
RUN_ONE_TESTCASE(testTimeLocaltime002);
|
||||
RUN_ONE_TESTCASE(testTimeLocaltime003);
|
||||
RUN_ONE_TESTCASE(testTimeLocaltimer001);
|
||||
RUN_ONE_TESTCASE(testTimeLocaltimer002);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user