Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
asn1c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
asn1c
Commits
7bb9d5b1
Commit
7bb9d5b1
authored
7 years ago
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
suppress binary output to a terminal
parent
a4a87215
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
5 deletions
+21
-5
skeletons/converter-sample.c
skeletons/converter-sample.c
+21
-5
No files found.
skeletons/converter-sample.c
View file @
7bb9d5b1
...
@@ -87,6 +87,7 @@ DEBUG(const char *fmt, ...) {
...
@@ -87,6 +87,7 @@ DEBUG(const char *fmt, ...) {
int
int
main
(
int
ac
,
char
*
av
[])
{
main
(
int
ac
,
char
*
av
[])
{
FILE
*
binary_out
;
static
asn_TYPE_descriptor_t
*
pduType
=
&
PDU_Type
;
static
asn_TYPE_descriptor_t
*
pduType
=
&
PDU_Type
;
ssize_t
suggested_bufsize
=
8192
;
/* close or equal to stdio buffer */
ssize_t
suggested_bufsize
=
8192
;
/* close or equal to stdio buffer */
int
number_of_iterations
=
1
;
int
number_of_iterations
=
1
;
...
@@ -271,6 +272,21 @@ main(int ac, char *av[]) {
...
@@ -271,6 +272,21 @@ main(int ac, char *av[]) {
exit
(
EX_USAGE
);
exit
(
EX_USAGE
);
}
}
if
(
isatty
(
1
))
{
const
int
is_text_output
=
oform
==
OUT_TEXT
||
oform
==
OUT_XER
;
if
(
is_text_output
)
{
binary_out
=
stdout
;
}
else
{
fprintf
(
stderr
,
"(Suppressing binary output to a terminal.)
\n
"
);
binary_out
=
fopen
(
"/dev/null"
,
"wb"
);
if
(
!
binary_out
)
{
fprintf
(
stderr
,
"Can't open /dev/null: %s
\n
"
,
strerror
(
errno
));
exit
(
EX_OSERR
);
}
}
}
else
{
binary_out
=
stdout
;
}
setvbuf
(
stdout
,
0
,
_IOLBF
,
0
);
setvbuf
(
stdout
,
0
,
_IOLBF
,
0
);
for
(
num
=
0
;
num
<
number_of_iterations
;
num
++
)
{
for
(
num
=
0
;
num
<
number_of_iterations
;
num
++
)
{
...
@@ -332,7 +348,7 @@ main(int ac, char *av[]) {
...
@@ -332,7 +348,7 @@ main(int ac, char *av[]) {
}
}
break
;
break
;
case
OUT_DER
:
case
OUT_DER
:
erv
=
der_encode
(
pduType
,
structure
,
write_out
,
std
out
);
erv
=
der_encode
(
pduType
,
structure
,
write_out
,
binary_
out
);
if
(
erv
.
encoded
<
0
)
{
if
(
erv
.
encoded
<
0
)
{
fprintf
(
stderr
,
"%s: Cannot convert %s into DER
\n
"
,
name
,
fprintf
(
stderr
,
"%s: Cannot convert %s into DER
\n
"
,
name
,
pduType
->
name
);
pduType
->
name
);
...
@@ -344,7 +360,7 @@ main(int ac, char *av[]) {
...
@@ -344,7 +360,7 @@ main(int ac, char *av[]) {
#ifdef ASN_DISABLE_OER_SUPPORT
#ifdef ASN_DISABLE_OER_SUPPORT
erv
.
encoded
=
-
1
;
erv
.
encoded
=
-
1
;
#else
#else
erv
=
oer_encode
(
pduType
,
structure
,
write_out
,
std
out
);
erv
=
oer_encode
(
pduType
,
structure
,
write_out
,
binary_
out
);
#endif
#endif
if
(
erv
.
encoded
<
0
)
{
if
(
erv
.
encoded
<
0
)
{
fprintf
(
stderr
,
"%s: Cannot convert %s into oER
\n
"
,
name
,
fprintf
(
stderr
,
"%s: Cannot convert %s into oER
\n
"
,
name
,
...
@@ -357,7 +373,7 @@ main(int ac, char *av[]) {
...
@@ -357,7 +373,7 @@ main(int ac, char *av[]) {
#ifdef ASN_DISABLE_PER_SUPPORT
#ifdef ASN_DISABLE_PER_SUPPORT
erv
.
encoded
=
-
1
;
erv
.
encoded
=
-
1
;
#else
#else
erv
=
uper_encode
(
pduType
,
structure
,
write_out
,
std
out
);
erv
=
uper_encode
(
pduType
,
structure
,
write_out
,
binary_
out
);
#endif
#endif
if
(
erv
.
encoded
<
0
)
{
if
(
erv
.
encoded
<
0
)
{
fprintf
(
stderr
,
fprintf
(
stderr
,
...
@@ -367,9 +383,9 @@ main(int ac, char *av[]) {
...
@@ -367,9 +383,9 @@ main(int ac, char *av[]) {
}
}
DEBUG
(
"Encoded in %ld bits of UPER"
,
(
long
)
erv
.
encoded
);
DEBUG
(
"Encoded in %ld bits of UPER"
,
(
long
)
erv
.
encoded
);
break
;
break
;
}
}
ASN_STRUCT_FREE
(
*
pduType
,
structure
);
ASN_STRUCT_FREE
(
*
pduType
,
structure
);
}
}
if
(
file
&&
file
!=
stdin
)
{
if
(
file
&&
file
!=
stdin
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment