[libc-commits] [libc] [libc] add sys/inotify (PR #230314)

via libc-commits libc-commits at lists.llvm.org
Thu Oct 8 16:03:23 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

<details>
<summary>Changes</summary>

The sys/inotify header has linux functions for watching a directory.
This PR adds those functions, and their relevant macros and type. Tests
are fairly simple since the functions are all syscall wrappers.

Assisted-by: Automated tooling, human reviewed


---

Patch is 44.69 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/230314.diff


41 Files Affected:

- (modified) libc/config/linux/aarch64/entrypoints.txt (+6) 
- (modified) libc/config/linux/aarch64/headers.txt (+1) 
- (modified) libc/config/linux/arm/entrypoints.txt (+6) 
- (modified) libc/config/linux/arm/headers.txt (+1) 
- (modified) libc/config/linux/riscv/entrypoints.txt (+6) 
- (modified) libc/config/linux/riscv/headers.txt (+1) 
- (modified) libc/config/linux/x86_64/entrypoints.txt (+6) 
- (modified) libc/config/linux/x86_64/headers.txt (+1) 
- (modified) libc/hdr/CMakeLists.txt (+8) 
- (added) libc/hdr/sys_inotify_macros.h (+27) 
- (modified) libc/include/CMakeLists.txt (+11) 
- (modified) libc/include/llvm-libc-macros/CMakeLists.txt (+8) 
- (modified) libc/include/llvm-libc-macros/linux/CMakeLists.txt (+6) 
- (added) libc/include/llvm-libc-macros/linux/sys-inotify-macros.h (+54) 
- (added) libc/include/llvm-libc-macros/sys-inotify-macros.h (+21) 
- (modified) libc/include/llvm-libc-types/CMakeLists.txt (+1) 
- (added) libc/include/llvm-libc-types/struct_inotify_event.h (+27) 
- (added) libc/include/sys/inotify.yaml (+82) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt (+49) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/inotify_add_watch.h (+35) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/inotify_init.h (+40) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/inotify_init1.h (+33) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/inotify_rm_watch.h (+33) 
- (modified) libc/src/sys/CMakeLists.txt (+1) 
- (added) libc/src/sys/inotify/CMakeLists.txt (+31) 
- (added) libc/src/sys/inotify/inotify_add_watch.h (+26) 
- (added) libc/src/sys/inotify/inotify_init.h (+25) 
- (added) libc/src/sys/inotify/inotify_init1.h (+25) 
- (added) libc/src/sys/inotify/inotify_rm_watch.h (+25) 
- (added) libc/src/sys/inotify/linux/CMakeLists.txt (+56) 
- (added) libc/src/sys/inotify/linux/inotify_add_watch.cpp (+34) 
- (added) libc/src/sys/inotify/linux/inotify_init.cpp (+32) 
- (added) libc/src/sys/inotify/linux/inotify_init1.cpp (+32) 
- (added) libc/src/sys/inotify/linux/inotify_rm_watch.cpp (+32) 
- (modified) libc/test/src/sys/CMakeLists.txt (+1) 
- (added) libc/test/src/sys/inotify/CMakeLists.txt (+3) 
- (added) libc/test/src/sys/inotify/linux/CMakeLists.txt (+73) 
- (added) libc/test/src/sys/inotify/linux/inotify_add_watch_test.cpp (+40) 
- (added) libc/test/src/sys/inotify/linux/inotify_init1_test.cpp (+34) 
- (added) libc/test/src/sys/inotify/linux/inotify_init_test.cpp (+50) 
- (added) libc/test/src/sys/inotify/linux/inotify_rm_watch_test.cpp (+45) 


``````````diff
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index b8ea3258262c83..5bfad95231133e 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -427,6 +427,12 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.sys.sysmacros.major
     libc.src.sys.sysmacros.minor
 
+    # sys/inotify.h entrypoints
+    libc.src.sys.inotify.inotify_add_watch
+    libc.src.sys.inotify.inotify_init
+    libc.src.sys.inotify.inotify_init1
+    libc.src.sys.inotify.inotify_rm_watch
+
     # termios.h entrypoints
     libc.src.termios.cfgetispeed
     libc.src.termios.cfgetospeed
diff --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index 4317f3e7bd18ea..5a2083c8f39d39 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -52,6 +52,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.sys_epoll
     libc.include.sys_fcntl
     libc.include.sys_file
+    libc.include.sys_inotify
     libc.include.sys_ioctl
     libc.include.sys_mman
     libc.include.sys_mount
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index f7714b2049a27f..ac66f1f5184842 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -213,6 +213,12 @@ set(TARGET_LIBC_ENTRYPOINTS
     # stdio.h entrypoints
     libc.src.stdio.tmpfile
 
+    # sys/inotify.h entrypoints
+    libc.src.sys.inotify.inotify_add_watch
+    libc.src.sys.inotify.inotify_init
+    libc.src.sys.inotify.inotify_init1
+    libc.src.sys.inotify.inotify_rm_watch
+
     # sys/ioctl.h entrypoints
     libc.src.sys.ioctl.ioctl
 
diff --git a/libc/config/linux/arm/headers.txt b/libc/config/linux/arm/headers.txt
index af0631843a157f..a46840383142ae 100644
--- a/libc/config/linux/arm/headers.txt
+++ b/libc/config/linux/arm/headers.txt
@@ -27,6 +27,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.unistd
     libc.include.wchar
     libc.include.wctype
+    libc.include.sys_inotify
     libc.include.sys_param
     libc.include.sys_personality
     libc.include.sys_sysinfo
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index af7586e61e098f..e5c886d53779dc 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -447,6 +447,12 @@ set(TARGET_LIBC_ENTRYPOINTS
     # sys/auxv.h entrypoints
     libc.src.sys.auxv.getauxval
 
+    # sys/inotify.h entrypoints
+    libc.src.sys.inotify.inotify_add_watch
+    libc.src.sys.inotify.inotify_init
+    libc.src.sys.inotify.inotify_init1
+    libc.src.sys.inotify.inotify_rm_watch
+
     # termios.h entrypoints
     libc.src.termios.cfgetispeed
     libc.src.termios.cfgetospeed
diff --git a/libc/config/linux/riscv/headers.txt b/libc/config/linux/riscv/headers.txt
index a0c7330ebe19f5..19d13a8574bc41 100644
--- a/libc/config/linux/riscv/headers.txt
+++ b/libc/config/linux/riscv/headers.txt
@@ -53,6 +53,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.sys_epoll
     libc.include.sys_fcntl
     libc.include.sys_file
+    libc.include.sys_inotify
     libc.include.sys_ioctl
     libc.include.sys_mman
     libc.include.sys_param
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index b386e049255b56..aec72d78fb5354 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -467,6 +467,12 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.sys.sysmacros.major
     libc.src.sys.sysmacros.minor
 
+    # sys/inotify.h entrypoints
+    libc.src.sys.inotify.inotify_add_watch
+    libc.src.sys.inotify.inotify_init
+    libc.src.sys.inotify.inotify_init1
+    libc.src.sys.inotify.inotify_rm_watch
+
     # termios.h entrypoints
     libc.src.termios.cfgetispeed
     libc.src.termios.cfgetospeed
diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index ea327ad0386dae..426972553b93b2 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -53,6 +53,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.sys_epoll
     libc.include.sys_fcntl
     libc.include.sys_file
+    libc.include.sys_inotify
     libc.include.sys_ioctl
     libc.include.sys_ipc
     libc.include.sys_mman
diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index 63077607bb4fbc..cf8b1f36d349ec 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -205,6 +205,14 @@ add_proxy_header_library(
     libc.include.llvm-libc-macros.sys_file_macros
 )
 
+add_proxy_header_library(
+  sys_inotify_macros
+  HDRS
+    sys_inotify_macros.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-macros.sys_inotify_macros
+)
+
 add_proxy_header_library(
   sys_ioctl_macros
   HDRS
diff --git a/libc/hdr/sys_inotify_macros.h b/libc/hdr/sys_inotify_macros.h
new file mode 100644
index 00000000000000..997a21bde9e89c
--- /dev/null
+++ b/libc/hdr/sys_inotify_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 macro values defined in sys/inotify.h.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_HDR_SYS_INOTIFY_MACROS_H
+#define LLVM_LIBC_HDR_SYS_INOTIFY_MACROS_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-macros/sys-inotify-macros.h"
+
+#else // Overlay mode
+
+#include <sys/inotify.h>
+
+#endif // LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_SYS_INOTIFY_MACROS_H
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 2fe1f92afc1d19..7b8dee2b4aa77e 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -747,6 +747,17 @@ add_header_macro(
     .llvm-libc-types.struct_winsize
 )
 
+add_header_macro(
+  sys_inotify
+  ../libc/include/sys/inotify.yaml
+  sys/inotify.h
+  DEPENDS
+    .llvm_libc_common_h
+    .llvm-libc-macros.sys_inotify_macros
+    .llvm-libc-types.struct_inotify_event
+    .stdint
+)
+
 add_header_macro(
   sys_ipc
   ../libc/include/sys/ipc.yaml
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index 309d1c78da42eb..dccbba272022f7 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -292,6 +292,14 @@ add_macro_header(
     sys-ioctl-macros.h
 )
 
+add_macro_header(
+  sys_inotify_macros
+  HDR
+    sys-inotify-macros.h
+  DEPENDS
+    .fcntl_macros
+)
+
 add_macro_header(
   sys_ipc_macros
   HDR
diff --git a/libc/include/llvm-libc-macros/linux/CMakeLists.txt b/libc/include/llvm-libc-macros/linux/CMakeLists.txt
index a634b0a9eb9e98..2b3fa2c027fa85 100644
--- a/libc/include/llvm-libc-macros/linux/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/linux/CMakeLists.txt
@@ -46,6 +46,12 @@ add_header(
     sys-ioctl-macros.h
 )
 
+add_header(
+  sys_inotify_macros
+  HDR
+    sys-inotify-macros.h
+)
+
 add_header(
   sys_ipc_macros
   HDR
diff --git a/libc/include/llvm-libc-macros/linux/sys-inotify-macros.h b/libc/include/llvm-libc-macros/linux/sys-inotify-macros.h
new file mode 100644
index 00000000000000..03679938d0d4df
--- /dev/null
+++ b/libc/include/llvm-libc-macros/linux/sys-inotify-macros.h
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 defined in sys/inotify.h header file.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_MACROS_LINUX_SYS_INOTIFY_MACROS_H
+#define LLVM_LIBC_MACROS_LINUX_SYS_INOTIFY_MACROS_H
+
+#include "fcntl-macros.h"
+
+#define IN_CLOEXEC O_CLOEXEC
+#define IN_NONBLOCK O_NONBLOCK
+
+#define IN_ACCESS 0x00000001
+#define IN_MODIFY 0x00000002
+#define IN_ATTRIB 0x00000004
+#define IN_CLOSE_WRITE 0x00000008
+#define IN_CLOSE_NOWRITE 0x00000010
+#define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE)
+#define IN_OPEN 0x00000020
+#define IN_MOVED_FROM 0x00000040
+#define IN_MOVED_TO 0x00000080
+#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO)
+#define IN_CREATE 0x00000100
+#define IN_DELETE 0x00000200
+#define IN_DELETE_SELF 0x00000400
+#define IN_MOVE_SELF 0x00000800
+
+#define IN_UNMOUNT 0x00002000
+#define IN_Q_OVERFLOW 0x00004000
+#define IN_IGNORED 0x00008000
+
+#define IN_ONLYDIR 0x01000000
+#define IN_DONT_FOLLOW 0x02000000
+#define IN_EXCL_UNLINK 0x04000000
+#define IN_MASK_CREATE 0x10000000
+#define IN_MASK_ADD 0x20000000
+#define IN_ISDIR 0x40000000
+#define IN_ONESHOT 0x80000000
+
+#define IN_ALL_EVENTS                                                          \
+  (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | IN_CLOSE_NOWRITE |     \
+   IN_OPEN | IN_MOVED_FROM | IN_MOVED_TO | IN_CREATE | IN_DELETE |             \
+   IN_DELETE_SELF | IN_MOVE_SELF)
+
+#endif // LLVM_LIBC_MACROS_LINUX_SYS_INOTIFY_MACROS_H
diff --git a/libc/include/llvm-libc-macros/sys-inotify-macros.h b/libc/include/llvm-libc-macros/sys-inotify-macros.h
new file mode 100644
index 00000000000000..b77e9842ad14f5
--- /dev/null
+++ b/libc/include/llvm-libc-macros/sys-inotify-macros.h
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 defined in sys/inotify.h header file.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_MACROS_SYS_INOTIFY_MACROS_H
+#define LLVM_LIBC_MACROS_SYS_INOTIFY_MACROS_H
+
+#ifdef __linux__
+#include "linux/sys-inotify-macros.h"
+#endif
+
+#endif // LLVM_LIBC_MACROS_SYS_INOTIFY_MACROS_H
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index ea710ef48857cf..816996332f1b65 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -315,6 +315,7 @@ add_header(regoff_t HDR regoff_t.h)
 add_header(regmatch_t HDR regmatch_t.h DEPENDS .regoff_t)
 add_header(struct_epoll_event HDR struct_epoll_event.h)
 add_header(struct_epoll_data HDR struct_epoll_data.h)
+add_header(struct_inotify_event HDR struct_inotify_event.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
 add_header(
   float128
   HDR
diff --git a/libc/include/llvm-libc-types/struct_inotify_event.h b/libc/include/llvm-libc-types/struct_inotify_event.h
new file mode 100644
index 00000000000000..08c505b7954b3c
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_inotify_event.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
+/// Definition of struct inotify_event.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_INOTIFY_EVENT_H
+#define LLVM_LIBC_TYPES_STRUCT_INOTIFY_EVENT_H
+
+#include "../llvm-libc-macros/stdint-macros.h"
+
+struct inotify_event {
+  int wd;
+  uint32_t mask;
+  uint32_t cookie;
+  uint32_t len;
+  char name[];
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_INOTIFY_EVENT_H
diff --git a/libc/include/sys/inotify.yaml b/libc/include/sys/inotify.yaml
new file mode 100644
index 00000000000000..d102f19a5efb33
--- /dev/null
+++ b/libc/include/sys/inotify.yaml
@@ -0,0 +1,82 @@
+header: sys/inotify.h
+standards:
+  - linux
+macros:
+  - macro_name: IN_ACCESS
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_MODIFY
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_ATTRIB
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_CLOSE_WRITE
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_CLOSE_NOWRITE
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_CLOSE
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_OPEN
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_MOVED_FROM
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_MOVED_TO
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_MOVE
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_CREATE
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_DELETE
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_DELETE_SELF
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_MOVE_SELF
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_UNMOUNT
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_Q_OVERFLOW
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_IGNORED
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_ONLYDIR
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_DONT_FOLLOW
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_EXCL_UNLINK
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_MASK_CREATE
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_MASK_ADD
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_ISDIR
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_ONESHOT
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_ALL_EVENTS
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_CLOEXEC
+    macro_header: sys-inotify-macros.h
+  - macro_name: IN_NONBLOCK
+    macro_header: sys-inotify-macros.h
+types:
+  - type_name: struct_inotify_event
+enums: []
+objects: []
+functions:
+  - name: inotify_init
+    return_type: int
+    arguments:
+      - type: void
+  - name: inotify_init1
+    return_type: int
+    arguments:
+      - type: int
+  - name: inotify_add_watch
+    return_type: int
+    arguments:
+      - type: int
+      - type: const char *
+      - type: uint32_t
+  - name: inotify_rm_watch
+    return_type: int
+    arguments:
+      - type: int
+      - type: int
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 1adad38b86e100..47ddb551680199 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1558,3 +1558,52 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  inotify_init
+  HDRS
+    inotify_init.h
+  DEPENDS
+    libc.include.sys_syscall
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  inotify_init1
+  HDRS
+    inotify_init1.h
+  DEPENDS
+    libc.include.sys_syscall
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  inotify_add_watch
+  HDRS
+    inotify_add_watch.h
+  DEPENDS
+    libc.hdr.stdint_proxy
+    libc.include.sys_syscall
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  inotify_rm_watch
+  HDRS
+    inotify_rm_watch.h
+  DEPENDS
+    libc.include.sys_syscall
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+)
+
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/inotify_add_watch.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/inotify_add_watch.h
new file mode 100644
index 00000000000000..dc0b65f1a17d1b
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/inotify_add_watch.h
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Syscall wrapper for inotify_add_watch.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_INOTIFY_ADD_WATCH_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_INOTIFY_ADD_WATCH_H
+
+#include "hdr/stdint_proxy.h"
+#include "src/__support/OSUtil/linux/syscall.h" // For syscall_checked
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/macros/config.h"
+#include <sys/syscall.h> // For syscall numbers
+
+namespace LIBC_NAMESPACE_DECL {
+namespace linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> inotify_add_watch(int fd, const char *pathname,
+                                           uint32_t mask) {
+  return syscall_checked<int>(SYS_inotify_add_watch, fd, pathname, mask);
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_INOTIFY_ADD_WATCH_H
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/inotify_init.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/inotify_init.h
new file mode 100644
index 00000000000000..ebb2c924862f65
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/inotify_init.h
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Syscall wrapper for inotify_init.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_INOTIFY_INIT_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_INOTIFY_INIT_H
+
+#include "src/__support/OSUtil/linux/syscall.h" // For syscall_checked
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/macros/config.h"
+#include <sys/syscall.h> // For syscall numbers
+
+namespace LIBC_NAMESPACE_DECL {
+namespace linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> inotify_init(void) {
+#ifdef SYS_inotify_init
+  return syscall_checked<int>(SYS_inotify_init);
+#elif defined(SYS_inotify_init1)
+  return syscall_checked<int>(SYS_inotify_init1, 0);
+#else
+#error                                                                         \
+    "inotify_init and inotify_init1 are unavailable. Unable to build inotify_init."
+#endif
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_INOTIFY_INIT_H
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/inotify_init1.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/inotify_init1.h
new file mode 100644
index 00000000000000..68a2dc5fb492d4
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/inotify_init1.h
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===------------------------------------------------...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/230314


More information about the libc-commits mailing list