]>
git.proxmox.com Git - efi-boot-shim.git/blob - Cryptlib/OpenSSL/crypto/bio/bss_fd.c
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
15 #if defined(OPENSSL_NO_POSIX_IO)
17 * Dummy placeholder for BIO_s_fd...
19 BIO
*BIO_new_fd(int fd
, int close_flag
)
24 int BIO_fd_non_fatal_error(int err
)
29 int BIO_fd_should_retry(int i
)
34 const BIO_METHOD
*BIO_s_fd(void)
40 * As for unconditional usage of "UPLINK" interface in this module.
41 * Trouble is that unlike Unix file descriptors [which are indexes
42 * in kernel-side per-process table], corresponding descriptors on
43 * platforms which require "UPLINK" interface seem to be indexes
44 * in a user-land, non-global table. Well, in fact they are indexes
45 * in stdio _iob[], and recall that _iob[] was the very reason why
46 * "UPLINK" interface was introduced in first place. But one way on
47 * another. Neither libcrypto or libssl use this BIO meaning that
48 * file descriptors can only be provided by application. Therefore
49 * "UPLINK" calls are due...
51 static int fd_write(BIO
*h
, const char *buf
, int num
);
52 static int fd_read(BIO
*h
, char *buf
, int size
);
53 static int fd_puts(BIO
*h
, const char *str
);
54 static int fd_gets(BIO
*h
, char *buf
, int size
);
55 static long fd_ctrl(BIO
*h
, int cmd
, long arg1
, void *arg2
);
56 static int fd_new(BIO
*h
);
57 static int fd_free(BIO
*data
);
58 int BIO_fd_should_retry(int s
);
60 static const BIO_METHOD methods_fdp
= {
61 BIO_TYPE_FD
, "file descriptor",
72 const BIO_METHOD
*BIO_s_fd(void)
74 return (&methods_fdp
);
77 BIO
*BIO_new_fd(int fd
, int close_flag
)
80 ret
= BIO_new(BIO_s_fd());
83 BIO_set_fd(ret
, fd
, close_flag
);
87 static int fd_new(BIO
*bi
)
92 bi
->flags
= BIO_FLAGS_UPLINK
; /* essentially redundant */
96 static int fd_free(BIO
*a
)
105 a
->flags
= BIO_FLAGS_UPLINK
;
110 static int fd_read(BIO
*b
, char *out
, int outl
)
116 ret
= UP_read(b
->num
, out
, outl
);
117 BIO_clear_retry_flags(b
);
119 if (BIO_fd_should_retry(ret
))
120 BIO_set_retry_read(b
);
126 static int fd_write(BIO
*b
, const char *in
, int inl
)
130 ret
= UP_write(b
->num
, in
, inl
);
131 BIO_clear_retry_flags(b
);
133 if (BIO_fd_should_retry(ret
))
134 BIO_set_retry_write(b
);
139 static long fd_ctrl(BIO
*b
, int cmd
, long num
, void *ptr
)
147 case BIO_C_FILE_SEEK
:
148 ret
= (long)UP_lseek(b
->num
, num
, 0);
150 case BIO_C_FILE_TELL
:
152 ret
= (long)UP_lseek(b
->num
, 0, 1);
156 b
->num
= *((int *)ptr
);
157 b
->shutdown
= (int)num
;
169 case BIO_CTRL_GET_CLOSE
:
172 case BIO_CTRL_SET_CLOSE
:
173 b
->shutdown
= (int)num
;
175 case BIO_CTRL_PENDING
:
176 case BIO_CTRL_WPENDING
:
190 static int fd_puts(BIO
*bp
, const char *str
)
195 ret
= fd_write(bp
, str
, n
);
199 static int fd_gets(BIO
*bp
, char *buf
, int size
)
203 char *end
= buf
+ size
- 1;
205 while ((ptr
< end
) && (fd_read(bp
, ptr
, 1) > 0) && (ptr
[0] != '\n'))
215 int BIO_fd_should_retry(int i
)
219 if ((i
== 0) || (i
== -1)) {
220 err
= get_last_sys_error();
222 return (BIO_fd_non_fatal_error(err
));
227 int BIO_fd_non_fatal_error(int err
)
232 # ifdef WSAEWOULDBLOCK
233 # if WSAEWOULDBLOCK != EWOULDBLOCK
241 # if defined(ENOTCONN)
250 # if EWOULDBLOCK != EAGAIN