You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Pierre Lindenbaum <pi...@univ-nantes.fr> on 2014/06/30 11:56:50 UTC

binding an external C library with I/O methods

(cross posted on SO: http://stackoverflow.com/questions/24486926)

I'd like to use an external library that is able to write files using a 
custom format. The API for this library looks like:

     MyFormatPtr format= myformat_openfd(int filedescriptor,const char* 
mode);
     MyFormatPtr format= myformat_open(const char* filename,const char* 
mode);
     (...)
     void myformat_close(MyFormatPtr format);

while the Apache API writes data using methods like `ap_rwrite`

How can I bind my library with Apache ? Something like:

     (...)
     ap_set_content_type(r,"data");
     int fd= ap_r_get_file_descriptor(r);/* <- this is what I need */
     MyFormatPtr format = myformat_openfd( fd , "w");
     (...)
     myformat_close(format);
     return OK;
     (...)

Thanks.

Re: binding an external C library with I/O methods

Posted by Nick Kew <ni...@apache.org>.
On Mon, 30 Jun 2014 11:56:50 +0200
Pierre Lindenbaum <pi...@univ-nantes.fr> wrote:

> (cross posted on SO: http://stackoverflow.com/questions/24486926)
> 
> I'd like to use an external library that is able to write files using a 
> custom format. The API for this library looks like:
> 
>      MyFormatPtr format= myformat_openfd(int filedescriptor,const char* 
> mode);
>      MyFormatPtr format= myformat_open(const char* filename,const char* 
> mode);
>      (...)
>      void myformat_close(MyFormatPtr format);

You probably want to look elsewhere in your API.  An apache request isn't
a file, and has no file descriptor.

If your library is designed to be usable in non-file applications,
it'll offer some mechanism for plugging in your own I/O functions.

If not, you could perhaps try some ugly hack: create some bucket of
file-compatible type for it to write to.


-- 
Nick Kew