[libc-commits] [libc] [libc] add ioctl (PR #141393)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Wed Jun 4 14:06:09 PDT 2025
================
@@ -0,0 +1,73 @@
+//===-- Unittests for ioctl -----------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/errno/libc_errno.h"
+#include "src/fcntl/open.h"
+#include "src/sys/ioctl/ioctl.h"
+#include "src/unistd/close.h"
+#include "src/unistd/read.h"
+#include "src/unistd/write.h"
+
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+#include "hdr/sys_ioctl_macros.h"
+
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
+
+TEST(LlvmLibcSysIoctlTest, InvalidCommandAndFIONREAD) {
+ LIBC_NAMESPACE::libc_errno = 0;
+
+ // Setup the test file
+ constexpr const char *TEST_FILE_NAME = "testdata/ioctl.test";
+ constexpr const char TEST_MSG[] = "ioctl test";
+ constexpr int TEST_MSG_SIZE = sizeof(TEST_MSG) - 1;
+ auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
+ int new_test_file_fd =
+ LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_WRONLY, 0644);
----------------
michaelrj-google wrote:
The `0644` can be replaced by `S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH` to make it more clear that's the file permissions being set.
https://github.com/llvm/llvm-project/pull/141393
More information about the libc-commits
mailing list