mirror of
https://github.com/intel/llvm.git
synced 2026-02-08 00:50:03 +08:00
@@ -208,6 +208,7 @@ set(TARGET_LIBC_ENTRYPOINTS
|
||||
libc.src.stdio.sscanf
|
||||
libc.src.stdio.scanf
|
||||
libc.src.stdio.fscanf
|
||||
libc.src.stdio.fileno
|
||||
|
||||
# sys/epoll.h entrypoints
|
||||
libc.src.sys.epoll.epoll_wait
|
||||
|
||||
@@ -236,6 +236,16 @@ add_entrypoint_object(
|
||||
libc.src.stdio.printf_core.vfprintf_internal
|
||||
)
|
||||
|
||||
add_stdio_entrypoint_object(
|
||||
fileno
|
||||
SRCS
|
||||
fileno.cpp
|
||||
HDRS
|
||||
fileno.h
|
||||
DEPENDS
|
||||
libc.src.stdio.fileno
|
||||
)
|
||||
|
||||
add_subdirectory(printf_core)
|
||||
add_subdirectory(scanf_core)
|
||||
|
||||
|
||||
21
libc/src/stdio/fileno.h
Normal file
21
libc/src/stdio/fileno.h
Normal file
@@ -0,0 +1,21 @@
|
||||
//===-- Implementation header of fileno --------------------------*- C++
|
||||
//-*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIBC_SRC_STDIO_FILENO_H
|
||||
#define LLVM_LIBC_SRC_STDIO_FILENO_H
|
||||
|
||||
#include "include/llvm-libc-types/FILE.h"
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
int fileno(::FILE *f);
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
#endif // LLVM_LIBC_SRC_STDIO_FILENO_H
|
||||
@@ -70,6 +70,18 @@ add_entrypoint_object(
|
||||
libc.src.__support.File.platform_file
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
fileno
|
||||
SRCS
|
||||
fileno.cpp
|
||||
HDRS
|
||||
../fileno.h
|
||||
DEPENDS
|
||||
libc.include.stdio
|
||||
libc.src.__support.File.file
|
||||
libc.src.__support.File.platform_file
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
fflush
|
||||
SRCS
|
||||
|
||||
21
libc/src/stdio/generic/fileno.cpp
Normal file
21
libc/src/stdio/generic/fileno.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
//===-- Implementation of fileno
|
||||
//-------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/stdio/fileno.h"
|
||||
|
||||
#include "include/llvm-libc-types/FILE.h"
|
||||
#include "src/__support/File/file.h"
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, fileno, (::FILE * stream)) {
|
||||
return get_fileno(reinterpret_cast<LIBC_NAMESPACE::File *>(stream));
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
@@ -30,6 +30,7 @@ TEST(LlvmLibcFILETest, SimpleFileOperations) {
|
||||
constexpr char FILENAME[] = "testdata/simple_operations.test";
|
||||
::FILE *file = LIBC_NAMESPACE::fopen(FILENAME, "w");
|
||||
ASSERT_FALSE(file == nullptr);
|
||||
ASSERT_EQ(LIBC_NAMESPACE::fileno(file), 3);
|
||||
constexpr char CONTENT[] = "1234567890987654321";
|
||||
ASSERT_EQ(sizeof(CONTENT) - 1,
|
||||
LIBC_NAMESPACE::fwrite(CONTENT, 1, sizeof(CONTENT) - 1, file));
|
||||
|
||||
Reference in New Issue
Block a user