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

docs/CURLOPT_WRITEFUNCTION: size is always 1 #2787

Closed
wants to merge 1 commit into from
Closed

docs/CURLOPT_WRITEFUNCTION: size is always 1 #2787

wants to merge 1 commit into from

Conversation

Hawk777
Copy link
Contributor

@Hawk777 Hawk777 commented Jul 25, 2018

For compatibility with fwrite, the CURLOPT_WRITEFUNCTION callback is
passed two size_t parameters which, when multiplied, designate the
number of bytes of data passed in. In practice, CURL always sets the
first parameter (size) to 1.

This practice is also enshrined in documentation and cannot be changed
in future. The documentation states that the default callback is
fwrite, which means fwrite must be a suitable function for this
purpose. However, the documentation also states that the callback must
return the number of bytes it successfully handled, whereas ISO C
fwrite returns the number of items (each of size size) which it
wrote. The only way these numbers can be equal is if size is 1.

Since size is 1 and can never be changed in future anyway, document
that fact explicitly and let users rely on it.

For compatibility with `fwrite`, the `CURLOPT_WRITEFUNCTION` callback is
passed two `size_t` parameters which, when multiplied, designate the
number of bytes of data passed in. In practice, CURL always sets the
first parameter (`size`) to 1.

This practice is also enshrined in documentation and cannot be changed
in future. The documentation states that the default callback is
`fwrite`, which means `fwrite` must be a suitable function for this
purpose. However, the documentation also states that the callback must
return the number of *bytes* it successfully handled, whereas ISO C
`fwrite` returns the number of items (each of size `size`) which it
wrote. The only way these numbers can be equal is if `size` is 1.

Since `size` is 1 and can never be changed in future anyway, document
that fact explicitly and let users rely on it.
Copy link
Member

@bagder bagder left a comment

Choose a reason for hiding this comment

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

It's also been like this always so there's no reason to believe we would ever want to change it...

@bagder
Copy link
Member

bagder commented Jul 26, 2018

Thanks!

@bagder bagder closed this in 9526cbe Jul 26, 2018
xquery pushed a commit to xquery/curl that referenced this pull request Aug 9, 2018
For compatibility with `fwrite`, the `CURLOPT_WRITEFUNCTION` callback is
passed two `size_t` parameters which, when multiplied, designate the
number of bytes of data passed in. In practice, CURL always sets the
first parameter (`size`) to 1.

This practice is also enshrined in documentation and cannot be changed
in future. The documentation states that the default callback is
`fwrite`, which means `fwrite` must be a suitable function for this
purpose. However, the documentation also states that the callback must
return the number of *bytes* it successfully handled, whereas ISO C
`fwrite` returns the number of items (each of size `size`) which it
wrote. The only way these numbers can be equal is if `size` is 1.

Since `size` is 1 and can never be changed in future anyway, document
that fact explicitly and let users rely on it.

Closes curl#2787
@Hawk777 Hawk777 deleted the write-function-param branch August 22, 2018 05:34
falconindy pushed a commit to falconindy/curl that referenced this pull request Sep 10, 2018
For compatibility with `fwrite`, the `CURLOPT_WRITEFUNCTION` callback is
passed two `size_t` parameters which, when multiplied, designate the
number of bytes of data passed in. In practice, CURL always sets the
first parameter (`size`) to 1.

This practice is also enshrined in documentation and cannot be changed
in future. The documentation states that the default callback is
`fwrite`, which means `fwrite` must be a suitable function for this
purpose. However, the documentation also states that the callback must
return the number of *bytes* it successfully handled, whereas ISO C
`fwrite` returns the number of items (each of size `size`) which it
wrote. The only way these numbers can be equal is if `size` is 1.

Since `size` is 1 and can never be changed in future anyway, document
that fact explicitly and let users rely on it.

Closes curl#2787
@lock lock bot locked as resolved and limited conversation to collaborators Nov 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

None yet

2 participants