apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmpil...@collab.net
Subject Re: fd from apr_file_t
Date Thu, 14 Aug 2003 17:24:47 GMT
Cliff Woolley <jwoolley@virginia.edu> writes:

> On Thu, 14 Aug 2003, Bojan Smojver wrote:
> 
> > I'm not sure if this list is the correct place to ask this question,
> > given it's the APR development list, but I'll take my chances...
> 
> Definitely the right place.  :)
> 
> > I'm trying to figure out how to get a file descriptor (integer or FILE*)
> > out of the apr_file_t. Is there a function to do that?
> 
> Sure... take a look at apr_os_file_get() which is declared in
> apr_portable.h

This answer is, I'm surmising, unfortunately incomplete.  That is, on
Unix systems, apr_os_file_get() will do the trick, but the OS file
descriptor mechanism on Windows platforms is a HANDLE (as you can also
see in apr_portable.h), so there's a little more work to be done there.

The Subversion project has code in its Python bindings that deals with
the same discrepancy.  Our goal is slightly different -- we're trying to
build an apr_file_t from a FILE * input.  The code runs like so (and
admittedly could be a little better at checking errors, but...):

   /* FD is the input FILE * file descriptor */
   apr_os_file_t osfile;
   apr_file_t *apr_file = NULL;
   #ifdef WIN32
      osfile = (apr_os_file_t)_get_osfhandle(_fileno(fd));
   #else
      osfile = (apr_os_file_t)fileno(fd);
   #endif
   status = apr_os_file_put (&apr_file, &osfile, O_CREAT | O_WRONLY, pool);
   if (status)
      return NULL;

While I've not written code to do exactly what your are doing (going
from OS file to FILE *), I can't believe that apr_os_file_get() would
behave any differently in this respect than apr_os_file_put().

Mime
View raw message