curl_stream Module

C interoperability module for streaming curl output via popen.

This module provides POSIX popen() bindings to stream curl output directly to memory, eliminating the need for temporary files.

Note

This module requires POSIX-compliant systems (Linux, macOS, Unix).

Warning

Not portable to Windows.



Variables

Type Visibility Attributes Name Initial
integer, private, parameter :: CHUNK_SIZE = 8192

Maximum chunk size for reading from pipe (8KB)


Interfaces

interface

  • private function c_popen(command, mode) bind(C, name="popen")

    Open a pipe to a command and return file pointer.

    @param command The command to execute @param mode Open mode ("r" for read, "w" for write) @return C pointer to FILE stream, or NULL on failure

    Arguments

    Type IntentOptional Attributes Name
    character(kind=c_char, len=1), intent(in), dimension(*) :: command
    character(kind=c_char, len=1), intent(in), dimension(*) :: mode

    Return Value type(c_ptr)

interface

  • private function c_pclose(stream) bind(C, name="pclose")

    Close a pipe opened with popen.

    @param stream The FILE pointer to close @return Exit status of command, or -1 on error

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in), value :: stream

    Return Value integer(kind=c_int)

interface

  • private function c_fread(ptr, size, nmemb, stream) bind(C, name="fread")

    Read data from a stream.

    @param ptr Pointer to buffer to read into @param size Size of each element @param nmemb Number of elements to read @param stream FILE pointer to read from @return Number of elements successfully read

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in), value :: ptr
    integer(kind=c_size_t), intent(in), value :: size
    integer(kind=c_size_t), intent(in), value :: nmemb
    type(c_ptr), intent(in), value :: stream

    Return Value integer(kind=c_size_t)


Functions

public function is_streaming_available() result(available)

Check if streaming is available on this platform.

Read more…

Arguments

None

Return Value logical

public function stream_command_output(command, output, exit_status) result(success)

Stream command output directly to memory.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: command
character(len=:), intent(out), allocatable :: output
integer, intent(out) :: exit_status

Return Value logical