
#use wml::openssl-macros area=docs page=BIO_s_fd

<title>Documents, BIO_s_fd(3)</title>

<h1>BIO_s_fd(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#NOTES">NOTES</A>
	<LI><A HREF="#RETURN_VALUES">RETURN VALUES</A>
	<LI><A HREF="#EXAMPLE">EXAMPLE</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
BIO_s_fd, BIO_set_fd, BIO_get_fd, BIO_new_fd - file descriptor BIO

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/bio.h&gt;
</PRE>
<PRE> BIO_METHOD *   BIO_s_fd(void);
</PRE>
<PRE> #define BIO_set_fd(b,fd,c)     BIO_int_ctrl(b,BIO_C_SET_FD,c,fd)
 \#define BIO_get_fd(b,c)        BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c)
</PRE>
<PRE> BIO *BIO_new_fd(int fd, int close_flag);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>BIO_s_fd()</CODE> returns the file descriptor BIO method. This is a
wrapper round the platforms file descriptor routines such as
<CODE>read()</CODE> and <CODE>write().</CODE>

</P>
<P>
<CODE>BIO_read()</CODE> and <CODE>BIO_write()</CODE> read or write the
underlying descriptor. <CODE>BIO_puts()</CODE> is supported but
<CODE>BIO_gets()</CODE> is not.

</P>
<P>
If the close flag is set then then <CODE>close()</CODE> is called on the
underlying file descriptor when the BIO is freed.

</P>
<P>
<CODE>BIO_reset()</CODE> attempts to change the file pointer to the start
of file using <CODE>lseek(fd,</CODE> 0, 0).

</P>
<P>
<CODE>BIO_seek()</CODE> sets the file pointer to position <STRONG>ofs</STRONG> from start of file using <CODE>lseek(fd,</CODE> ofs, 0).

</P>
<P>
<CODE>BIO_tell()</CODE> returns the current file position by calling
<CODE>lseek(fd,</CODE> 0, 1).

</P>
<P>
<CODE>BIO_set_fd()</CODE> sets the file descriptor of BIO <STRONG>b</STRONG> to <STRONG>fd</STRONG> and the close flag to <STRONG>c</STRONG>.

</P>
<P>
<CODE>BIO_get_fd()</CODE> places the file descriptor in <STRONG>c</STRONG> if it is not NULL, it also returns the file descriptor. If <STRONG>c</STRONG> is not NULL it should be of type (int *).

</P>
<P>
<CODE>BIO_new_fd()</CODE> returns a file descriptor BIO using <STRONG>fd</STRONG> and <STRONG>close_flag</STRONG>.

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
The behaviour of <CODE>BIO_read()</CODE> and <CODE>BIO_write()</CODE>
depends on the behavior of the platforms <CODE>read()</CODE> and
<CODE>write()</CODE> calls on the descriptor. If the underlying file
descriptor is in a non blocking mode then the BIO will behave in the manner
described in the <A HREF="../crypto/BIO_read.html#">BIO_read(3)</A> and <A HREF="../crypto/BIO_should_retry.html#">BIO_should_retry(3)</A>
manual pages.

</P>
<P>
File descriptor BIOs should not be used for socket I/O. Use socket BIOs
instead.

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>BIO_s_fd()</CODE> returns the file descriptor BIO method.

</P>
<P>
<CODE>BIO_reset()</CODE> returns zero for success and -1 if an error
occurred. <CODE>BIO_seek()</CODE> and <CODE>BIO_tell()</CODE> return the
current file position or -1 is an error occurred. These values reflect the
underlying <CODE>lseek()</CODE> behaviour.

</P>
<P>
<CODE>BIO_set_fd()</CODE> always returns 1.

</P>
<P>
<CODE>BIO_get_fd()</CODE> returns the file descriptor or -1 if the BIO has
not been initialized.

</P>
<P>
<CODE>BIO_new_fd()</CODE> returns the newly allocated BIO or NULL is an
error occurred.

</P>
<P>
<HR>
<H1><A NAME="EXAMPLE">EXAMPLE</A></H1>
<P>
This is a file descriptor BIO version of ``Hello World'':

</P>
<PRE> BIO *out;
 out = BIO_new_fd(fileno(stdout), BIO_NOCLOSE);
 BIO_printf(out, &quot;Hello World\n&quot;);
 BIO_free(out);
</PRE>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../crypto/BIO_ctrl.html#">BIO_seek(3)</A>, <A HREF="../crypto/BIO_ctrl.html#">BIO_tell(3)</A>,
<A HREF="../crypto/BIO_ctrl.html#">BIO_reset(3)</A>, <A HREF="../crypto/BIO_read.html#">BIO_read(3)</A>,
<A HREF="../crypto/BIO_read.html#">BIO_write(3)</A>, <A HREF="../crypto/BIO_read.html#">BIO_puts(3)</A>,
<A HREF="../crypto/BIO_read.html#">BIO_gets(3)</A>, <EM>BIO_printf(3)</EM>,
<A HREF="../crypto/BIO_ctrl.html#">BIO_set_close(3)</A>, <A HREF="../crypto/BIO_ctrl.html#">BIO_get_close(3)</A>

</P>
:}

