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
da672c41
Commit
da672c41
authored
Nov 18, 2017
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better error reporting when destination directory is not available
parent
4645db07
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
96 deletions
+119
-96
libasn1compiler/asn1c_compat.c
libasn1compiler/asn1c_compat.c
+17
-10
libasn1compiler/asn1c_save.c
libasn1compiler/asn1c_save.c
+102
-86
No files found.
libasn1compiler/asn1c_compat.c
View file @
da672c41
...
...
@@ -36,7 +36,8 @@ int mkstemp(char *template) {
#endif
FILE
*
asn1c_open_file
(
const
char
*
destdir
,
const
char
*
name
,
const
char
*
ext
,
char
**
opt_tmpname
)
{
asn1c_open_file
(
const
char
*
destdir
,
const
char
*
name
,
const
char
*
ext
,
char
**
opt_tmpname
)
{
char
fname
[
PATH_MAX
];
int
created
=
1
;
#ifndef _WIN32
...
...
@@ -49,10 +50,8 @@ asn1c_open_file(const char* destdir, const char *name, const char *ext, char **o
/*
* Compute filenames.
*/
ret
=
snprintf
(
fname
,
sizeof
(
fname
),
"%s%s%s%s"
,
opt_tmpname
?
""
:
destdir
,
name
,
ext
,
opt_tmpname
?
".XXXXXX"
:
""
);
ret
=
snprintf
(
fname
,
sizeof
(
fname
),
"%s%s%s%s"
,
destdir
?
destdir
:
""
,
name
,
ext
,
opt_tmpname
?
".XXXXXX"
:
""
);
assert
(
ret
>
0
&&
ret
<
(
ssize_t
)
sizeof
(
fname
));
if
(
opt_tmpname
)
{
...
...
@@ -61,8 +60,10 @@ asn1c_open_file(const char* destdir, const char *name, const char *ext, char **o
*/
fd
=
mkstemp
(
fname
);
#ifndef _WIN32
if
(
fd
!=
-
1
)
{
/* fchmod() does not respect umask */
(
void
)
fchmod
(
fd
,
REASONABLE_FILE_MODE
);
}
#endif
}
else
{
/*
...
...
@@ -75,9 +76,15 @@ asn1c_open_file(const char* destdir, const char *name, const char *ext, char **o
}
}
if
(
fd
==
-
1
)
{
struct
stat
st
;
if
(
destdir
&&
stat
(
destdir
,
&
st
)
==
-
1
)
{
fprintf
(
stderr
,
"%s: No such directory
\n
"
,
destdir
);
return
NULL
;
}
else
{
perror
(
fname
);
return
NULL
;
}
}
#ifndef _WIN32
/*
...
...
libasn1compiler/asn1c_save.c
View file @
da672c41
...
...
@@ -40,8 +40,10 @@ enum include_type_result {
static
int
asn1c_dump_streams
(
arg_t
*
arg
,
asn1c_dep_chainset
*
,
const
char
*
,
int
,
char
**
);
static
int
asn1c_print_streams
(
arg_t
*
arg
);
static
int
asn1c_save_streams
(
arg_t
*
arg
,
asn1c_dep_chainset
*
,
const
char
*
,
int
,
char
**
);
static
int
asn1c_copy_over
(
arg_t
*
arg
,
const
char
*
destdir
,
const
char
*
path
,
const
char
*
msg
);
static
int
asn1c_save_streams
(
arg_t
*
arg
,
asn1c_dep_chainset
*
,
const
char
*
,
int
,
char
**
);
static
int
asn1c_copy_over
(
arg_t
*
arg
,
const
char
*
destdir
,
const
char
*
path
,
const
char
*
msg
);
static
int
identical_files
(
const
char
*
fname1
,
const
char
*
fname2
);
static
int
need_to_generate_pdu_collection
(
arg_t
*
arg
);
static
abuf
*
generate_pdu_collection
(
arg_t
*
arg
);
...
...
@@ -55,7 +57,8 @@ static int asn1c__pdu_type_lookup(const char *typename);
static
int
asn1c__save_library_makefile
(
arg_t
*
arg
,
const
asn1c_dep_chainset
*
deps
,
const
char
*
datadir
,
const
char
*
destdir
,
const
char
*
makefile_name
)
{
const
char
*
datadir
,
const
char
*
destdir
,
const
char
*
makefile_name
)
{
asn1p_module_t
*
mod
;
FILE
*
mkf
;
...
...
@@ -80,7 +83,8 @@ asn1c__save_library_makefile(arg_t *arg, const asn1c_dep_chainset *deps,
TQ_FOR
(
arg
->
expr
,
&
(
mod
->
members
),
next
)
{
if
(
asn1_lang_map
[
arg
->
expr
->
meta_type
]
[
arg
->
expr
->
expr_type
].
type_cb
)
{
safe_fprintf
(
mkf
,
"
\t\\\n\t
%s%s.h"
,
destdir
,
safe_fprintf
(
mkf
,
"
\t\\\n\t
%s%s.h"
,
destdir
,
asn1c_make_identifier
(
AMI_MASK_ONLY_SPACES
,
arg
->
expr
,
0
));
}
}
...
...
@@ -131,7 +135,8 @@ asn1c__save_library_makefile(arg_t *arg, const asn1c_dep_chainset *deps,
}
else
{
what_kind
=
"SRCS"
;
}
safe_fprintf
(
mkf
,
"ASN_MODULE_%s+=%s%s
\n
"
,
what_kind
,
destdir
,
fname
);
safe_fprintf
(
mkf
,
"ASN_MODULE_%s+=%s%s
\n
"
,
what_kind
,
destdir
,
fname
);
}
asn1c_dep_chain_free
(
dlist
);
...
...
@@ -160,8 +165,9 @@ asn1c__save_library_makefile(arg_t *arg, const asn1c_dep_chainset *deps,
}
static
int
asn1c__save_example_mk_makefile
(
arg_t
*
arg
,
const
asn1c_dep_chainset
*
deps
,
const
char
*
datadir
,
const
char
*
destdir
,
const
char
*
makefile_name
,
asn1c__save_example_mk_makefile
(
arg_t
*
arg
,
const
asn1c_dep_chainset
*
deps
,
const
char
*
datadir
,
const
char
*
destdir
,
const
char
*
makefile_name
,
const
char
*
library_makefile_name
,
int
argc
,
char
**
argv
)
{
FILE
*
mkf
;
...
...
@@ -173,7 +179,8 @@ asn1c__save_example_mk_makefile(arg_t *arg, const asn1c_dep_chainset *deps, cons
perror
(
makefile_name
);
return
-
1
;
}
safe_fprintf
(
mkf
,
safe_fprintf
(
mkf
,
"include %s%s
\n\n
"
"LIBS += -lm
\n
"
"CFLAGS += $(ASN_MODULE_CFLAGS) %s%s-I.
\n
"
...
...
@@ -202,15 +209,17 @@ asn1c__save_example_mk_makefile(arg_t *arg, const asn1c_dep_chainset *deps, cons
if
(
need_to_generate_pdu_collection
(
arg
))
{
safe_fprintf
(
mkf
,
"
\\\n\t
%spdu_collection.c"
,
destdir
);
if
(
generate_pdu_collection_file
(
arg
,
destdir
))
if
(
generate_pdu_collection_file
(
arg
,
destdir
))
{
return
-
1
;
}
}
safe_fprintf
(
mkf
,
"
\n\n
all: $(ASN_PROGRAM)
\n
"
"
\n
$(ASN_PROGRAM): $(ASN_LIBRARY) $(ASN_PROGRAM_SRCS:.c=.o)"
"
\n\t
$(CC) $(CFLAGS) $(CPPFLAGS) -o $(ASN_PROGRAM) $(ASN_PROGRAM_SRCS:.c=.o) $(LDFLAGS) $(ASN_LIBRARY) $(LIBS)
\n
"
"
\n\t
$(CC) $(CFLAGS) $(CPPFLAGS) -o $(ASN_PROGRAM) "
"$(ASN_PROGRAM_SRCS:.c=.o) $(LDFLAGS) $(ASN_LIBRARY) $(LIBS)
\n
"
"
\n
$(ASN_LIBRARY): $(ASN_MODULE_SRCS:.c=.o)"
"
\n\t
$(AR) rcs $@ $(ASN_MODULE_SRCS:.c=.o)
\n
"
"
\n
.SUFFIXES:"
...
...
@@ -244,7 +253,6 @@ asn1c__save_example_am_makefile(arg_t *arg, const asn1c_dep_chainset *deps, cons
/* Generate example.am snippet */
mkf
=
asn1c_open_file
(
destdir
,
makefile_name
,
""
,
0
);
if
(
mkf
==
NULL
)
{
perror
(
makefile_name
);
return
-
1
;
}
safe_fprintf
(
mkf
,
...
...
@@ -387,7 +395,8 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir, const char *destdir,
TQ_FOR
(
arg
->
expr
,
&
(
mod
->
members
),
next
)
{
if
(
asn1_lang_map
[
arg
->
expr
->
meta_type
][
arg
->
expr
->
expr_type
]
.
type_cb
)
{
if
(
asn1c_dump_streams
(
arg
,
deps
,
destdir
,
optc
,
argv
))
break
;
ret
=
asn1c_dump_streams
(
arg
,
deps
,
destdir
,
optc
,
argv
);
if
(
ret
)
break
;
}
}
}
...
...
@@ -401,6 +410,8 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir, const char *destdir,
break
;
}
if
(
ret
)
break
;
ret
=
asn1c__save_library_makefile
(
arg
,
deps
,
datadir
,
destdir
,
library_makefile
);
if
(
ret
)
break
;
...
...
@@ -432,8 +443,8 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir, const char *destdir,
* Dump the streams.
*/
static
int
asn1c_dump_streams
(
arg_t
*
arg
,
asn1c_dep_chainset
*
deps
,
const
char
*
destdir
,
int
optc
,
char
**
argv
)
{
asn1c_dump_streams
(
arg_t
*
arg
,
asn1c_dep_chainset
*
deps
,
const
char
*
destdir
,
int
optc
,
char
**
argv
)
{
if
(
arg
->
flags
&
A1C_PRINT_COMPILED
)
{
return
asn1c_print_streams
(
arg
);
}
else
{
...
...
@@ -465,8 +476,8 @@ asn1c_print_streams(arg_t *arg) {
}
static
int
asn1c_save_streams
(
arg_t
*
arg
,
asn1c_dep_chainset
*
deps
,
const
char
*
destdir
,
int
optc
,
char
**
argv
)
{
asn1c_save_streams
(
arg_t
*
arg
,
asn1c_dep_chainset
*
deps
,
const
char
*
destdir
,
int
optc
,
char
**
argv
)
{
asn1p_expr_t
*
expr
=
arg
->
expr
;
compiler_streams_t
*
cs
=
expr
->
data
;
out_chunk_t
*
ot
;
...
...
@@ -486,10 +497,14 @@ asn1c_save_streams(arg_t *arg, asn1c_dep_chainset *deps, const char* destdir, in
filename
=
strdup
(
asn1c_make_identifier
(
AMI_MASK_ONLY_SPACES
,
expr
,
(
char
*
)
0
));
fp_c
=
asn1c_open_file
(
destdir
,
filename
,
".c"
,
&
tmpname_c
);
if
(
fp_c
==
NULL
)
{
return
-
1
;
}
fp_h
=
asn1c_open_file
(
destdir
,
filename
,
".h"
,
&
tmpname_h
);
if
(
fp_c
==
NULL
||
fp_h
==
NULL
)
{
if
(
fp_c
)
{
unlink
(
tmpname_c
);
free
(
tmpname_c
);
fclose
(
fp_c
);
}
if
(
fp_h
)
{
unlink
(
tmpname_h
);
free
(
tmpname_h
);
fclose
(
fp_h
);
}
if
(
fp_h
==
NULL
)
{
unlink
(
tmpname_c
);
free
(
tmpname_c
);
fclose
(
fp_c
);
return
-
1
;
}
...
...
@@ -690,7 +705,8 @@ real_copy(const char *src, const char *dst) {
}
static
int
asn1c_copy_over
(
arg_t
*
arg
,
const
char
*
destdir
,
const
char
*
path
,
const
char
*
msg
)
{
asn1c_copy_over
(
arg_t
*
arg
,
const
char
*
destdir
,
const
char
*
path
,
const
char
*
msg
)
{
#ifdef _WIN32
int
use_real_copy
=
1
;
#else
...
...
@@ -741,7 +757,7 @@ asn1c_copy_over(arg_t *arg, const char* destdir, const char *path, const char *m
static
int
generate_pdu_collection_file
(
arg_t
*
arg
,
const
char
*
destdir
)
{
generate_pdu_collection_file
(
arg_t
*
arg
,
const
char
*
destdir
)
{
abuf
*
buf
=
generate_pdu_collection
(
arg
);
assert
(
buf
);
...
...
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