blob: 9365eaf973ee29c85088dd4aaf30744c72c3ac89 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
.\" $OpenBSD: BIO_s_fd.3,v 1.4 2016/11/07 15:52:47 jmc Exp $
.\"
.Dd $Mdocdate: November 7 2016 $
.Dt BIO_S_FD 3
.Os
.Sh NAME
.Nm BIO_s_fd ,
.Nm BIO_set_fd ,
.Nm BIO_get_fd ,
.Nm BIO_new_fd
.Nd file descriptor BIO
.Sh SYNOPSIS
.In openssl/bio.h
.Ft BIO_METHOD *
.Fo BIO_s_fd
.Fa "void"
.Fc
.Ft long
.Fo BIO_set_fd
.Fa "BIO *b"
.Fa "int fd"
.Fa "long close_flag"
.Fc
.Ft long
.Fo BIO_get_fd
.Fa "BIO *b"
.Fa "int *c"
.Fc
.Ft BIO *
.Fo BIO_new_fd
.Fa "int fd"
.Fa "int close_flag"
.Fc
.Sh DESCRIPTION
.Fn BIO_s_fd
returns the file descriptor BIO method.
This is a wrapper around the platform's file descriptor routines such as
.Xr read 2
and
.Xr write 2 .
.Pp
.Xr BIO_read 3
and
.Xr BIO_write 3
read or write the underlying descriptor.
.Xr BIO_puts 3
is supported but
.Xr BIO_gets 3
is not.
.Pp
If the close flag is set,
.Xr close 2
is called on the underlying file descriptor when the
.Vt BIO
is freed.
.Pp
.Xr BIO_reset 3
attempts to set the file pointer to the start of the file using
.Fn lseek fd 0 0 .
.Pp
.Xr BIO_seek 3
sets the file pointer to position
.Fa ofs
from start of file using
.Fn lseek fd ofs 0 .
.Pp
.Xr BIO_tell 3
returns the current file position by calling
.Fn lseek fd 0 1 .
.Pp
.Fn BIO_set_fd
sets the file descriptor of
.Vt BIO
.Fa b
to
.Fa fd
and the close flag to
.Fa close_flag .
It is currently implemented as a macro.
.Pp
.Fn BIO_get_fd
places the file descriptor in
.Fa c
if it is not
.Dv NULL
and also returns the file descriptor.
It is currently implemented as a macro.
.Pp
.Fn BIO_new_fd
returns a file descriptor BIO using
.Fa fd
and
.Fa close_flag .
.Pp
The behaviour of
.Xr BIO_read 3
and
.Xr BIO_write 3
depends on the behavior of the platform's
.Xr read 2
and
.Xr write 2
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
.Xr BIO_read 3
and
.Xr BIO_should_retry 3
manual pages.
.Pp
File descriptor BIOs should not be used for socket I/O.
Use socket BIOs instead.
.Sh RETURN VALUES
.Fn BIO_s_fd
returns the file descriptor BIO method.
.Pp
.Xr BIO_reset 3
returns zero for success and -1 if an error occurred.
.Xr BIO_seek 3
and
.Xr BIO_tell 3
return the current file position or -1 if an error occurred.
These values reflect the underlying
.Xr lseek 2
behaviour.
.Pp
.Fn BIO_set_fd
always returns 1.
.Pp
.Fn BIO_get_fd
returns the file descriptor or -1 if the
.Vt BIO
has not been initialized.
.Pp
.Fn BIO_new_fd
returns the newly allocated
.Vt BIO
or
.Dv NULL
if an error occurred.
.Sh EXAMPLES
This is a file descriptor BIO version of "Hello World":
.Bd -literal -offset indent
BIO *out;
out = BIO_new_fd(fileno(stdout), BIO_NOCLOSE);
BIO_printf(out, "Hello World\en");
BIO_free(out);
.Ed
.Sh SEE ALSO
.Xr BIO_read 3 ,
.Xr BIO_s_socket 3 ,
.Xr BIO_seek 3
|