Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Openssl
提交
a412b891
T
Third Party Openssl
项目概览
OpenHarmony
/
Third Party Openssl
接近 2 年 前同步成功
通知
12
Star
18
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Openssl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a412b891
编写于
9月 06, 2015
作者:
R
Richard Levitte
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dup_bio_* and bio_open_* are utility functions and belong in apps.c
Reviewed-by:
N
Tim Hudson
<
tjh@openssl.org
>
上级
29717229
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
158 addition
and
151 deletion
+158
-151
apps/apps.c
apps/apps.c
+158
-1
apps/openssl.c
apps/openssl.c
+0
-150
未找到文件。
apps/apps.c
浏览文件 @
a412b891
...
...
@@ -121,7 +121,13 @@
#if !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_WINCE) && !defined(NETWARE_CLIB)
# include <strings.h>
#endif
#include <sys/types.h>
#ifndef NO_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifndef OPENSSL_NO_POSIX_IO
# include <sys/stat.h>
# include <fcntl.h>
#endif
#include <ctype.h>
#include <errno.h>
#include <openssl/err.h>
...
...
@@ -2707,3 +2713,154 @@ int raw_write_stdout(const void *buf, int siz)
return
write
(
fileno
(
stdout
),
buf
,
siz
);
}
#endif
/*
* Centralized handling if input and output files with format specification
* The format is meant to show what the input and output is supposed to be,
* and is therefore a show of intent more than anything else. However, it
* does impact behavior on some platform, such as differentiating between
* text and binary input/output on non-Unix platforms
*/
BIO
*
dup_bio_in
(
void
)
{
return
BIO_new_fp
(
stdin
,
BIO_NOCLOSE
|
BIO_FP_TEXT
);
}
BIO
*
dup_bio_out
(
void
)
{
BIO
*
b
=
BIO_new_fp
(
stdout
,
BIO_NOCLOSE
|
BIO_FP_TEXT
);
#ifdef OPENSSL_SYS_VMS
b
=
BIO_push
(
BIO_new
(
BIO_f_linebuffer
()),
b
);
#endif
return
b
;
}
void
unbuffer
(
FILE
*
fp
)
{
setbuf
(
fp
,
NULL
);
}
static
const
char
*
modestr
(
char
mode
,
int
format
)
{
OPENSSL_assert
(
mode
==
'a'
||
mode
==
'r'
||
mode
==
'w'
);
switch
(
mode
)
{
case
'a'
:
return
(
format
&
B_FORMAT_TEXT
)
?
"a"
:
"ab"
;
case
'r'
:
return
(
format
&
B_FORMAT_TEXT
)
?
"r"
:
"rb"
;
case
'w'
:
return
(
format
&
B_FORMAT_TEXT
)
?
"w"
:
"wb"
;
}
/* The assert above should make sure we never reach this point */
return
NULL
;
}
static
const
char
*
modeverb
(
char
mode
)
{
switch
(
mode
)
{
case
'a'
:
return
"appending"
;
case
'r'
:
return
"reading"
;
case
'w'
:
return
"writing"
;
}
return
"(doing something)"
;
}
/*
* Open a file for writing, owner-read-only.
*/
BIO
*
bio_open_owner
(
const
char
*
filename
,
int
format
,
int
private
)
{
FILE
*
fp
=
NULL
;
BIO
*
b
=
NULL
;
int
fd
=
-
1
,
bflags
,
mode
,
binmode
;
if
(
!
private
||
filename
==
NULL
||
strcmp
(
filename
,
"-"
)
==
0
)
return
bio_open_default
(
filename
,
'w'
,
format
);
mode
=
O_WRONLY
;
#ifdef O_CREAT
mode
|=
O_CREAT
;
#endif
#ifdef O_TRUNC
mode
|=
O_TRUNC
;
#endif
binmode
=
!
(
format
&
B_FORMAT_TEXT
);
if
(
binmode
)
{
#ifdef O_BINARY
mode
|=
O_BINARY
;
#elif defined(_O_BINARY)
mode
|=
_O_BINARY
;
#endif
}
fd
=
open
(
filename
,
mode
,
0600
);
if
(
fd
<
0
)
goto
err
;
fp
=
fdopen
(
fd
,
modestr
(
'w'
,
format
));
if
(
fp
==
NULL
)
goto
err
;
bflags
=
BIO_CLOSE
;
if
(
!
binmode
)
bflags
|=
BIO_FP_TEXT
;
b
=
BIO_new_fp
(
fp
,
bflags
);
if
(
b
)
return
b
;
err:
BIO_printf
(
bio_err
,
"%s: Can't open
\"
%s
\"
for writing, %s
\n
"
,
opt_getprog
(),
filename
,
strerror
(
errno
));
ERR_print_errors
(
bio_err
);
/* If we have fp, then fdopen took over fd, so don't close both. */
if
(
fp
)
fclose
(
fp
);
else
if
(
fd
>=
0
)
close
(
fd
);
return
NULL
;
}
static
BIO
*
bio_open_default_
(
const
char
*
filename
,
char
mode
,
int
format
,
int
quiet
)
{
BIO
*
ret
;
if
(
filename
==
NULL
||
strcmp
(
filename
,
"-"
)
==
0
)
{
ret
=
mode
==
'r'
?
dup_bio_in
()
:
dup_bio_out
();
if
(
quiet
)
{
ERR_clear_error
();
return
ret
;
}
if
(
ret
!=
NULL
)
return
ret
;
BIO_printf
(
bio_err
,
"Can't open %s, %s
\n
"
,
mode
==
'r'
?
"stdin"
:
"stdout"
,
strerror
(
errno
));
}
else
{
ret
=
BIO_new_file
(
filename
,
modestr
(
mode
,
format
));
if
(
quiet
)
{
ERR_clear_error
();
return
ret
;
}
if
(
ret
!=
NULL
)
return
ret
;
BIO_printf
(
bio_err
,
"Can't open %s for %s, %s
\n
"
,
filename
,
modeverb
(
mode
),
strerror
(
errno
));
}
ERR_print_errors
(
bio_err
);
return
NULL
;
}
BIO
*
bio_open_default
(
const
char
*
filename
,
char
mode
,
int
format
)
{
return
bio_open_default_
(
filename
,
mode
,
format
,
0
);
}
BIO
*
bio_open_default_quiet
(
const
char
*
filename
,
char
mode
,
int
format
)
{
return
bio_open_default_
(
filename
,
mode
,
format
,
1
);
}
apps/openssl.c
浏览文件 @
a412b891
...
...
@@ -132,13 +132,6 @@
#ifdef OPENSSL_SYS_VMS
# include <unixio.h>
#endif
#ifndef NO_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifndef OPENSSL_NO_POSIX_IO
# include <sys/stat.h>
# include <fcntl.h>
#endif
#define INCLUDE_FUNCTION_TABLE
#include "apps.h"
...
...
@@ -280,149 +273,6 @@ static void lock_dbg_cb(int mode, int type, const char *file, int line)
}
}
BIO
*
dup_bio_in
(
void
)
{
return
BIO_new_fp
(
stdin
,
BIO_NOCLOSE
|
BIO_FP_TEXT
);
}
BIO
*
dup_bio_out
(
void
)
{
BIO
*
b
=
BIO_new_fp
(
stdout
,
BIO_NOCLOSE
|
BIO_FP_TEXT
);
#ifdef OPENSSL_SYS_VMS
b
=
BIO_push
(
BIO_new
(
BIO_f_linebuffer
()),
b
);
#endif
return
b
;
}
void
unbuffer
(
FILE
*
fp
)
{
setbuf
(
fp
,
NULL
);
}
static
const
char
*
modestr
(
char
mode
,
int
format
)
{
OPENSSL_assert
(
mode
==
'a'
||
mode
==
'r'
||
mode
==
'w'
);
switch
(
mode
)
{
case
'a'
:
return
(
format
&
B_FORMAT_TEXT
)
?
"a"
:
"ab"
;
case
'r'
:
return
(
format
&
B_FORMAT_TEXT
)
?
"r"
:
"rb"
;
case
'w'
:
return
(
format
&
B_FORMAT_TEXT
)
?
"w"
:
"wb"
;
}
/* The assert above should make sure we never reach this point */
return
NULL
;
}
static
const
char
*
modeverb
(
char
mode
)
{
switch
(
mode
)
{
case
'a'
:
return
"appending"
;
case
'r'
:
return
"reading"
;
case
'w'
:
return
"writing"
;
}
return
"(doing something)"
;
}
/*
* Open a file for writing, owner-read-only.
*/
BIO
*
bio_open_owner
(
const
char
*
filename
,
int
format
,
int
private
)
{
FILE
*
fp
=
NULL
;
BIO
*
b
=
NULL
;
int
fd
=
-
1
,
bflags
,
mode
,
binmode
;
if
(
!
private
||
filename
==
NULL
||
strcmp
(
filename
,
"-"
)
==
0
)
return
bio_open_default
(
filename
,
'w'
,
format
);
mode
=
O_WRONLY
;
#ifdef O_CREAT
mode
|=
O_CREAT
;
#endif
#ifdef O_TRUNC
mode
|=
O_TRUNC
;
#endif
binmode
=
!
(
format
&
B_FORMAT_TEXT
);
if
(
binmode
)
{
#ifdef O_BINARY
mode
|=
O_BINARY
;
#elif defined(_O_BINARY)
mode
|=
_O_BINARY
;
#endif
}
fd
=
open
(
filename
,
mode
,
0600
);
if
(
fd
<
0
)
goto
err
;
fp
=
fdopen
(
fd
,
modestr
(
'w'
,
format
));
if
(
fp
==
NULL
)
goto
err
;
bflags
=
BIO_CLOSE
;
if
(
!
binmode
)
bflags
|=
BIO_FP_TEXT
;
b
=
BIO_new_fp
(
fp
,
bflags
);
if
(
b
)
return
b
;
err:
BIO_printf
(
bio_err
,
"%s: Can't open
\"
%s
\"
for writing, %s
\n
"
,
opt_getprog
(),
filename
,
strerror
(
errno
));
ERR_print_errors
(
bio_err
);
/* If we have fp, then fdopen took over fd, so don't close both. */
if
(
fp
)
fclose
(
fp
);
else
if
(
fd
>=
0
)
close
(
fd
);
return
NULL
;
}
static
BIO
*
bio_open_default_
(
const
char
*
filename
,
char
mode
,
int
format
,
int
quiet
)
{
BIO
*
ret
;
if
(
filename
==
NULL
||
strcmp
(
filename
,
"-"
)
==
0
)
{
ret
=
mode
==
'r'
?
dup_bio_in
()
:
dup_bio_out
();
if
(
quiet
)
{
ERR_clear_error
();
return
ret
;
}
if
(
ret
!=
NULL
)
return
ret
;
BIO_printf
(
bio_err
,
"Can't open %s, %s
\n
"
,
mode
==
'r'
?
"stdin"
:
"stdout"
,
strerror
(
errno
));
}
else
{
ret
=
BIO_new_file
(
filename
,
modestr
(
mode
,
format
));
if
(
quiet
)
{
ERR_clear_error
();
return
ret
;
}
if
(
ret
!=
NULL
)
return
ret
;
BIO_printf
(
bio_err
,
"Can't open %s for %s, %s
\n
"
,
filename
,
modeverb
(
mode
),
strerror
(
errno
));
}
ERR_print_errors
(
bio_err
);
return
NULL
;
}
BIO
*
bio_open_default
(
const
char
*
filename
,
char
mode
,
int
format
)
{
return
bio_open_default_
(
filename
,
mode
,
format
,
0
);
}
BIO
*
bio_open_default_quiet
(
const
char
*
filename
,
char
mode
,
int
format
)
{
return
bio_open_default_
(
filename
,
mode
,
format
,
1
);
}
#if defined( OPENSSL_SYS_VMS)
extern
char
**
copy_argv
(
int
*
argc
,
char
**
argv
);
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录