1.\" $OpenBSD: BIO_s_fd.3,v 1.9 2018/05/01 17:05:05 schwarze Exp $ 2.\" OpenSSL 9b86974e Aug 17 15:21:33 2015 -0400 3.\" 4.\" This file was written by Dr. Stephen Henson <steve@openssl.org>. 5.\" Copyright (c) 2000 The OpenSSL Project. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in 16.\" the documentation and/or other materials provided with the 17.\" distribution. 18.\" 19.\" 3. All advertising materials mentioning features or use of this 20.\" software must display the following acknowledgment: 21.\" "This product includes software developed by the OpenSSL Project 22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 23.\" 24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 25.\" endorse or promote products derived from this software without 26.\" prior written permission. For written permission, please contact 27.\" openssl-core@openssl.org. 28.\" 29.\" 5. Products derived from this software may not be called "OpenSSL" 30.\" nor may "OpenSSL" appear in their names without prior written 31.\" permission of the OpenSSL Project. 32.\" 33.\" 6. Redistributions of any form whatsoever must retain the following 34.\" acknowledgment: 35.\" "This product includes software developed by the OpenSSL Project 36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 37.\" 38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 49.\" OF THE POSSIBILITY OF SUCH DAMAGE. 50.\" 51.Dd $Mdocdate: May 1 2018 $ 52.Dt BIO_S_FD 3 53.Os 54.Sh NAME 55.Nm BIO_s_fd , 56.Nm BIO_set_fd , 57.Nm BIO_get_fd , 58.Nm BIO_new_fd 59.Nd file descriptor BIO 60.Sh SYNOPSIS 61.In openssl/bio.h 62.Ft const BIO_METHOD * 63.Fo BIO_s_fd 64.Fa "void" 65.Fc 66.Ft long 67.Fo BIO_set_fd 68.Fa "BIO *b" 69.Fa "int fd" 70.Fa "long close_flag" 71.Fc 72.Ft long 73.Fo BIO_get_fd 74.Fa "BIO *b" 75.Fa "int *c" 76.Fc 77.Ft BIO * 78.Fo BIO_new_fd 79.Fa "int fd" 80.Fa "int close_flag" 81.Fc 82.Sh DESCRIPTION 83.Fn BIO_s_fd 84returns the file descriptor BIO method. 85This is a wrapper around the platform's file descriptor routines such as 86.Xr read 2 87and 88.Xr write 2 . 89.Pp 90.Xr BIO_read 3 91and 92.Xr BIO_write 3 93read or write the underlying descriptor. 94.Xr BIO_puts 3 95is supported but 96.Xr BIO_gets 3 97is not. 98.Pp 99If the close flag is set, 100.Xr close 2 101is called on the underlying file descriptor when the 102.Vt BIO 103is freed. 104.Pp 105.Xr BIO_reset 3 106attempts to set the file pointer to the start of the file using 107.Fn lseek fd 0 0 . 108.Pp 109.Xr BIO_seek 3 110sets the file pointer to position 111.Fa ofs 112from start of file using 113.Fn lseek fd ofs 0 . 114.Pp 115.Xr BIO_tell 3 116returns the current file position by calling 117.Fn lseek fd 0 1 . 118.Pp 119.Fn BIO_set_fd 120sets the file descriptor of 121.Vt BIO 122.Fa b 123to 124.Fa fd 125and the close flag to 126.Fa close_flag . 127It is currently implemented as a macro. 128.Pp 129.Fn BIO_get_fd 130places the file descriptor in 131.Fa c 132if it is not 133.Dv NULL 134and also returns the file descriptor. 135It is currently implemented as a macro. 136.Pp 137.Fn BIO_new_fd 138returns a file descriptor BIO using 139.Fa fd 140and 141.Fa close_flag . 142.Pp 143The behaviour of 144.Xr BIO_read 3 145and 146.Xr BIO_write 3 147depends on the behavior of the platform's 148.Xr read 2 149and 150.Xr write 2 151calls on the descriptor. 152If the underlying file descriptor is in a non-blocking mode, 153then the BIO will behave in the manner described in the 154.Xr BIO_read 3 155and 156.Xr BIO_should_retry 3 157manual pages. 158.Pp 159File descriptor BIOs should not be used for socket I/O. 160Use socket BIOs instead. 161.Pp 162.Fn BIO_set_fd 163and 164.Fn BIO_get_fd 165are implemented as macros. 166.Sh RETURN VALUES 167.Fn BIO_s_fd 168returns the file descriptor BIO method. 169.Pp 170.Fn BIO_set_fd 171always returns 1. 172.Pp 173.Fn BIO_get_fd 174returns the file descriptor or -1 if the 175.Vt BIO 176has not been initialized. 177.Pp 178.Fn BIO_new_fd 179returns the newly allocated 180.Vt BIO 181or 182.Dv NULL 183if an error occurred. 184.Sh EXAMPLES 185This is a file descriptor BIO version of "Hello World": 186.Bd -literal -offset indent 187BIO *out; 188out = BIO_new_fd(fileno(stdout), BIO_NOCLOSE); 189BIO_printf(out, "Hello World\en"); 190BIO_free(out); 191.Ed 192.Sh SEE ALSO 193.Xr BIO_new 3 , 194.Xr BIO_read 3 , 195.Xr BIO_s_socket 3 , 196.Xr BIO_seek 3 197.Sh HISTORY 198.Fn BIO_s_fd , 199.Fn BIO_set_fd , 200and 201.Fn BIO_get_fd 202first appeared in SSLeay 0.6.0. 203.Fn BIO_new_fd 204first appeared in SSLeay 0.8.0. 205All these functions have been available since 206.Ox 2.4 . 207