提交 b244ad4a 编写于 作者: W wangchen

feat: 解决fclose等函数工具链重定义问题

【背景】当前部分单板编译fclose等函数时与对应的gcc工具链重定义。

【修改方案】
1. fclose等函数新增weak定义,并恢复与musl源码一致。
2.外层添加wrap函数,用于配合gcc的--wrap选项。

【影响】
对现有的产品编译不会有影响,报重定义的工程需单独在自己的build.gn中添加
--wrap=xxx。

re #I3UG6O
Signed-off-by: Nwangchen <253227059@qq.com>
上级 beea9963
......@@ -6,6 +6,11 @@
#include <string.h>
#include <pthread.h>
int ioctl(int fd, int req, ...)
{
return 0;
}
FILE *__fdopen(int fd, const char *mode)
{
FILE *f;
......
......@@ -4,7 +4,7 @@
static void dummy(FILE *f) { }
weak_alias(dummy, __unlist_locked_file);
int fclose(FILE *f)
int __fclose(FILE *f)
{
int r;
......@@ -34,3 +34,4 @@ int fclose(FILE *f)
return r;
}
weak_alias(__fclose, fclose);
\ No newline at end of file
......@@ -5,16 +5,16 @@ static FILE *volatile dummy = 0;
weak_alias(dummy, __stdout_used);
weak_alias(dummy, __stderr_used);
int fflush(FILE *f)
int __fflush(FILE *f)
{
if (!f) {
int r = 0;
if (__stdout_used) r |= fflush(__stdout_used);
if (__stderr_used) r |= fflush(__stderr_used);
if (__stdout_used) r |= __fflush(__stdout_used);
if (__stderr_used) r |= __fflush(__stderr_used);
for (f=*__ofl_lock(); f; f=f->next) {
FLOCK(f);
if (f->wpos != f->wbase) r |= fflush(f);
if (f->wpos != f->wbase) r |= __fflush(f);
FUNLOCK(f);
}
__ofl_unlock();
......@@ -45,3 +45,4 @@ int fflush(FILE *f)
}
weak_alias(fflush, fflush_unlocked);
weak_alias(__fflush, fflush);
......@@ -15,7 +15,7 @@ int __fseeko_unlocked(FILE *f, off_t off, int whence)
f->wpos = f->wbase = f->wend = 0;
/* Perform the underlying seek. */
if (lseek(f->fd, (unsigned int)off, whence) < 0) return -1;
if (lseek(f->fd, off, whence) < 0) return -1;
/* If seek succeeded, file is seekable and we discard read buffer. */
f->rpos = f->rend = 0;
......
/*
* 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 "stdio_impl.h"
int __wrap_fclose(FILE *f)
{
return __fclose(f);
}
int __wrap_fflush(FILE *f)
{
return __fflush(f);
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册