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
4b102255
Commit
4b102255
authored
Aug 19, 2004
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved around
parent
acd9f8b3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
68 deletions
+69
-68
libasn1compiler/asn1c_compat.c
libasn1compiler/asn1c_compat.c
+60
-5
libasn1compiler/asn1c_compat.h
libasn1compiler/asn1c_compat.h
+9
-0
libasn1compiler/asn1c_misc.c
libasn1compiler/asn1c_misc.c
+0
-58
libasn1compiler/asn1c_misc.h
libasn1compiler/asn1c_misc.h
+0
-5
No files found.
libasn1compiler/asn1c_compat.c
View file @
4b102255
#include "asn1c_internal.h"
#include <asn1c_compat.h>
#include <string.h>
#include <errno.h>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
/* For MAXPATHLEN */
#endif
...
...
@@ -11,6 +9,63 @@
#define MAXPATHLEN 1024
#endif
#ifndef DEFFILEMODE
/* Normally in <sys/stat.h> */
#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
#endif
FILE
*
asn1c_open_file
(
const
char
*
name
,
const
char
*
ext
)
{
int
created
=
1
;
struct
stat
sb
;
char
*
fname
;
int
len
;
FILE
*
fp
;
int
fd
;
/*
* Compute filenames.
*/
len
=
strlen
(
name
)
+
strlen
(
ext
)
+
1
;
fname
=
alloca
(
len
);
snprintf
(
fname
,
len
,
"%s%s"
,
name
,
ext
);
/*
* Create files.
*/
fd
=
open
(
fname
,
O_CREAT
|
O_EXCL
|
O_WRONLY
,
DEFFILEMODE
);
if
(
fd
==
-
1
&&
errno
==
EEXIST
)
{
fd
=
open
(
fname
,
O_WRONLY
,
DEFFILEMODE
);
created
=
0
;
}
if
(
fd
==
-
1
)
{
perror
(
fname
);
return
NULL
;
}
/*
* Check sanity.
*/
if
(
fstat
(
fd
,
&
sb
)
||
!
S_ISREG
(
sb
.
st_mode
))
{
fprintf
(
stderr
,
"%s: Not a regular file
\n
"
,
fname
);
if
(
created
)
unlink
(
fname
);
close
(
fd
);
return
NULL
;
}
(
void
)
ftruncate
(
fd
,
0
);
/*
* Convert file descriptor into file pointer.
*/
fp
=
fdopen
(
fd
,
"w"
);
if
(
fp
==
NULL
)
{
if
(
created
)
unlink
(
fname
);
close
(
fd
);
}
return
fp
;
}
char
*
a1c_basename
(
const
char
*
path
)
{
static
char
strbuf
[
MAXPATHLEN
];
...
...
@@ -33,7 +88,7 @@ a1c_basename(const char *path) {
for
(
name
=
pend
;
name
>
path
&&
name
[
-
1
]
!=
'/'
;
name
--
);
if
((
pend
-
name
)
>=
sizeof
(
strbuf
)
-
1
)
{
if
((
pend
-
name
)
>=
(
int
)
sizeof
(
strbuf
)
-
1
)
{
errno
=
ENAMETOOLONG
;
return
0
;
}
...
...
@@ -79,7 +134,7 @@ a1c_dirname(const char *path) {
return
strbuf
;
}
if
((
last
-
path
)
>=
sizeof
(
strbuf
))
{
if
((
last
-
path
)
>=
(
int
)
sizeof
(
strbuf
))
{
errno
=
ENAMETOOLONG
;
return
0
;
}
...
...
libasn1compiler/asn1c_compat.h
View file @
4b102255
...
...
@@ -5,6 +5,15 @@
#include <config.h>
#endif
/*
* Open the arbitrary file by its base name and extension.
*/
FILE
*
asn1c_open_file
(
const
char
*
base_part
,
const
char
*
extension
);
/*
* Obtain base name and directory name of a path.
* Some systems have them in <libgen.h> as dirname(3) and basename(3).
*/
char
*
a1c_basename
(
const
char
*
path
);
char
*
a1c_dirname
(
const
char
*
path
);
...
...
libasn1compiler/asn1c_misc.c
View file @
4b102255
#include "asn1c_internal.h"
#include <asn1fix_export.h>
#ifndef DEFFILEMODE
/* Normally in <sys/stat.h> */
#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
#endif
/*
* Construct identifier from multiple parts.
* Convert unsafe characters to underscores.
...
...
@@ -85,60 +81,6 @@ asn1c_make_identifier(int unsafe_only_spaces, char *arg1, ...) {
return
storage
;
}
FILE
*
asn1c_open_file
(
arg_t
*
arg
,
const
char
*
name
,
const
char
*
ext
)
{
int
created
=
1
;
struct
stat
sb
;
char
*
fname
;
int
len
;
FILE
*
fp
;
int
fd
;
(
void
)
arg
;
/* Unused argument */
/*
* Compute filenames.
*/
len
=
strlen
(
name
)
+
strlen
(
ext
)
+
1
;
fname
=
alloca
(
len
);
snprintf
(
fname
,
len
,
"%s%s"
,
name
,
ext
);
/*
* Create files.
*/
fd
=
open
(
fname
,
O_CREAT
|
O_EXCL
|
O_WRONLY
,
DEFFILEMODE
);
if
(
fd
==
-
1
&&
errno
==
EEXIST
)
{
fd
=
open
(
fname
,
O_WRONLY
,
DEFFILEMODE
);
created
=
0
;
}
if
(
fd
==
-
1
)
{
perror
(
fname
);
return
NULL
;
}
/*
* Check sanity.
*/
if
(
fstat
(
fd
,
&
sb
)
||
!
S_ISREG
(
sb
.
st_mode
))
{
fprintf
(
stderr
,
"%s: Not a regular file
\n
"
,
fname
);
if
(
created
)
unlink
(
fname
);
close
(
fd
);
return
NULL
;
}
(
void
)
ftruncate
(
fd
,
0
);
/*
* Convert file descriptor into file pointer.
*/
fp
=
fdopen
(
fd
,
"w"
);
if
(
fp
==
NULL
)
{
if
(
created
)
unlink
(
fname
);
close
(
fd
);
}
return
fp
;
}
char
*
asn1c_type_name
(
arg_t
*
arg
,
asn1p_expr_t
*
expr
,
enum
tnfmt
_format
)
{
char
*
typename
;
...
...
libasn1compiler/asn1c_misc.h
View file @
4b102255
...
...
@@ -20,9 +20,4 @@ enum tnfmt {
};
char
*
asn1c_type_name
(
arg_t
*
arg
,
asn1p_expr_t
*
expr
,
enum
tnfmt
_format
);
/*
* Open the arbitrary file by its base name and extension.
*/
FILE
*
asn1c_open_file
(
arg_t
*
arg
,
const
char
*
base_part
,
const
char
*
extension
);
#endif
/* _ASN1_COMPILER_MISC_H_ */
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