curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: Curl handle as a FILE *

From: Patrick Monnerat via curl-library <curl-library_at_lists.haxx.se>
Date: Tue, 6 Dec 2022 15:24:07 +0100

On 12/6/22 13:08, Daniel Stenberg wrote:
> On Tue, 6 Dec 2022, Patrick Monnerat via curl-library wrote:
>
>> Please find the source code and use examples of functions
>> curl_fopen() and curl_fdopen() in attachement.
>>
>> These allow associating an URL or a curl handle with a standard C
>> FILE pointer and use the standard C IO API on it.
>
> Fun!
>
> Also a quick reminder to readers that if you want an fopen/fread/frite
> style API for libcurl, there is also this start =>
> https://github.com/curl/fcurl


Thanks for your feedback. And the reminder was a good idea.

Although the goal is the same, I targetted something really compatible
with C FILE. This allows to easily insert libcurl use in existing
programs as old as C iitself and use on a handle a much wider range of
API without having to write wrappers. The real challenge was "FILE *" !

I know fcurl is not complete yet, but noted the method is a bit
different: curl_fopen plays with the pause flags and unpause only when
enough buffer is available (that is: when in read or write). I did it
this way because I support writes too and to prevent buffer overflows.


If you try my code on an Apache+PHP-FPM web service, you might
experience problems while posting: there currently is an Apache bug on
handling chunked post input. It works perfectly with nginx.

Patrick

-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2022-12-06