diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt --- a/libc/config/linux/x86_64/headers.txt +++ b/libc/config/linux/x86_64/headers.txt @@ -10,6 +10,7 @@ libc.include.pthread libc.include.sched libc.include.signal + libc.include.search libc.include.spawn libc.include.setjmp libc.include.stdio diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt --- a/libc/include/CMakeLists.txt +++ b/libc/include/CMakeLists.txt @@ -241,6 +241,18 @@ .llvm-libc-types.posix_spawn_file_actions_t ) +add_gen_header( + search + DEF_FILE search.h.def + GEN_HDR search.h + DEPENDS + .llvm_libc_common_h + .llvm-libc-types.action + .llvm-libc-types.struct_hsearch_data + .llvm-libc-types.entry + .llvm-libc-types.size_t +) + # TODO: Not all platforms will have a include/sys directory. Add the sys # directory and the targets for sys/*.h files conditional to the OS requiring # them. diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt --- a/libc/include/llvm-libc-types/CMakeLists.txt +++ b/libc/include/llvm-libc-types/CMakeLists.txt @@ -84,3 +84,6 @@ add_header(tcflag_t HDR tcflag_t.h) add_header(struct_termios HDR struct_termios.h DEPENDS .cc_t .speed_t .tcflag_t) add_header(__getoptargv_t HDR __getoptargv_t.h) +add_header(action HDR action.h) +add_header(entry HDR entry.h) +add_header(struct_hsearch_data HDR struct_hsearch_data.h) diff --git a/libc/include/llvm-libc-types/action.h b/libc/include/llvm-libc-types/action.h new file mode 100644 --- /dev/null +++ b/libc/include/llvm-libc-types/action.h @@ -0,0 +1,14 @@ +//===-- Definition of type enum ACTION ------------------------------------===// +// +// 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_ENUM_ACTION_H__ +#define __LLVM_LIBC_TYPES_ENUM_ACTION_H__ + +typedef enum { FIND, ENTER } ACTION; + +#endif // __LLVM_LIBC_TYPES_ENUM_ACTION_H__ diff --git a/libc/include/llvm-libc-types/entry.h b/libc/include/llvm-libc-types/entry.h new file mode 100644 --- /dev/null +++ b/libc/include/llvm-libc-types/entry.h @@ -0,0 +1,17 @@ +//===-- Definition of type struct ENTRY -----------------------------------===// +// +// 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_STRUCT_ENTRY_H__ +#define __LLVM_LIBC_TYPES_STRUCT_ENTRY_H__ + +typedef struct { + char *key; + void *data; +} ENTRY; + +#endif // __LLVM_LIBC_TYPES_STRUCT_ENTRY_H__ diff --git a/libc/include/llvm-libc-types/struct_hsearch_data.h b/libc/include/llvm-libc-types/struct_hsearch_data.h new file mode 100644 --- /dev/null +++ b/libc/include/llvm-libc-types/struct_hsearch_data.h @@ -0,0 +1,17 @@ +//===-- Definition of type struct hsearch_data ----------------------------===// +// +// 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_STRUCT_HSEARCH_DATA_H__ +#define __LLVM_LIBC_TYPES_STRUCT_HSEARCH_DATA_H__ + +struct hsearch_data { + void *__opaque; + unsigned int __unused[2]; +}; + +#endif // __LLVM_LIBC_TYPES_STRUCT_HSEARCH_DATA_H__ diff --git a/libc/include/search.h.def b/libc/include/search.h.def new file mode 100644 --- /dev/null +++ b/libc/include/search.h.def @@ -0,0 +1,20 @@ +//===-- POSIX header search.h ---------------------------------------------===// +// +// 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_SEARCH_H +#define LLVM_LIBC_SEARCH_H + +#include <__llvm-libc-common.h> +#include +#include +#include +#include + +%%public_api() + +#endif // LLVM_LIBC_SEARCH_H diff --git a/libc/spec/posix.td b/libc/spec/posix.td --- a/libc/spec/posix.td +++ b/libc/spec/posix.td @@ -1008,6 +1008,71 @@ ] >; + NamedType StructHsearchDataName = NamedType<"struct hsearch_data">; + PtrType StructHsearchDataNamePtr = PtrType; + NamedType ActionType = NamedType<"ACTION">; + NamedType EntryType = NamedType<"ENTRY">; + PtrType EntryTypePtr = PtrType; + PtrType EntryTypePtrPtr = PtrType; + + HeaderSpec Search = HeaderSpec< + "search.h", + [], // Macros + [ + StructHsearchDataName, + ActionType, + EntryType + ], // Types + [], // Enumerations + [ + FunctionSpec< + "hcreate", + RetValSpec, + [ + ArgSpec + ] + >, + FunctionSpec< + "hcreate_r", + RetValSpec, + [ + ArgSpec, + ArgSpec + ] + >, + FunctionSpec< + "hdestroy", + RetValSpec, + [] // Args + >, + FunctionSpec< + "hdestroy_r", + RetValSpec, + [ + ArgSpec + ] + >, + FunctionSpec< + "hsearch", + RetValSpec, + [ + ArgSpec, + ArgSpec + ] + >, + FunctionSpec< + "hsearch_r", + RetValSpec, + [ + ArgSpec, + ArgSpec, + ArgSpec, + ArgSpec + ] + >, + ] + >; + HeaderSpec StdIO = HeaderSpec< "stdio.h", [], // Macros @@ -1267,6 +1332,7 @@ PThread, Signal, Spawn, + Search, StdIO, StdLib, SysIOctl,