refactor: 内核目录结构整理
1. 原kernel/common目录下属于内核拓展组件,统一移入kernel/extend管理 2. Kconfig分层,各模块自己的配置放到自己目录下管理 3. 原platform下不属于平台的公共代码抽到kernel/common下,只留板级链接脚本和一些编译脚本指向device目录下触发平台相关的编译 4. 对外公共头文件统一抽到对外include路径 5. 废弃宏,头文件清理 close: #I48KI4 Signed-off-by: arvinzzz <zhaotianyu9@huawei.com> Change-Id: I0cf5ea81c92a8fa7b113da9cbdc8b7bc935f5aae
This commit is contained in:
@@ -32,8 +32,10 @@ import("//kernel/liteos_a/liteos.gni")
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [
|
||||
"src/los_cir_buf.c",
|
||||
"src/los_crc32.c",
|
||||
"src/los_rbtree.c",
|
||||
"src/los_seq_buf.c",
|
||||
]
|
||||
|
||||
sources += [ "$LITEOSTHIRDPARTY/FreeBSD/sys/libkern/crc32.c" ]
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_CIRBUF_PRI_H
|
||||
#define _LOS_CIRBUF_PRI_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "los_spinlock.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef enum {
|
||||
CBUF_UNUSED,
|
||||
CBUF_USED
|
||||
} CirBufStatus;
|
||||
|
||||
typedef struct {
|
||||
UINT32 startIdx;
|
||||
UINT32 endIdx;
|
||||
UINT32 size;
|
||||
UINT32 remain;
|
||||
SPIN_LOCK_S lock;
|
||||
CirBufStatus status;
|
||||
CHAR *fifo;
|
||||
} CirBuf;
|
||||
|
||||
STATIC INLINE VOID LOS_CirBufLock(CirBuf *cirbufCB, UINT32 *intSave)
|
||||
{
|
||||
if (cirbufCB == NULL) {
|
||||
return;
|
||||
}
|
||||
LOS_SpinLockSave(&cirbufCB->lock, intSave);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID LOS_CirBufUnlock(CirBuf *cirbufCB, UINT32 intSave)
|
||||
{
|
||||
if (cirbufCB == NULL) {
|
||||
return;
|
||||
}
|
||||
LOS_SpinUnlockRestore(&cirbufCB->lock, intSave);
|
||||
}
|
||||
|
||||
extern UINT32 LOS_CirBufInit(CirBuf *cirbufCB, CHAR *fifo, UINT32 size);
|
||||
extern VOID LOS_CirBufDeinit(CirBuf *cirbufCB);
|
||||
extern UINT32 LOS_CirBufWrite(CirBuf *cirbufCB, const CHAR *buf, UINT32 size);
|
||||
extern UINT32 LOS_CirBufRead(CirBuf *cirbufCB, CHAR *buf, UINT32 size);
|
||||
extern UINT32 LOS_CirBufUsedSize(CirBuf *cirbufCB);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_CIRBUF_PRI_H */
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#ifndef __LOS_SEQ_BUF_H__
|
||||
#define __LOS_SEQ_BUF_H__
|
||||
|
||||
#include "stdarg.h"
|
||||
#include "stddef.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define SEQBUF_PAGE_SIZE 4096
|
||||
#define SEQBUF_LIMIT_SIZE (256 * SEQBUF_PAGE_SIZE)
|
||||
|
||||
struct SeqBuf {
|
||||
char *buf;
|
||||
size_t size;
|
||||
size_t count;
|
||||
void *private;
|
||||
};
|
||||
|
||||
struct SeqBuf *LosBufCreat(void);
|
||||
int LosBufPrintf(struct SeqBuf *seqBuf, const char *fmt, ...);
|
||||
int LosBufVprintf(struct SeqBuf *seqBuf, const char *fmt, va_list argList);
|
||||
int LosBufRelease(struct SeqBuf *seqBuf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-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_cir_buf.h"
|
||||
|
||||
|
||||
UINT32 LOS_CirBufUsedSize(CirBuf *cirbufCB)
|
||||
{
|
||||
UINT32 size;
|
||||
UINT32 intSave;
|
||||
|
||||
LOS_SpinLockSave(&cirbufCB->lock, &intSave);
|
||||
size = cirbufCB->size - cirbufCB->remain;
|
||||
LOS_SpinUnlockRestore(&cirbufCB->lock, intSave);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
/*
|
||||
* startIdx
|
||||
* |
|
||||
* 0 0 0 0 0 0 0 0 X X X X X X X X 0 0 0 0 0 0
|
||||
* |
|
||||
* endIdx
|
||||
*/
|
||||
STATIC UINT32 OsCirBufWriteLinear(CirBuf *cirbufCB, const CHAR *buf, UINT32 size)
|
||||
{
|
||||
UINT32 cpSize;
|
||||
errno_t err;
|
||||
|
||||
cpSize = (cirbufCB->remain < size) ? cirbufCB->remain : size;
|
||||
|
||||
if (cpSize == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = memcpy_s(cirbufCB->fifo + cirbufCB->endIdx, cirbufCB->remain, buf, cpSize);
|
||||
if (err != EOK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
cirbufCB->remain -= cpSize;
|
||||
cirbufCB->endIdx += cpSize;
|
||||
|
||||
return cpSize;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsCirBufWriteLoop(CirBuf *cirbufCB, const CHAR *buf, UINT32 size)
|
||||
{
|
||||
UINT32 right, cpSize;
|
||||
errno_t err;
|
||||
|
||||
right = cirbufCB->size - cirbufCB->endIdx;
|
||||
cpSize = (right < size) ? right : size;
|
||||
|
||||
err = memcpy_s(cirbufCB->fifo + cirbufCB->endIdx, right, buf, cpSize);
|
||||
if (err != EOK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
cirbufCB->remain -= cpSize;
|
||||
cirbufCB->endIdx += cpSize;
|
||||
if (cirbufCB->endIdx == cirbufCB->size) {
|
||||
cirbufCB->endIdx = 0;
|
||||
}
|
||||
|
||||
if (cpSize == size) {
|
||||
return size;
|
||||
} else {
|
||||
cpSize += OsCirBufWriteLinear(cirbufCB, buf + cpSize, size - cpSize);
|
||||
}
|
||||
|
||||
return cpSize;
|
||||
}
|
||||
|
||||
UINT32 LOS_CirBufWrite(CirBuf *cirbufCB, const CHAR *buf, UINT32 size)
|
||||
{
|
||||
UINT32 cpSize;
|
||||
|
||||
if ((cirbufCB == NULL) || (buf == NULL) || (size == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((cirbufCB->fifo == NULL) || (cirbufCB->remain == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cirbufCB->startIdx <= cirbufCB->endIdx) {
|
||||
cpSize = OsCirBufWriteLoop(cirbufCB, buf, size);
|
||||
} else {
|
||||
cpSize = OsCirBufWriteLinear(cirbufCB, buf, size);
|
||||
}
|
||||
|
||||
return cpSize;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsCirBufReadLinear(CirBuf *cirbufCB, CHAR *buf, UINT32 size)
|
||||
{
|
||||
UINT32 cpSize, remain;
|
||||
errno_t err;
|
||||
|
||||
remain = cirbufCB->endIdx - cirbufCB->startIdx;
|
||||
cpSize = (remain < size) ? remain : size;
|
||||
|
||||
if (cpSize == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = memcpy_s(buf, size, cirbufCB->fifo + cirbufCB->startIdx, cpSize);
|
||||
if (err != EOK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
cirbufCB->remain += cpSize;
|
||||
cirbufCB->startIdx += cpSize;
|
||||
|
||||
return cpSize;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsCirBufReadLoop(CirBuf *cirbufCB, CHAR *buf, UINT32 size)
|
||||
{
|
||||
UINT32 right, cpSize;
|
||||
errno_t err;
|
||||
|
||||
right = cirbufCB->size - cirbufCB->startIdx;
|
||||
cpSize = (right < size) ? right : size;
|
||||
|
||||
err = memcpy_s(buf, size, cirbufCB->fifo + cirbufCB->startIdx, cpSize);
|
||||
if (err != EOK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
cirbufCB->remain += cpSize;
|
||||
cirbufCB->startIdx += cpSize;
|
||||
if (cirbufCB->startIdx == cirbufCB->size) {
|
||||
cirbufCB->startIdx = 0;
|
||||
}
|
||||
|
||||
if (cpSize < size) {
|
||||
cpSize += OsCirBufReadLinear(cirbufCB, buf + cpSize, size - cpSize);
|
||||
}
|
||||
|
||||
return cpSize;
|
||||
}
|
||||
|
||||
UINT32 LOS_CirBufRead(CirBuf *cirbufCB, CHAR *buf, UINT32 size)
|
||||
{
|
||||
UINT32 cpSize;
|
||||
|
||||
if ((cirbufCB == NULL) || (buf == NULL) || (size == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((cirbufCB->fifo == NULL) || (cirbufCB->remain == cirbufCB->size)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cirbufCB->startIdx >= cirbufCB->endIdx) {
|
||||
cpSize = OsCirBufReadLoop(cirbufCB, buf, size);
|
||||
} else {
|
||||
cpSize = OsCirBufReadLinear(cirbufCB, buf, size);
|
||||
}
|
||||
|
||||
return cpSize;
|
||||
}
|
||||
|
||||
UINT32 LOS_CirBufInit(CirBuf *cirbufCB, CHAR *fifo, UINT32 size)
|
||||
{
|
||||
if ((cirbufCB == NULL) || (fifo == NULL)) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
(VOID)memset_s(cirbufCB, sizeof(CirBuf), 0, sizeof(CirBuf));
|
||||
LOS_SpinInit(&cirbufCB->lock);
|
||||
cirbufCB->size = size;
|
||||
cirbufCB->remain = size;
|
||||
cirbufCB->status = CBUF_USED;
|
||||
cirbufCB->fifo = fifo;
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID LOS_CirBufDeinit(CirBuf *cirbufCB)
|
||||
{
|
||||
(VOID)memset_s(cirbufCB, sizeof(CirBuf), 0, sizeof(CirBuf));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-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_seq_buf.h"
|
||||
#include "los_typedef.h"
|
||||
#include <stdlib.h>
|
||||
#include "securec.h"
|
||||
|
||||
static int ExpandSeqBuf(struct SeqBuf *seqBuf, size_t oldCount)
|
||||
{
|
||||
char *newBuf = NULL;
|
||||
int ret;
|
||||
|
||||
if ((seqBuf == NULL) || (seqBuf->buf == NULL)) {
|
||||
return -LOS_NOK;
|
||||
}
|
||||
|
||||
if (seqBuf->size >= SEQBUF_LIMIT_SIZE) {
|
||||
goto EXPAND_FAILED;
|
||||
}
|
||||
|
||||
newBuf = (char*)malloc(seqBuf->size <<= 1);
|
||||
if (newBuf == NULL) {
|
||||
goto EXPAND_FAILED;
|
||||
}
|
||||
(void)memset_s(newBuf + oldCount, seqBuf->size - oldCount, 0, seqBuf->size - oldCount);
|
||||
|
||||
ret = memcpy_s(newBuf, seqBuf->size, seqBuf->buf, oldCount);
|
||||
if (ret != LOS_OK) {
|
||||
free(newBuf);
|
||||
goto EXPAND_FAILED;
|
||||
}
|
||||
seqBuf->count = oldCount;
|
||||
|
||||
free(seqBuf->buf);
|
||||
seqBuf->buf = newBuf;
|
||||
|
||||
return LOS_OK;
|
||||
EXPAND_FAILED:
|
||||
free(seqBuf->buf);
|
||||
seqBuf->buf = NULL;
|
||||
seqBuf->count = 0;
|
||||
seqBuf->size = 0;
|
||||
|
||||
return -LOS_NOK;
|
||||
}
|
||||
|
||||
struct SeqBuf *LosBufCreat(void)
|
||||
{
|
||||
struct SeqBuf *seqBuf = NULL;
|
||||
|
||||
seqBuf = (struct SeqBuf *)malloc(sizeof(struct SeqBuf));
|
||||
if (seqBuf == NULL) {
|
||||
errno = -LOS_ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
(void)memset_s(seqBuf, sizeof(struct SeqBuf), 0, sizeof(struct SeqBuf));
|
||||
|
||||
return seqBuf;
|
||||
}
|
||||
|
||||
int LosBufVprintf(struct SeqBuf *seqBuf, const char *fmt, va_list argList)
|
||||
{
|
||||
bool needreprintf = FALSE;
|
||||
int bufLen;
|
||||
|
||||
if (seqBuf == NULL) {
|
||||
return -LOS_EPERM;
|
||||
}
|
||||
|
||||
if (seqBuf->buf == NULL) {
|
||||
seqBuf->size = SEQBUF_PAGE_SIZE;
|
||||
seqBuf->buf = (char *)malloc(seqBuf->size);
|
||||
if (seqBuf->buf == NULL) {
|
||||
return -LOS_ENOMEM;
|
||||
}
|
||||
(void)memset_s(seqBuf->buf, seqBuf->size, 0, seqBuf->size);
|
||||
seqBuf->count = 0;
|
||||
}
|
||||
|
||||
do {
|
||||
bufLen = vsnprintf_s(seqBuf->buf + seqBuf->count, seqBuf->size - seqBuf->count,
|
||||
seqBuf->size - seqBuf->count - 1, fmt, argList);
|
||||
if (bufLen >= 0) {
|
||||
/* succeed write. */
|
||||
seqBuf->count += bufLen;
|
||||
return 0;
|
||||
}
|
||||
if (seqBuf->buf[seqBuf->count] == '\0') {
|
||||
free(seqBuf->buf);
|
||||
seqBuf->buf = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
needreprintf = TRUE;
|
||||
|
||||
if (ExpandSeqBuf(seqBuf, seqBuf->count) != 0) {
|
||||
break;
|
||||
}
|
||||
} while (needreprintf);
|
||||
|
||||
return -LOS_NOK;
|
||||
}
|
||||
|
||||
int LosBufPrintf(struct SeqBuf *seqBuf, const char *fmt, ...)
|
||||
{
|
||||
va_list argList;
|
||||
int ret;
|
||||
|
||||
va_start(argList, fmt);
|
||||
ret = LosBufVprintf(seqBuf, fmt, argList);
|
||||
va_end(argList);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LosBufRelease(struct SeqBuf *seqBuf)
|
||||
{
|
||||
if (seqBuf == NULL) {
|
||||
return -LOS_EPERM;
|
||||
}
|
||||
|
||||
if (seqBuf->buf != NULL) {
|
||||
free(seqBuf->buf);
|
||||
seqBuf->buf = NULL;
|
||||
}
|
||||
free(seqBuf);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
Reference in New Issue
Block a user