Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.stdio.fileno
libc.src.stdio.flockfile
libc.src.stdio.fopen
libc.src.stdio.fopen_s
libc.src.stdio.fopencookie
libc.src.stdio.fputc
libc.src.stdio.fputs
Expand Down Expand Up @@ -1000,11 +1001,14 @@ if(LLVM_LIBC_FULL_BUILD)
# stdlib.h entrypoints
libc.src.stdlib._Exit
libc.src.stdlib.abort
libc.src.stdlib.abort_handler_s
libc.src.stdlib.at_quick_exit
libc.src.stdlib.atexit
libc.src.stdlib.exit
libc.src.stdlib.getenv
libc.src.stdlib.ignore_handler_s
libc.src.stdlib.quick_exit
libc.src.stdlib.set_constraint_handler_s

# signal.h entrypoints
libc.src.signal.kill
Expand Down
4 changes: 4 additions & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,7 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.stdio.fileno
libc.src.stdio.flockfile
libc.src.stdio.fopen
libc.src.stdio.fopen_s
libc.src.stdio.fopencookie
libc.src.stdio.fputc
libc.src.stdio.fputs
Expand Down Expand Up @@ -1126,11 +1127,14 @@ if(LLVM_LIBC_FULL_BUILD)
# stdlib.h entrypoints
libc.src.stdlib._Exit
libc.src.stdlib.abort
libc.src.stdlib.abort_handler_s
libc.src.stdlib.at_quick_exit
libc.src.stdlib.atexit
libc.src.stdlib.exit
libc.src.stdlib.getenv
libc.src.stdlib.ignore_handler_s
libc.src.stdlib.quick_exit
libc.src.stdlib.set_constraint_handler_s

# signal.h entrypoints
libc.src.signal.kill
Expand Down
4 changes: 4 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.stdio.fileno
libc.src.stdio.flockfile
libc.src.stdio.fopen
libc.src.stdio.fopen_s
libc.src.stdio.fopencookie
libc.src.stdio.fputc
libc.src.stdio.fputs
Expand Down Expand Up @@ -1161,11 +1162,14 @@ if(LLVM_LIBC_FULL_BUILD)
# stdlib.h entrypoints
libc.src.stdlib._Exit
libc.src.stdlib.abort
libc.src.stdlib.abort_handler_s
libc.src.stdlib.at_quick_exit
libc.src.stdlib.atexit
libc.src.stdlib.exit
libc.src.stdlib.getenv
libc.src.stdlib.ignore_handler_s
libc.src.stdlib.quick_exit
libc.src.stdlib.set_constraint_handler_s

# signal.h entrypoints
libc.src.signal.kill
Expand Down
18 changes: 18 additions & 0 deletions libc/hdr/types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,24 @@ add_proxy_header_library(
libc.include.fcntl
)

add_proxy_header_library(
errno_t
HDRS
errno_t.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.errno_t
libc.include.errno
)

add_proxy_header_library(
constraint_handler_t
HDRS
constraint_handler_t.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.constraint_handler_t
libc.include.stdlib
)

add_proxy_header_library(
fenv_t
HDRS
Expand Down
18 changes: 18 additions & 0 deletions libc/hdr/types/constraint_handler_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Proxy for constraint_handler_t ------------------------------------===//
//
// 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_HDR_TYPES_CONSTRAINT_HANDLER_T_H
#define LLVM_LIBC_HDR_TYPES_CONSTRAINT_HANDLER_T_H

#define LIBC_HAS_ANNEX_K

#include "include/llvm-libc-types/constraint_handler_t.h"

#undef LIBC_HAS_ANNEX_K

#endif // LLVM_LIBC_HDR_TYPES_CONSTRAINT_HANDLER_T_H
18 changes: 18 additions & 0 deletions libc/hdr/types/errno_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Proxy for errno_t -------------------------------------------------===//
//
// 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_HDR_TYPES_ERRNO_T_H
#define LLVM_LIBC_HDR_TYPES_ERRNO_T_H

#define LIBC_HAS_ANNEX_K

#include "include/llvm-libc-types/errno_t.h"

#undef LIBC_HAS_ANNEX_K

#endif // LLVM_LIBC_HDR_TYPES_ERRNO_T_H
5 changes: 5 additions & 0 deletions libc/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ add_header_macro(
DEPENDS
.llvm-libc-macros.generic_error_number_macros
.llvm-libc-macros.error_number_macros
.llvm-libc-types.errno_t
)

add_header_macro(
Expand Down Expand Up @@ -331,6 +332,7 @@ add_header_macro(
../libc/include/stdio.yaml
stdio.h
DEPENDS
.llvm-libc-macros.annex_k_macros
.llvm-libc-macros.file_seek_macros
.llvm-libc-macros.null_macro
.llvm-libc-macros.stdio_macros
Expand All @@ -339,6 +341,7 @@ add_header_macro(
.llvm-libc-types.off_t
.llvm-libc-types.size_t
.llvm-libc-types.ssize_t
.llvm-libc-types.errno_t
.llvm_libc_common_h
)

Expand All @@ -358,6 +361,8 @@ add_header_macro(
.llvm-libc-types.lldiv_t
.llvm-libc-types.locale_t
.llvm-libc-types.size_t
.llvm-libc-types.rsize_t
.llvm-libc-types.constraint_handler_t
.llvm_libc_common_h
)

Expand Down
2 changes: 2 additions & 0 deletions libc/include/errno.h.def
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ __END_C_DECLS

#define errno (*__llvm_libc_errno())

#include "llvm-libc-types/errno_t.h"

#endif // LLVM_LIBC_ERRNO_H
6 changes: 6 additions & 0 deletions libc/include/llvm-libc-macros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
endif()

add_macro_header(
annex_k_macros
HDR
annex-k-macros.h
)

add_macro_header(
assert_macros
HDR
Expand Down
25 changes: 25 additions & 0 deletions libc/include/llvm-libc-macros/annex-k-macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===-- Definition of macros to be used with Annex K functions ------------===//
//
// 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_INCLUDE_LLVM_LIBC_MACROS_ANNEX_K_MACROS_H
#define LLVM_LIBC_INCLUDE_LLVM_LIBC_MACROS_ANNEX_K_MACROS_H

#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
(defined(__cplusplus) && __cplusplus >= 201703L)

#define __STDC_LIB_EXT1__ 200509L

#if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ == 1

#define LIBC_HAS_ANNEX_K

#endif // defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ == 1

#endif // (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) ||
// (defined(__cplusplus) && __cplusplus >= 201703L)
#endif // LLVM_LIBC_INCLUDE_LLVM_LIBC_MACROS_ANNEX_K_MACROS_H
5 changes: 5 additions & 0 deletions libc/include/llvm-libc-types/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_header(off64_t HDR off64_t.h)
add_header(size_t HDR size_t.h)
add_header(rsize_t HDR rsize_t.h)
add_header(ssize_t HDR ssize_t.h)
add_header(__atfork_callback_t HDR __atfork_callback_t.h)
add_header(__search_compare_t HDR __search_compare_t.h)
Expand Down Expand Up @@ -289,3 +290,7 @@ add_header(EFI_SYSTEM_TABLE
.EFI_TABLE_HEADER
.char16_t
)

add_header(errno_t HDR errno_t.h)

add_header(constraint_handler_t HDR constraint_handler_t.h DEPENDS .errno_t)
21 changes: 21 additions & 0 deletions libc/include/llvm-libc-types/constraint_handler_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Definition of type constraint_handler_t ---------------------------===//
//
// 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_INCLUDE_LLVM_LIBC_TYPES_CONSTRAINT_HANDLER_T_H
#define LLVM_LIBC_INCLUDE_LLVM_LIBC_TYPES_CONSTRAINT_HANDLER_T_H

#include "errno_t.h"

#ifdef LIBC_HAS_ANNEX_K

typedef void (*constraint_handler_t)(const char *__restrict, void *__restrict,
errno_t);

#endif // LIBC_HAS_ANNEX_K

#endif // LLVM_LIBC_INCLUDE_LLVM_LIBC_TYPES_CONSTRAINT_HANDLER_T_H
18 changes: 18 additions & 0 deletions libc/include/llvm-libc-types/errno_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Definition of type errno_t ----------------------------------------===//
//
// 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_INCLUDE_LLVM_LIBC_TYPES_ERRNO_T_H
#define LLVM_LIBC_INCLUDE_LLVM_LIBC_TYPES_ERRNO_T_H

#ifdef LIBC_HAS_ANNEX_K

typedef int errno_t;

#endif // LIBC_HAS_ANNEX_K

#endif // LLVM_LIBC_INCLUDE_LLVM_LIBC_TYPES_ERRNO_T_H
18 changes: 18 additions & 0 deletions libc/include/llvm-libc-types/rsize_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Definition of rsize_t types ---------------------------------------===//
//
// 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_TYPES_RSIZE_T_H
#define LLVM_LIBC_TYPES_RSIZE_T_H

#ifdef LIBC_HAS_ANNEX_K

typedef __SIZE_TYPE__ rsize_t;

#endif // LIBC_HAS_ANNEX_K

#endif // LLVM_LIBC_TYPES_RSIZE_T_H
12 changes: 12 additions & 0 deletions libc/include/stdio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ macros:
macro_value: stdin
- macro_name: stderr
macro_value: stderr
- macro_name: LIBC_HAS_ANNEX_K
macro_header: annex-k-macros.h
types:
- type_name: size_t
- type_name: errno_t
- type_name: off_t
- type_name: cookie_io_functions_t
- type_name: FILE
Expand Down Expand Up @@ -125,6 +128,15 @@ functions:
arguments:
- type: const char *
- type: const char *
- name: fopen_s
guard: LIBC_HAS_ANNEX_K
standards:
- stdc
return_type: errno_t
arguments:
- type: FILE *__restrict *__restrict
- type: const char *__restrict
- type: const char *__restrict
- name: fopencookie
standards:
- GNUExtensions
Expand Down
32 changes: 31 additions & 1 deletion libc/include/stdlib.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ standards:
merge_yaml_files:
- stdlib-malloc.yaml
macros:
- macro_name: NULL
- macro_name: 'LIBC_HAS_ANNEX_K'
macro_header: annex-k-macros.h
- macro_name: 'NULL'
macro_header: null-macro.h
types:
- type_name: __atexithandler_t
Expand All @@ -17,6 +19,9 @@ types:
- type_name: lldiv_t
- type_name: locale_t
- type_name: size_t
- type_name: rsize_t
- type_name: errno_t
- type_name: constraint_handler_t
enums: []
objects: []
functions:
Expand Down Expand Up @@ -180,6 +185,31 @@ functions:
return_type: int
arguments:
- type: void
- name: set_constraint_handler_s
standards:
- stdc
return_type: constraint_handler_t
arguments:
- type: constraint_handler_t
guard: 'LIBC_HAS_ANNEX_K'
- name: abort_handler_s
standards:
- stdc
return_type: void
arguments:
- type: const char *__restrict
- type: void *__restrict
- type: errno_t
guard: 'LIBC_HAS_ANNEX_K'
- name: ignore_handler_s
standards:
- stdc
return_type: void
arguments:
- type: const char *__restrict
- type: void *__restrict
- type: errno_t
guard: 'LIBC_HAS_ANNEX_K'
- name: srand
standards:
- stdc
Expand Down
1 change: 1 addition & 0 deletions libc/src/stdio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ add_stdio_entrypoint_object(fflush)
add_stdio_entrypoint_object(clearerr)
add_stdio_entrypoint_object(clearerr_unlocked)
add_stdio_entrypoint_object(fopen)
add_stdio_entrypoint_object(fopen_s)
add_stdio_entrypoint_object(fclose)
add_stdio_entrypoint_object(fread_unlocked)
add_stdio_entrypoint_object(fread)
Expand Down
23 changes: 23 additions & 0 deletions libc/src/stdio/fopen_s.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- Implementation header of fopen_s ------------------------*- 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_FOPEN_S_H
#define LLVM_LIBC_SRC_STDIO_FOPEN_S_H

#include "hdr/types/FILE.h"
#include "hdr/types/errno_t.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

errno_t fopen_s(FILE *__restrict *__restrict streamptr,
const char *__restrict filename, const char *__restrict mode);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_STDIO_FOPEN_S_H
Loading
Loading