Skip to content
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

runtime/fcntl #4603

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

runtime/fcntl #4603

wants to merge 1 commit into from

Conversation

leongross
Copy link
Contributor

Rework of #4481

src/runtime/os_linux.go Outdated Show resolved Hide resolved
src/runtime/os_linux.go Outdated Show resolved Hide resolved
Signed-off-by: leongross <[email protected]>
@leongross leongross marked this pull request as ready for review November 15, 2024 13:06
Comment on lines +156 to +160
ret = int32(libc_fcntl(int(fd), int(cmd), int(arg)))
if ret < 0 {
return 0, int32(*libc_errno_location())
}
return ret, 0
Copy link
Member

@aykevl aykevl Nov 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not quite correct. If you look at where runtime.fcntl is used, the code looks like this:

func Fcntl(fd int, cmd int, arg int) (int, error) {
        val, errno := fcntl(int32(fd), int32(cmd), int32(arg))
        if val == -1 {
                return int(val), syscall.Errno(errno)
        }
        return int(val), nil
}

So val needs to be -1 when there's an error.
This probably means you can simplify the code like this:

Suggested change
ret = int32(libc_fcntl(int(fd), int(cmd), int(arg)))
if ret < 0 {
return 0, int32(*libc_errno_location())
}
return ret, 0
ret = int32(libc_fcntl(int(fd), int(cmd), int(arg)))
errno = *libc_errno_location()
return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants