OPENSSL_Applink update.
[openssl.git] / crypto / bio / bss_fd.c
index 5e3e187de6892a8ffadc919d9a6228c3d698b6b5..4c229bf64103258a41eb05279a80085329c57650 100644 (file)
 #include <errno.h>
 #define USE_SOCKETS
 #include "cryptlib.h"
-#include <openssl/bio.h>
+/*
+ * As for unconditional usage of "UPLINK" interface in this module.
+ * Trouble is that unlike Unix file descriptors [which are indexes
+ * in kernel-side per-process table], corresponding descriptors on
+ * platforms which require "UPLINK" interface seem to be indexes
+ * in a user-land, non-global table. Well, in fact they are indexes
+ * in stdio _iob[], and recall that _iob[] was the very reason why
+ * "UPLINK" interface was introduced in first place. But one way on
+ * another. Neither libcrypto or libssl use this BIO meaning that
+ * file descriptors can only be provided by application. Therefore
+ * "UPLINK" calls are due...
+ */
+#include "bio_lcl.h"
 
 static int fd_write(BIO *h, const char *buf, int num);
 static int fd_read(BIO *h, char *buf, int size);
@@ -100,9 +112,9 @@ BIO *BIO_new_fd(int fd,int close_flag)
 static int fd_new(BIO *bi)
        {
        bi->init=0;
-       bi->num=0;
+       bi->num=-1;
        bi->ptr=NULL;
-       bi->flags=0;
+       bi->flags=BIO_FLAGS_UPLINK; /* essentially redundant */
        return(1);
        }
 
@@ -113,10 +125,10 @@ static int fd_free(BIO *a)
                {
                if (a->init)
                        {
-                       close(a->num);
+                       UP_close(a->num);
                        }
                a->init=0;
-               a->flags=0;
+               a->flags=BIO_FLAGS_UPLINK;
                }
        return(1);
        }
@@ -128,7 +140,7 @@ static int fd_read(BIO *b, char *out,int outl)
        if (out != NULL)
                {
                clear_sys_error();
-               ret=read(b->num,out,outl);
+               ret=UP_read(b->num,out,outl);
                BIO_clear_retry_flags(b);
                if (ret <= 0)
                        {
@@ -143,7 +155,7 @@ static int fd_write(BIO *b, const char *in, int inl)
        {
        int ret;
        clear_sys_error();
-       ret=write(b->num,in,inl);
+       ret=UP_write(b->num,in,inl);
        BIO_clear_retry_flags(b);
        if (ret <= 0)
                {
@@ -163,11 +175,11 @@ static long fd_ctrl(BIO *b, int cmd, long num, void *ptr)
        case BIO_CTRL_RESET:
                num=0;
        case BIO_C_FILE_SEEK:
-               ret=(long)lseek(b->num,num,0);
+               ret=(long)UP_lseek(b->num,num,0);
                break;
        case BIO_C_FILE_TELL:
        case BIO_CTRL_INFO:
-               ret=(long)lseek(b->num,0,1);
+               ret=(long)UP_lseek(b->num,0,1);
                break;
        case BIO_C_SET_FD:
                fd_free(b);