-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libc] Implement fchown #167286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[libc] Implement fchown #167286
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9f7ee38
[libc] fchown initial impl
nigham 74e5658
clang-format
nigham e9af916
clang-format on test_fchown.cpp
nigham 2b614b4
Fix fchown failure test
nigham fd262a7
Update error code in fchown failure test
nigham 3476780
add fchown to aarch64 entrypoints
nigham 63492b1
Addressed review comments
nigham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //===-- Implementation header for fchown ------------------------*- C++ -*-===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_LIBC_SRC_UNISTD_FCHOWN_H | ||
| #define LLVM_LIBC_SRC_UNISTD_FCHOWN_H | ||
|
|
||
| #include "hdr/types/gid_t.h" | ||
| #include "hdr/types/uid_t.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| int fchown(int fildes, uid_t owner, gid_t group); | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| #endif // LLVM_LIBC_SRC_UNISTD_FCHOWN_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| //===-- Linux implementation of fchown ------------------------------------===// | ||
| // | ||
| // 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/unistd/fchown.h" | ||
|
|
||
| #include "src/__support/OSUtil/syscall.h" // For internal syscall function. | ||
| #include "src/__support/common.h" | ||
|
|
||
| #include "hdr/types/gid_t.h" | ||
| #include "hdr/types/uid_t.h" | ||
| #include "src/__support/libc_errno.h" | ||
| #include "src/__support/macros/config.h" | ||
| #include <sys/syscall.h> // For syscall numbers. | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, fchown, (int fildes, uid_t owner, gid_t group)) { | ||
| int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_fchown, fildes, owner, group); | ||
| if (ret < 0) { | ||
| libc_errno = -ret; | ||
| return -1; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| //===-- Unittests for fchown ----------------------------------------------===// | ||
| // | ||
| // 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/fcntl/open.h" | ||
| #include "src/unistd/close.h" | ||
| #include "src/unistd/fchown.h" | ||
| #include "src/unistd/getgid.h" | ||
| #include "src/unistd/getuid.h" | ||
| #include "src/unistd/unlink.h" | ||
|
|
||
| #include "test/UnitTest/ErrnoCheckingTest.h" | ||
| #include "test/UnitTest/ErrnoSetterMatcher.h" | ||
| #include "test/UnitTest/Test.h" | ||
|
|
||
| #include "hdr/fcntl_macros.h" | ||
| #include <sys/stat.h> | ||
|
|
||
| using LlvmLibcFchownTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest; | ||
|
|
||
| TEST_F(LlvmLibcFchownTest, FchownSuccess) { | ||
| using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; | ||
| uid_t my_uid = LIBC_NAMESPACE::getuid(); | ||
| gid_t my_gid = LIBC_NAMESPACE::getgid(); | ||
| constexpr const char *FILENAME = "fchown.test"; | ||
| auto TEST_FILE = libc_make_test_file_path(FILENAME); | ||
|
|
||
| // Create a test file. | ||
| int write_fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU); | ||
| ASSERT_ERRNO_SUCCESS(); | ||
| ASSERT_GT(write_fd, 0); | ||
|
|
||
| // Change the ownership of the file. | ||
| ASSERT_THAT(LIBC_NAMESPACE::fchown(write_fd, my_uid, my_gid), Succeeds(0)); | ||
|
|
||
| // Close the file descriptor. | ||
| ASSERT_THAT(LIBC_NAMESPACE::close(write_fd), Succeeds(0)); | ||
|
|
||
| // Clean up the test file. | ||
| ASSERT_THAT(LIBC_NAMESPACE::unlink(TEST_FILE), Succeeds(0)); | ||
| } | ||
|
|
||
| TEST_F(LlvmLibcFchownTest, FchownInvalidFileDescriptor) { | ||
| using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; | ||
| ASSERT_THAT(LIBC_NAMESPACE::fchown(-1, 1000, 1000), Fails(EBADF)); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add includes for the proxy headers here, ideally we'd include everything we use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks!