BIO_s_file.3ossl 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "BIO_S_FILE 3ossl"
  58. .TH BIO_S_FILE 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. BIO_s_file, BIO_new_file, BIO_new_fp, BIO_set_fp, BIO_get_fp,
  65. BIO_read_filename, BIO_write_filename, BIO_append_filename,
  66. BIO_rw_filename \- FILE bio
  67. .SH SYNOPSIS
  68. .IX Header "SYNOPSIS"
  69. .Vb 1
  70. \& #include <openssl/bio.h>
  71. \&
  72. \& const BIO_METHOD *BIO_s_file(void);
  73. \& BIO *BIO_new_file(const char *filename, const char *mode);
  74. \& BIO *BIO_new_fp(FILE *stream, int flags);
  75. \&
  76. \& BIO_set_fp(BIO *b, FILE *fp, int flags);
  77. \& BIO_get_fp(BIO *b, FILE **fpp);
  78. \&
  79. \& int BIO_read_filename(BIO *b, char *name);
  80. \& int BIO_write_filename(BIO *b, char *name);
  81. \& int BIO_append_filename(BIO *b, char *name);
  82. \& int BIO_rw_filename(BIO *b, char *name);
  83. .Ve
  84. .SH DESCRIPTION
  85. .IX Header "DESCRIPTION"
  86. \&\fBBIO_s_file()\fR returns the BIO file method. As its name implies it
  87. is a wrapper round the stdio FILE structure and it is a
  88. source/sink BIO.
  89. .PP
  90. Calls to \fBBIO_read_ex()\fR and \fBBIO_write_ex()\fR read and write data to the
  91. underlying stream. \fBBIO_gets()\fR and \fBBIO_puts()\fR are supported on file BIOs.
  92. .PP
  93. \&\fBBIO_flush()\fR on a file BIO calls the \fBfflush()\fR function on the wrapped
  94. stream.
  95. .PP
  96. \&\fBBIO_reset()\fR attempts to change the file pointer to the start of file
  97. using fseek(stream, 0, 0).
  98. .PP
  99. \&\fBBIO_seek()\fR sets the file pointer to position \fBofs\fR from start of file
  100. using fseek(stream, ofs, 0).
  101. .PP
  102. \&\fBBIO_eof()\fR calls \fBfeof()\fR.
  103. .PP
  104. Setting the BIO_CLOSE flag calls \fBfclose()\fR on the stream when the BIO
  105. is freed.
  106. .PP
  107. \&\fBBIO_new_file()\fR creates a new file BIO with mode \fBmode\fR the meaning
  108. of \fBmode\fR is the same as the stdio function \fBfopen()\fR. The BIO_CLOSE
  109. flag is set on the returned BIO.
  110. .PP
  111. \&\fBBIO_new_fp()\fR creates a file BIO wrapping \fBstream\fR. Flags can be:
  112. BIO_CLOSE, BIO_NOCLOSE (the close flag) BIO_FP_TEXT (sets the underlying
  113. stream to text mode, default is binary: this only has any effect under
  114. Win32).
  115. .PP
  116. \&\fBBIO_set_fp()\fR sets the fp of a file BIO to \fBfp\fR. \fBflags\fR has the same
  117. meaning as in \fBBIO_new_fp()\fR, it is a macro.
  118. .PP
  119. \&\fBBIO_get_fp()\fR retrieves the fp of a file BIO, it is a macro.
  120. .PP
  121. \&\fBBIO_seek()\fR is a macro that sets the position pointer to \fBoffset\fR bytes
  122. from the start of file.
  123. .PP
  124. \&\fBBIO_tell()\fR returns the value of the position pointer.
  125. .PP
  126. \&\fBBIO_read_filename()\fR, \fBBIO_write_filename()\fR, \fBBIO_append_filename()\fR and
  127. \&\fBBIO_rw_filename()\fR set the file BIO \fBb\fR to use file \fBname\fR for
  128. reading, writing, append or read write respectively.
  129. .SH NOTES
  130. .IX Header "NOTES"
  131. When wrapping stdout, stdin or stderr the underlying stream should not
  132. normally be closed so the BIO_NOCLOSE flag should be set.
  133. .PP
  134. Because the file BIO calls the underlying stdio functions any quirks
  135. in stdio behaviour will be mirrored by the corresponding BIO.
  136. .PP
  137. On Windows BIO_new_files reserves for the filename argument to be
  138. UTF\-8 encoded. In other words if you have to make it work in multi\-
  139. lingual environment, encode filenames in UTF\-8.
  140. .SH "RETURN VALUES"
  141. .IX Header "RETURN VALUES"
  142. \&\fBBIO_s_file()\fR returns the file BIO method.
  143. .PP
  144. \&\fBBIO_new_file()\fR and \fBBIO_new_fp()\fR return a file BIO or NULL if an error
  145. occurred.
  146. .PP
  147. \&\fBBIO_set_fp()\fR and \fBBIO_get_fp()\fR return 1 for success or <=0 for failure
  148. (although the current implementation never return 0).
  149. .PP
  150. \&\fBBIO_seek()\fR returns 0 for success or negative values for failure.
  151. .PP
  152. \&\fBBIO_tell()\fR returns the current file position or negative values for failure.
  153. .PP
  154. \&\fBBIO_read_filename()\fR, \fBBIO_write_filename()\fR, \fBBIO_append_filename()\fR and
  155. \&\fBBIO_rw_filename()\fR return 1 for success or <=0 for failure.
  156. .SH EXAMPLES
  157. .IX Header "EXAMPLES"
  158. File BIO "hello world":
  159. .PP
  160. .Vb 1
  161. \& BIO *bio_out;
  162. \&
  163. \& bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
  164. \& BIO_printf(bio_out, "Hello World\en");
  165. .Ve
  166. .PP
  167. Alternative technique:
  168. .PP
  169. .Vb 1
  170. \& BIO *bio_out;
  171. \&
  172. \& bio_out = BIO_new(BIO_s_file());
  173. \& if (bio_out == NULL)
  174. \& /* Error */
  175. \& if (BIO_set_fp(bio_out, stdout, BIO_NOCLOSE) <= 0)
  176. \& /* Error */
  177. \& BIO_printf(bio_out, "Hello World\en");
  178. .Ve
  179. .PP
  180. Write to a file:
  181. .PP
  182. .Vb 1
  183. \& BIO *out;
  184. \&
  185. \& out = BIO_new_file("filename.txt", "w");
  186. \& if (!out)
  187. \& /* Error */
  188. \& BIO_printf(out, "Hello World\en");
  189. \& BIO_free(out);
  190. .Ve
  191. .PP
  192. Alternative technique:
  193. .PP
  194. .Vb 1
  195. \& BIO *out;
  196. \&
  197. \& out = BIO_new(BIO_s_file());
  198. \& if (out == NULL)
  199. \& /* Error */
  200. \& if (BIO_write_filename(out, "filename.txt") <= 0)
  201. \& /* Error */
  202. \& BIO_printf(out, "Hello World\en");
  203. \& BIO_free(out);
  204. .Ve
  205. .SH BUGS
  206. .IX Header "BUGS"
  207. \&\fBBIO_reset()\fR and \fBBIO_seek()\fR are implemented using \fBfseek()\fR on the underlying
  208. stream. The return value for \fBfseek()\fR is 0 for success or \-1 if an error
  209. occurred this differs from other types of BIO which will typically return
  210. 1 for success and a non positive value if an error occurred.
  211. .SH "SEE ALSO"
  212. .IX Header "SEE ALSO"
  213. \&\fBBIO_seek\fR\|(3), \fBBIO_tell\fR\|(3),
  214. \&\fBBIO_reset\fR\|(3), \fBBIO_flush\fR\|(3),
  215. \&\fBBIO_read_ex\fR\|(3),
  216. \&\fBBIO_write_ex\fR\|(3), \fBBIO_puts\fR\|(3),
  217. \&\fBBIO_gets\fR\|(3), \fBBIO_printf\fR\|(3),
  218. \&\fBBIO_set_close\fR\|(3), \fBBIO_get_close\fR\|(3)
  219. .SH COPYRIGHT
  220. .IX Header "COPYRIGHT"
  221. Copyright 2000\-2020 The OpenSSL Project Authors. All Rights Reserved.
  222. .PP
  223. Licensed under the Apache License 2.0 (the "License"). You may not use
  224. this file except in compliance with the License. You can obtain a copy
  225. in the file LICENSE in the source distribution or at
  226. <https://www.openssl.org/source/license.html>.