[libc-commits] [libc] [libc] Add <glob.h> POSIX header. (PR #221362)

Alexey Samsonov via libc-commits libc-commits at lists.llvm.org
Fri Sep 4 16:02:59 PDT 2026


https://github.com/vonosmas created https://github.com/llvm/llvm-project/pull/221362

* Provide the `<glob.h>` header as defined in POSIX:
  https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/glob.h.html. 
* Provide declaration of `glob_t` struct type, and `GLOB_*` family of macros for controlling `glob()` function behavior and
  for describing `glob()` error return codes.
* Provide stubs / placeholder implementations for `glob()` and `globfree()` functions - similar to `fnmatch()`
  added in f571c5e34a06bc769924ff9100b6f31612279ab0 those would likely depend in part on pattern matching
  logic shared between them and with regex.
* Since there are no real implementations yet, only enable the header and entrypoints on Linux platforms with
  `LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS` specified.

>From 87070f20e5c63ea78e021b91dc20c67bbc51cdf1 Mon Sep 17 00:00:00 2001
From: Alexey Samsonov <vonosmas at gmail.com>
Date: Fri, 4 Sep 2026 22:55:17 +0000
Subject: [PATCH] [libc] Add <glob.h> POSIX header.

---
 libc/config/linux/aarch64/entrypoints.txt    |  4 ++
 libc/config/linux/aarch64/headers.txt        |  1 +
 libc/config/linux/riscv/entrypoints.txt      |  4 ++
 libc/config/linux/riscv/headers.txt          |  1 +
 libc/config/linux/x86_64/entrypoints.txt     |  4 ++
 libc/config/linux/x86_64/headers.txt         |  1 +
 libc/hdr/CMakeLists.txt                      |  8 ++++
 libc/hdr/glob_macros.h                       | 27 ++++++++++++
 libc/hdr/types/CMakeLists.txt                |  8 ++++
 libc/hdr/types/glob_t.h                      | 27 ++++++++++++
 libc/include/CMakeLists.txt                  | 11 +++++
 libc/include/glob.yaml                       | 45 ++++++++++++++++++++
 libc/include/llvm-libc-macros/CMakeLists.txt |  6 +++
 libc/include/llvm-libc-macros/glob-macros.h  | 31 ++++++++++++++
 libc/include/llvm-libc-types/CMakeLists.txt  |  1 +
 libc/include/llvm-libc-types/glob_t.h        | 25 +++++++++++
 libc/src/CMakeLists.txt                      |  1 +
 libc/src/glob/CMakeLists.txt                 | 24 +++++++++++
 libc/src/glob/glob.cpp                       | 31 ++++++++++++++
 libc/src/glob/glob.h                         | 28 ++++++++++++
 libc/src/glob/globfree.cpp                   | 26 +++++++++++
 libc/src/glob/globfree.h                     | 26 +++++++++++
 libc/test/src/CMakeLists.txt                 |  1 +
 libc/test/src/glob/CMakeLists.txt            | 14 ++++++
 libc/test/src/glob/glob_test.cpp             | 26 +++++++++++
 25 files changed, 381 insertions(+)
 create mode 100644 libc/hdr/glob_macros.h
 create mode 100644 libc/hdr/types/glob_t.h
 create mode 100644 libc/include/glob.yaml
 create mode 100644 libc/include/llvm-libc-macros/glob-macros.h
 create mode 100644 libc/include/llvm-libc-types/glob_t.h
 create mode 100644 libc/src/glob/CMakeLists.txt
 create mode 100644 libc/src/glob/glob.cpp
 create mode 100644 libc/src/glob/glob.h
 create mode 100644 libc/src/glob/globfree.cpp
 create mode 100644 libc/src/glob/globfree.h
 create mode 100644 libc/test/src/glob/CMakeLists.txt
 create mode 100644 libc/test/src/glob/glob_test.cpp

diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 4c707cb00912b..8a6f09097fdb2 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1401,6 +1401,10 @@ if(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
       # fnmatch.h entrypoints
       libc.src.fnmatch.fnmatch
 
+      # glob.h entrypoints
+      libc.src.glob.glob
+      libc.src.glob.globfree
+
       # net/if.h entrypoints
       libc.src.net.if_freenameindex
       libc.src.net.if_nameindex
diff --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index bb57af812d364..399149d4dde90 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -94,6 +94,7 @@ set(TARGET_PUBLIC_HEADERS
 
 if(LLVM_LIBC_FULL_BUILD AND LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
   list(APPEND TARGET_PUBLIC_HEADERS
+    libc.include.glob
     libc.include.netdb
     libc.include.regex
     libc.include.sys_ptrace
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 49bd22356e988..cac00bff173c0 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1619,6 +1619,10 @@ if(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
       # fnmatch.h entrypoints
       libc.src.fnmatch.fnmatch
 
+      # glob.h entrypoints
+      libc.src.glob.glob
+      libc.src.glob.globfree
+
       # net/if.h entrypoints
       libc.src.net.if_freenameindex
       libc.src.net.if_nameindex
diff --git a/libc/config/linux/riscv/headers.txt b/libc/config/linux/riscv/headers.txt
index 74e0dbc9277e5..fa5376bc1f1f8 100644
--- a/libc/config/linux/riscv/headers.txt
+++ b/libc/config/linux/riscv/headers.txt
@@ -93,6 +93,7 @@ set(TARGET_PUBLIC_HEADERS
 
 if(LLVM_LIBC_FULL_BUILD AND LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
   list(APPEND TARGET_PUBLIC_HEADERS
+    libc.include.glob
     libc.include.regex
     libc.include.sys_ptrace
   )
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index c645deea487c6..fae50098648aa 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1632,6 +1632,10 @@ if(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
       # fnmatch.h entrypoints
       libc.src.fnmatch.fnmatch
 
+      # glob.h entrypoints
+      libc.src.glob.glob
+      libc.src.glob.globfree
+
       # net/if.h entrypoints
       libc.src.net.if_freenameindex
       libc.src.net.if_nameindex
diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index ac06e5b5e742d..6df2b54216c1f 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -100,6 +100,7 @@ set(TARGET_PUBLIC_HEADERS
 
 if(LLVM_LIBC_FULL_BUILD AND LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
   list(APPEND TARGET_PUBLIC_HEADERS
+    libc.include.glob
     libc.include.netdb
     libc.include.regex
     libc.include.sys_ptrace
diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index 4d63860906ffc..061ff36f8b74f 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -80,6 +80,14 @@ add_proxy_header_library(
     libc.include.llvm-libc-macros.fnmatch_macros
 )
 
+add_proxy_header_library(
+  glob_macros
+  HDRS
+    glob_macros.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-macros.glob_macros
+)
+
 add_proxy_header_library(
   inet_address_macros
   HDRS
diff --git a/libc/hdr/glob_macros.h b/libc/hdr/glob_macros.h
new file mode 100644
index 0000000000000..194d2ca6afd2a
--- /dev/null
+++ b/libc/hdr/glob_macros.h
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Proxy header for glob macros.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_HDR_GLOB_MACROS_H
+#define LLVM_LIBC_HDR_GLOB_MACROS_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-macros/glob-macros.h"
+
+#else // Overlay mode
+
+#include <glob.h>
+
+#endif // LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_GLOB_MACROS_H
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index 33be74c1420c5..af5231b123a07 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -1310,6 +1310,14 @@ add_proxy_header_library(
     libc.include.search
 )
 
+add_proxy_header_library(
+  glob_t
+  HDRS
+    glob_t.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.glob_t
+)
+
 add_proxy_header_library(
   regex_t
   HDRS
diff --git a/libc/hdr/types/glob_t.h b/libc/hdr/types/glob_t.h
new file mode 100644
index 0000000000000..22bf5c3f019a2
--- /dev/null
+++ b/libc/hdr/types/glob_t.h
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Proxy header for glob_t.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_HDR_TYPES_GLOB_T_H
+#define LLVM_LIBC_HDR_TYPES_GLOB_T_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/glob_t.h"
+
+#else
+
+#include <glob.h>
+
+#endif // LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_GLOB_T_H
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 87b52bb756d11..35b7bdc8c184e 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -163,6 +163,17 @@ add_header_macro(
     .llvm-libc-macros.float_macros
 )
 
+add_header_macro(
+  glob
+  ../libc/include/glob.yaml
+  glob.h
+  DEPENDS
+    .llvm_libc_common_h
+    .llvm-libc-macros.glob_macros
+    .llvm-libc-types.glob_t
+    .llvm-libc-types.size_t
+)
+
 add_header_macro(
   grp
   ../libc/include/grp.yaml
diff --git a/libc/include/glob.yaml b/libc/include/glob.yaml
new file mode 100644
index 0000000000000..edc32b70b3e2b
--- /dev/null
+++ b/libc/include/glob.yaml
@@ -0,0 +1,45 @@
+header: glob.h
+standards:
+  - posix
+macros:
+  - macro_name: GLOB_APPEND
+    macro_header: glob-macros.h
+  - macro_name: GLOB_DOOFFS
+    macro_header: glob-macros.h
+  - macro_name: GLOB_ERR
+    macro_header: glob-macros.h
+  - macro_name: GLOB_MARK
+    macro_header: glob-macros.h
+  - macro_name: GLOB_NOCHECK
+    macro_header: glob-macros.h
+  - macro_name: GLOB_NOESCAPE
+    macro_header: glob-macros.h
+  - macro_name: GLOB_NOSORT
+    macro_header: glob-macros.h
+  - macro_name: GLOB_ABORTED
+    macro_header: glob-macros.h
+  - macro_name: GLOB_NOMATCH
+    macro_header: glob-macros.h
+  - macro_name: GLOB_NOSPACE
+    macro_header: glob-macros.h
+types:
+  - type_name: glob_t
+  - type_name: size_t
+enums: []
+objects: []
+functions:
+  - name: glob
+    standards:
+      - posix
+    return_type: int
+    arguments:
+      - type: const char *__restrict
+      - type: int
+      - type: int (*)(const char *, int)
+      - type: glob_t *__restrict
+  - name: globfree
+    standards:
+      - posix
+    return_type: void
+    arguments:
+      - type: glob_t *
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index e7f7d47659497..52d7f50c0858a 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -123,6 +123,12 @@ add_macro_header(
     fnmatch-macros.h
 )
 
+add_macro_header(
+  glob_macros
+  HDR
+    glob-macros.h
+)
+
 add_macro_header(
   file_seek_macros
   HDR
diff --git a/libc/include/llvm-libc-macros/glob-macros.h b/libc/include/llvm-libc-macros/glob-macros.h
new file mode 100644
index 0000000000000..58965202734ae
--- /dev/null
+++ b/libc/include/llvm-libc-macros/glob-macros.h
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Macros for POSIX glob.h.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_MACROS_GLOB_MACROS_H
+#define LLVM_LIBC_MACROS_GLOB_MACROS_H
+
+// Flags controlling glob() behavior.
+#define GLOB_ERR (1 << 0)
+#define GLOB_MARK (1 << 1)
+#define GLOB_NOSORT (1 << 2)
+#define GLOB_DOOFFS (1 << 3)
+#define GLOB_NOCHECK (1 << 4)
+#define GLOB_APPEND (1 << 5)
+#define GLOB_NOESCAPE (1 << 6)
+
+// glob() error return values.
+#define GLOB_NOSPACE 1
+#define GLOB_ABORTED 2
+#define GLOB_NOMATCH 3
+
+#endif // LLVM_LIBC_MACROS_GLOB_MACROS_H
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 381098968d2ec..8a944c9a5a573 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -308,6 +308,7 @@ add_header(ACTION HDR ACTION.h)
 add_header(ENTRY HDR ENTRY.h)
 add_header(VISIT HDR VISIT.h)
 add_header(struct_hsearch_data HDR struct_hsearch_data.h)
+add_header(glob_t HDR glob_t.h DEPENDS .size_t)
 add_header(regex_t HDR regex_t.h DEPENDS .size_t)
 add_header(regoff_t HDR regoff_t.h)
 add_header(regmatch_t HDR regmatch_t.h DEPENDS .regoff_t)
diff --git a/libc/include/llvm-libc-types/glob_t.h b/libc/include/llvm-libc-types/glob_t.h
new file mode 100644
index 0000000000000..811de9cab103d
--- /dev/null
+++ b/libc/include/llvm-libc-types/glob_t.h
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Type definition for glob_t.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_GLOB_T_H
+#define LLVM_LIBC_TYPES_GLOB_T_H
+
+#include "size_t.h"
+
+typedef struct {
+  size_t gl_pathc; // Count of paths matched by pattern.
+  char **gl_pathv; // Pointer to a list of matched pathnames.
+  size_t gl_offs;  // Slots to reserve at the beginning of gl_pathv.
+} glob_t;
+
+#endif // LLVM_LIBC_TYPES_GLOB_T_H
diff --git a/libc/src/CMakeLists.txt b/libc/src/CMakeLists.txt
index 483d21cadd432..ad2716cdc0724 100644
--- a/libc/src/CMakeLists.txt
+++ b/libc/src/CMakeLists.txt
@@ -7,6 +7,7 @@ add_subdirectory(dlfcn)
 add_subdirectory(errno)
 add_subdirectory(fenv)
 add_subdirectory(fnmatch)
+add_subdirectory(glob)
 add_subdirectory(inttypes)
 add_subdirectory(libgen)
 add_subdirectory(link)
diff --git a/libc/src/glob/CMakeLists.txt b/libc/src/glob/CMakeLists.txt
new file mode 100644
index 0000000000000..3c34c6b34f4e1
--- /dev/null
+++ b/libc/src/glob/CMakeLists.txt
@@ -0,0 +1,24 @@
+add_entrypoint_object(
+  glob
+  SRCS
+    glob.cpp
+  HDRS
+    glob.h
+  DEPENDS
+    libc.hdr.glob_macros
+    libc.hdr.types.glob_t
+    libc.src.__support.common
+    libc.src.__support.macros.config
+)
+
+add_entrypoint_object(
+  globfree
+  SRCS
+    globfree.cpp
+  HDRS
+    globfree.h
+  DEPENDS
+    libc.hdr.types.glob_t
+    libc.src.__support.common
+    libc.src.__support.macros.config
+)
diff --git a/libc/src/glob/glob.cpp b/libc/src/glob/glob.cpp
new file mode 100644
index 0000000000000..1e104a7bab024
--- /dev/null
+++ b/libc/src/glob/glob.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of glob.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/glob/glob.h"
+#include "hdr/glob_macros.h"
+#include "hdr/types/glob_t.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, glob,
+                   ([[maybe_unused]] const char *__restrict pattern,
+                    [[maybe_unused]] int flags,
+                    [[maybe_unused]] int (*errfunc)(const char *, int),
+                    [[maybe_unused]] glob_t *__restrict pglob)) {
+  // TODO: Implement glob.
+  return GLOB_NOMATCH;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/glob/glob.h b/libc/src/glob/glob.h
new file mode 100644
index 0000000000000..58e12af90c04e
--- /dev/null
+++ b/libc/src/glob/glob.h
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for glob.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_GLOB_GLOB_H
+#define LLVM_LIBC_SRC_GLOB_GLOB_H
+
+#include "hdr/types/glob_t.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int glob(const char *__restrict pattern, int flags,
+         int (*errfunc)(const char *epath, int eerrno),
+         glob_t *__restrict pglob);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_GLOB_GLOB_H
diff --git a/libc/src/glob/globfree.cpp b/libc/src/glob/globfree.cpp
new file mode 100644
index 0000000000000..a92fea768bb78
--- /dev/null
+++ b/libc/src/glob/globfree.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of globfree.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/glob/globfree.h"
+#include "hdr/types/glob_t.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(void, globfree, ([[maybe_unused]] glob_t * pglob)) {
+  // TODO: Implement globfree.
+  return;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/glob/globfree.h b/libc/src/glob/globfree.h
new file mode 100644
index 0000000000000..6c8015ac2745f
--- /dev/null
+++ b/libc/src/glob/globfree.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for globfree.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_GLOB_GLOBFREE_H
+#define LLVM_LIBC_SRC_GLOB_GLOBFREE_H
+
+#include "hdr/types/glob_t.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+void globfree(glob_t *pglob);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_GLOB_GLOBFREE_H
diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt
index d7e729c389abb..f8758930817ae 100644
--- a/libc/test/src/CMakeLists.txt
+++ b/libc/test/src/CMakeLists.txt
@@ -74,6 +74,7 @@ add_subdirectory(ctype)
 add_subdirectory(errno)
 add_subdirectory(fenv)
 add_subdirectory(fnmatch)
+add_subdirectory(glob)
 add_subdirectory(libgen)
 add_subdirectory(link)
 add_subdirectory(math)
diff --git a/libc/test/src/glob/CMakeLists.txt b/libc/test/src/glob/CMakeLists.txt
new file mode 100644
index 0000000000000..8410821bccb4e
--- /dev/null
+++ b/libc/test/src/glob/CMakeLists.txt
@@ -0,0 +1,14 @@
+add_custom_target(libc-glob-tests)
+
+add_libc_test(
+  glob_test
+  SUITE
+    libc-glob-tests
+  SRCS
+    glob_test.cpp
+  DEPENDS
+    libc.hdr.glob_macros
+    libc.hdr.types.glob_t
+    libc.src.glob.glob
+    libc.src.glob.globfree
+)
diff --git a/libc/test/src/glob/glob_test.cpp b/libc/test/src/glob/glob_test.cpp
new file mode 100644
index 0000000000000..e90d4e47226b5
--- /dev/null
+++ b/libc/test/src/glob/glob_test.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for glob and globfree.
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/glob_macros.h"
+#include "hdr/types/glob_t.h"
+#include "src/glob/glob.h"
+#include "src/glob/globfree.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcGlobTest, Dummy) {
+  glob_t globbuf = {};
+  EXPECT_EQ(LIBC_NAMESPACE::glob("/*", 0, nullptr, &globbuf), GLOB_NOMATCH);
+
+  // globfree should do nothing and not crash.
+  LIBC_NAMESPACE::globfree(&globbuf);
+}



More information about the libc-commits mailing list