[libc-commits] [libc] [libc] Add the get and set sys/xattr.h entrypoints. (PR #224729)

Alex Strelnikov via libc-commits libc-commits at lists.llvm.org
Thu Sep 24 07:48:54 PDT 2026


================
@@ -0,0 +1,128 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Unit tests for fgetxattr.
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/sys_stat_macros.h"
+#include "src/__support/CPP/scope.h"
+#include "src/__support/CPP/string_view.h"
+#include "src/__support/OSUtil/linux/syscall.h"
+#include "src/__support/libc_errno.h"
+#include "src/fcntl/creat.h"
+#include "src/sys/xattr/fgetxattr.h"
+#include "src/unistd/close.h"
+#include "src/unistd/unlink.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+#include <sys/syscall.h>
+
+namespace {
+
+using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
+using LlvmLibcFgetxattrTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+using LIBC_NAMESPACE::cpp::scope_exit;
+using LIBC_NAMESPACE::cpp::string_view;
+
+int recreate_test_file(const char *path) {
+  LIBC_NAMESPACE::unlink(path);
+  LIBC_NAMESPACE::libc_errno = 0;
+  return LIBC_NAMESPACE::creat(path, S_IRWXU);
+}
+
+TEST_F(LlvmLibcFgetxattrTest, WithUserExtendedAttribute) {
+  const LIBC_NAMESPACE::CString TEST_FILE_NAME =
+      libc_make_test_file_path("testdata/fgetxattr.txt");
+
+  int fd = recreate_test_file(TEST_FILE_NAME);
+  ASSERT_ERRNO_SUCCESS();
+  scope_exit cleanup([&] {
+    ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
+    ASSERT_THAT(LIBC_NAMESPACE::unlink(TEST_FILE_NAME), Succeeds(0));
+  });
+
+  string_view XATTR_NAME = "user.test_attr";
+  string_view XATTR_VALUE = "test_value";
+  ASSERT_EQ(0, LIBC_NAMESPACE::syscall_impl<int>(
----------------
strel-12 wrote:

Consolidated all of the tests into three tests, one for each of:
* getxattr, setxattr, listxattr
* lgetxattr, lsetxattr, llistxattr
* fgetxattr, fsetxattr, flistxattr

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


More information about the libc-commits mailing list