feat: Implement Lchown function for changing file ownership (#5161)

* feat: Implement Lchown function for changing file ownership

- Added Lchown function to change the numeric uid and gid of a file or symbolic link.
- Included error handling to return *PathError for failed operations.
- Added unit tests for Lchown to verify behavior on different error scenarios.

* fix: fix chmod tests
This commit is contained in:
Itxaka
2026-01-10 09:31:22 +01:00
committed by GitHub
parent 743bf45e00
commit ca36fba7e4
3 changed files with 63 additions and 0 deletions
+14
View File
@@ -172,6 +172,15 @@ func Chown(path string, uid, gid int) (err error) {
return
}
func Lchown(path string, uid, gid int) (err error) {
data := cstring(path)
fail := int(libc_lchown(&data[0], uid, gid))
if fail < 0 {
err = getErrno()
}
return
}
func Fork() (err error) {
fail := int(libc_fork())
if fail < 0 {
@@ -368,6 +377,11 @@ func libc_chmod(pathname *byte, mode uint32) int32
//export chown
func libc_chown(pathname *byte, owner, group int) int32
// int lchown(const char *pathname, uid_t owner, gid_t group);
//
//export lchown
func libc_lchown(pathname *byte, owner, group int) int32
// int mkdir(const char *pathname, mode_t mode);
//
//export mkdir