[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
Tue Sep 22 07:18:47 PDT 2026
================
@@ -0,0 +1,158 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 getxattr.
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/sys_stat_macros.h"
+#include "src/__support/CPP/scope.h"
+#include "src/__support/OSUtil/linux/syscall.h"
+#include "src/__support/libc_errno.h"
+#include "src/fcntl/creat.h"
+#include "src/sys/xattr/getxattr.h"
+#include "src/unistd/close.h"
+#include "src/unistd/symlink.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 LlvmLibcGetxattrTest = 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);
+}
+
+int recreate_test_symlink(const char *target, const char *linkpath) {
+ LIBC_NAMESPACE::unlink(linkpath);
+ LIBC_NAMESPACE::libc_errno = 0;
+ return LIBC_NAMESPACE::symlink(target, linkpath);
+}
+
+TEST_F(LlvmLibcGetxattrTest, WithUserExtendedAttribute) {
+ const LIBC_NAMESPACE::CString TEST_FILE_NAME =
+ libc_make_test_file_path("testdata/getxattr.txt");
+ constexpr const char *TEST_SYMLINK_TARGET = "getxattr.txt";
+ const LIBC_NAMESPACE::CString TEST_SYMLINK_NAME =
+ libc_make_test_file_path("testdata/getxattr_symlink.txt");
+
+ int fd = recreate_test_file(TEST_FILE_NAME);
+ ASSERT_ERRNO_SUCCESS();
+ ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
+
+ ASSERT_THAT(recreate_test_symlink(TEST_SYMLINK_TARGET, TEST_SYMLINK_NAME),
+ Succeeds(0));
+ scope_exit cleanup([&] {
----------------
strel-12 wrote:
Done
https://github.com/llvm/llvm-project/pull/224729
More information about the libc-commits
mailing list