xref: /openbsd-src/lib/libcrypto/bio/b_posix.c (revision acf644016ec1190723fc541ba590471e90a9ef53)
1*acf64401Sbeck /* $OpenBSD: b_posix.c,v 1.3 2023/07/05 21:23:37 beck Exp $ */
2f1b4d7a8Sbcook /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3f1b4d7a8Sbcook  * All rights reserved.
4f1b4d7a8Sbcook  *
5f1b4d7a8Sbcook  * This package is an SSL implementation written
6f1b4d7a8Sbcook  * by Eric Young (eay@cryptsoft.com).
7f1b4d7a8Sbcook  * The implementation was written so as to conform with Netscapes SSL.
8f1b4d7a8Sbcook  *
9f1b4d7a8Sbcook  * This library is free for commercial and non-commercial use as long as
10f1b4d7a8Sbcook  * the following conditions are aheared to.  The following conditions
11f1b4d7a8Sbcook  * apply to all code found in this distribution, be it the RC4, RSA,
12f1b4d7a8Sbcook  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13f1b4d7a8Sbcook  * included with this distribution is covered by the same copyright terms
14f1b4d7a8Sbcook  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15f1b4d7a8Sbcook  *
16f1b4d7a8Sbcook  * Copyright remains Eric Young's, and as such any Copyright notices in
17f1b4d7a8Sbcook  * the code are not to be removed.
18f1b4d7a8Sbcook  * If this package is used in a product, Eric Young should be given attribution
19f1b4d7a8Sbcook  * as the author of the parts of the library used.
20f1b4d7a8Sbcook  * This can be in the form of a textual message at program startup or
21f1b4d7a8Sbcook  * in documentation (online or textual) provided with the package.
22f1b4d7a8Sbcook  *
23f1b4d7a8Sbcook  * Redistribution and use in source and binary forms, with or without
24f1b4d7a8Sbcook  * modification, are permitted provided that the following conditions
25f1b4d7a8Sbcook  * are met:
26f1b4d7a8Sbcook  * 1. Redistributions of source code must retain the copyright
27f1b4d7a8Sbcook  *    notice, this list of conditions and the following disclaimer.
28f1b4d7a8Sbcook  * 2. Redistributions in binary form must reproduce the above copyright
29f1b4d7a8Sbcook  *    notice, this list of conditions and the following disclaimer in the
30f1b4d7a8Sbcook  *    documentation and/or other materials provided with the distribution.
31f1b4d7a8Sbcook  * 3. All advertising materials mentioning features or use of this software
32f1b4d7a8Sbcook  *    must display the following acknowledgement:
33f1b4d7a8Sbcook  *    "This product includes cryptographic software written by
34f1b4d7a8Sbcook  *     Eric Young (eay@cryptsoft.com)"
35f1b4d7a8Sbcook  *    The word 'cryptographic' can be left out if the rouines from the library
36f1b4d7a8Sbcook  *    being used are not cryptographic related :-).
37f1b4d7a8Sbcook  * 4. If you include any Windows specific code (or a derivative thereof) from
38f1b4d7a8Sbcook  *    the apps directory (application code) you must include an acknowledgement:
39f1b4d7a8Sbcook  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40f1b4d7a8Sbcook  *
41f1b4d7a8Sbcook  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42f1b4d7a8Sbcook  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43f1b4d7a8Sbcook  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44f1b4d7a8Sbcook  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45f1b4d7a8Sbcook  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46f1b4d7a8Sbcook  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47f1b4d7a8Sbcook  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48f1b4d7a8Sbcook  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49f1b4d7a8Sbcook  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50f1b4d7a8Sbcook  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51f1b4d7a8Sbcook  * SUCH DAMAGE.
52f1b4d7a8Sbcook  *
53f1b4d7a8Sbcook  * The licence and distribution terms for any publically available version or
54f1b4d7a8Sbcook  * derivative of this code cannot be changed.  i.e. this code cannot simply be
55f1b4d7a8Sbcook  * copied and put under another distribution licence
56f1b4d7a8Sbcook  * [including the GNU Public Licence.]
57f1b4d7a8Sbcook  */
58f1b4d7a8Sbcook 
59f1b4d7a8Sbcook /*
60f1b4d7a8Sbcook  * Functions that need to be overridden by non-POSIX operating systems.
61f1b4d7a8Sbcook  */
62f1b4d7a8Sbcook 
63f1b4d7a8Sbcook #include <fcntl.h>
64f1b4d7a8Sbcook #include <unistd.h>
65f1b4d7a8Sbcook 
66f1b4d7a8Sbcook #include <openssl/bio.h>
67f1b4d7a8Sbcook 
68f1b4d7a8Sbcook int
BIO_sock_init(void)69f1b4d7a8Sbcook BIO_sock_init(void)
70f1b4d7a8Sbcook {
71e68eaf89Sbeck 	if (!OPENSSL_init_crypto(0, NULL)) /* XXX do we need this? */
72e68eaf89Sbeck 		return (0);
73f1b4d7a8Sbcook 	return (1);
74f1b4d7a8Sbcook }
75*acf64401Sbeck LCRYPTO_ALIAS(BIO_sock_init);
76f1b4d7a8Sbcook 
77f1b4d7a8Sbcook void
BIO_sock_cleanup(void)78f1b4d7a8Sbcook BIO_sock_cleanup(void)
79f1b4d7a8Sbcook {
80f1b4d7a8Sbcook }
81*acf64401Sbeck LCRYPTO_ALIAS(BIO_sock_cleanup);
82f1b4d7a8Sbcook 
83f1b4d7a8Sbcook int
BIO_socket_nbio(int s,int mode)84f1b4d7a8Sbcook BIO_socket_nbio(int s, int mode)
85f1b4d7a8Sbcook {
86f1b4d7a8Sbcook 	int flags = fcntl(s, F_GETFD);
87f1b4d7a8Sbcook 	if (mode && !(flags & O_NONBLOCK))
88f1b4d7a8Sbcook 		return (fcntl(s, F_SETFL, flags | O_NONBLOCK) != -1);
89f1b4d7a8Sbcook 	else if (!mode && (flags & O_NONBLOCK))
90f1b4d7a8Sbcook 		return (fcntl(s, F_SETFL, flags & ~O_NONBLOCK) != -1);
91f1b4d7a8Sbcook 	return (1);
92f1b4d7a8Sbcook }
93*acf64401Sbeck LCRYPTO_ALIAS(BIO_socket_nbio);
94