Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Havar
asn1c
Commits
4efbfb7e
Commit
4efbfb7e
authored
Feb 25, 2005
by
Lev Walkin
Browse files
portability fixes
parent
8d35c46d
Changes
29
Hide whitespace changes
Inline
Side-by-side
asn1c/sys-common.h
View file @
4efbfb7e
...
...
@@ -24,17 +24,26 @@
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
/* for stat(2) */
#include <unistd.h>
#include <assert.h>
#include <errno.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
/* for stat(2) */
#endif
#ifndef WIN32
...
...
config.h.in
View file @
4efbfb7e
/* config.h.in. Generated from configure.in by autoheader. */
/* Define to 1 if you have the <
errno
.h> header file. */
#undef HAVE_
ERRNO
_H
/* Define to 1 if you have the <
dlfcn
.h> header file. */
#undef HAVE_
DLFCN
_H
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
...
...
@@ -9,6 +9,9 @@
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `mergesort' function. */
#undef HAVE_MERGESORT
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
...
...
@@ -27,6 +30,9 @@
/* Define to 1 if you have the `strtoll' function. */
#undef HAVE_STRTOLL
/* Define to 1 if you have the <sys/param.h> header file. */
#undef HAVE_SYS_PARAM_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
...
...
libasn1compiler/asn1c_compat.c
View file @
4efbfb7e
#include "asn1c_internal.h"
#include <asn1c_compat.h>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
/* For MAXPATHLEN */
#endif
#include "asn1c_compat.h"
#ifndef MAXPATHLEN
#define MAXPATHLEN 1024
#endif
#ifndef DEFFILEMODE
/* Normally in <sys/stat.h> */
#ifdef WIN32
#define DEFFILEMODE 0
#else
#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
#endif
#endif
FILE
*
asn1c_open_file
(
const
char
*
name
,
const
char
*
ext
)
{
int
created
=
1
;
#ifndef WIN32
struct
stat
sb
;
#endif
char
*
fname
;
in
t
len
;
size_
t
len
;
FILE
*
fp
;
int
fd
;
...
...
@@ -42,6 +44,7 @@ asn1c_open_file(const char *name, const char *ext) {
return
NULL
;
}
#ifndef WIN32
/*
* Check sanity.
*/
...
...
@@ -53,6 +56,9 @@ asn1c_open_file(const char *name, const char *ext) {
}
(
void
)
ftruncate
(
fd
,
0
);
#else
_chsize
(
fd
,
0
);
#endif
/* WIN32 */
/*
* Convert file descriptor into file pointer.
...
...
libasn1compiler/asn1c_compat.h
View file @
4efbfb7e
#ifndef ASN1C_COMPAT_H
#define ASN1C_COMPAT_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/*
* Open the arbitrary file by its base name and extension.
*/
...
...
libasn1compiler/asn1c_internal.h
View file @
4efbfb7e
...
...
@@ -7,16 +7,37 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
/* for fstat(2) */
#include <unistd.h>
/* for unlink(2) */
#include <fcntl.h>
/* for open(2) */
#include <glob.h>
/* for glob(3) */
#include <string.h>
/* for strlen(3) and memset(3) */
#include <ctype.h>
/* for isalnum(3) */
#include <sys/types.h>
/* for fstat(2) */
#include <stdarg.h>
#include <errno.h>
#include <assert.h>
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
/* for fstat(2) */
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
/* for unlink(2) */
#endif
#ifdef WIN32
#include <io.h>
#define open _open
#define close _close
#define alloca _alloca
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#else
#include <fcntl.h>
/* for open(2) */
#include <glob.h>
/* for glob(3) */
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
/* For MAXPATHLEN */
#endif
#include "asn1compiler.h"
typedef
struct
arg_s
{
...
...
libasn1compiler/asn1c_misc.c
View file @
4efbfb7e
...
...
@@ -32,7 +32,7 @@ asn1c_make_identifier(enum ami_flags_e flags, char *arg1, ...) {
va_list
ap
;
char
*
str
;
char
*
nextstr
;
in
t
size
;
size_
t
size
;
char
*
p
;
if
(
arg1
==
NULL
)
...
...
libasn1compiler/asn1c_save.c
View file @
4efbfb7e
...
...
@@ -76,11 +76,12 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir) {
if
(
dlist
)
{
char
buf
[
8129
];
char
*
dir_end
;
int
i
=
strlen
(
datadir
);
size_t
dlen
=
strlen
(
datadir
);
int
i
;
assert
(
i
<
(
int
)
(
sizeof
(
buf
)
/
2
-
2
));
memcpy
(
buf
,
datadir
,
i
);
dir_end
=
buf
+
i
;
assert
(
dlen
<
(
sizeof
(
buf
)
/
2
-
2
));
memcpy
(
buf
,
datadir
,
dlen
);
dir_end
=
buf
+
dlen
;
*
dir_end
++
=
'/'
;
for
(
i
=
0
;
i
<
dlist
->
el_count
;
i
++
)
{
...
...
@@ -254,6 +255,35 @@ asn1c_save_streams(arg_t *arg, asn1c_fdeps_t *deps) {
return
0
;
}
/*
* Copy file for real.
*/
static
int
real_copy
(
const
char
*
src
,
const
char
*
dst
)
{
unsigned
char
buf
[
8192
];
FILE
*
fpsrc
,
*
fpdst
;
size_t
len
;
int
retval
=
0
;
fpsrc
=
fopen
(
src
,
"rb"
);
if
(
!
fpsrc
)
{
errno
=
EIO
;
return
-
1
;
}
fpdst
=
fopen
(
src
,
"wb"
);
if
(
!
fpdst
)
{
fclose
(
fpsrc
);
errno
=
EIO
;
return
-
1
;
}
while
(
!
feof
(
fpsrc
))
{
len
=
fread
(
buf
,
1
,
sizeof
(
buf
),
fpsrc
);
if
(
fwrite
(
buf
,
1
,
len
,
fpsrc
)
!=
len
)
{
errno
=
EIO
;
retval
=
-
1
;
break
;
}
}
fclose
(
fpsrc
);
fclose
(
fpdst
);
return
retval
;
}
static
int
asn1c_copy_over
(
arg_t
*
arg
,
char
*
path
)
{
char
*
fname
;
...
...
@@ -261,7 +291,13 @@ asn1c_copy_over(arg_t *arg, char *path) {
(
void
)
arg
;
/* Unused argument */
fname
=
a1c_basename
(
path
);
if
(
!
fname
||
symlink
(
path
,
fname
))
{
if
(
!
fname
#ifdef WIN32
||
real_copy
(
path
,
fname
)
#else
||
(
1
?
symlink
(
path
,
fname
)
:
real_copy
(
path
,
fname
))
#endif
)
{
if
(
errno
==
EEXIST
)
{
struct
stat
sb1
,
sb2
;
if
(
stat
(
path
,
&
sb1
)
==
0
...
...
libasn1fix/asn1fix.c
View file @
4efbfb7e
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdarg.h>
#include "asn1fix.h"
#include "asn1fix_internal.h"
#include "asn1fix.h"
/* Print everything to stderr */
static
void
_default_error_logger
(
int
_severity
,
const
char
*
fmt
,
...);
...
...
libasn1fix/asn1fix_constraint.c
View file @
4efbfb7e
#include
<
asn1fix_internal.h
>
#include
<
asn1fix_constraint.h
>
#include
<
asn1fix_crange.h
>
#include
"
asn1fix_internal.h
"
#include
"
asn1fix_constraint.h
"
#include
"
asn1fix_crange.h
"
static
void
_remove_exceptions
(
arg_t
*
arg
,
asn1p_constraint_t
*
ct
);
static
int
_constraint_value_resolve
(
arg_t
*
arg
,
asn1p_module_t
*
mod
,
asn1p_value_t
**
value
);
...
...
libasn1fix/asn1fix_constraint_compat.c
View file @
4efbfb7e
#include
<
asn1fix_internal.h
>
#include
<
asn1fix_crange.h
>
#include
"
asn1fix_internal.h
"
#include
"
asn1fix_crange.h
"
/*
* Check that a specific constraint is compatible
...
...
libasn1fix/asn1fix_crange.c
View file @
4efbfb7e
#include
<
asn1fix_internal.h
>
#include
<
asn1fix_constraint.h
>
#include
<
asn1fix_crange.h
>
#include
"
asn1fix_internal.h
"
#include
"
asn1fix_constraint.h
"
#include
"
asn1fix_crange.h
"
#undef FATAL
#define FATAL(fmt, args...) do { \
...
...
libasn1fix/asn1fix_cstring.c
View file @
4efbfb7e
...
...
@@ -2,7 +2,7 @@
struct
_cstring_pattern
{
char
*
start
;
in
t
length
;
size_
t
length
;
};
static
int
_asn1f_cstring_find_line_pattern
(
char
*
s
,
struct
_cstring_pattern
*
);
...
...
@@ -55,7 +55,7 @@ _asn1f_cstring_find_line_pattern(char *s, struct _cstring_pattern *cp) {
case
'\0'
:
default:
if
(
newline_found
)
{
cp
->
length
=
s
-
cp
->
start
;
cp
->
length
=
(
size_t
)(
s
-
cp
->
start
)
;
return
1
;
}
...
...
libasn1fix/asn1fix_export.h
View file @
4efbfb7e
...
...
@@ -5,7 +5,7 @@
#ifndef _ASN1FIX_EXPORT_H_
#define _ASN1FIX_EXPORT_H_
#include
<
asn1fix_tags.h
>
#include
"
asn1fix_tags.h
"
/*
* Create a human-readable representation of a reference and value.
...
...
libasn1fix/asn1fix_internal.h
View file @
4efbfb7e
...
...
@@ -10,13 +10,29 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
/* isupper() */
#include <errno.h>
#include <assert.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <asn1parser.h>
/* Our lovely ASN.1 parser module */
#include <asn1fix.h>
#include "asn1fix.h"
#ifdef WIN32
#define EX_NOINPUT 66
#define EX_DATAERR 65
#define snprintf _snprintf
#define strcasecmp stricmp
#endif
#ifndef ETOOMANYREFS
#define ETOOMANYREFS 144
#endif
/*
* A definition of a function that will log error messages.
...
...
libasn1fix/asn1fix_misc.c
View file @
4efbfb7e
...
...
@@ -19,11 +19,11 @@ char const *
asn1f_printable_value
(
asn1p_value_t
*
v
)
{
static
char
buf
[
128
];
static
char
*
managedptr
;
static
in
t
managedptr_len
;
static
size_
t
managedptr_len
;
int
ret
;
#define ENSURE(len) do { \
in
t __len = (len); \
size_
t __len = (len); \
if(__len >= managedptr_len) { \
if(managedptr) \
free(managedptr); \
...
...
@@ -69,7 +69,7 @@ asn1f_printable_value(asn1p_value_t *v) {
{
uint8_t
*
bitvector
;
char
*
ptr
;
in
t
len
;
size_
t
len
;
int
i
;
/*
* Compute number of bytes necessary
...
...
@@ -110,13 +110,13 @@ asn1f_printable_value(asn1p_value_t *v) {
*
ptr
++
=
'\''
;
*
ptr
++
=
(
bits
%
8
)
?
'B'
:
'H'
;
*
ptr
++
=
'H'
;
assert
((
ptr
-
managedptr
)
==
len
);
assert
(
len
==
(
size_t
)
(
ptr
-
managedptr
));
return
managedptr
;
}
case
ATV_REFERENCED
:
{
asn1p_ref_t
*
ref
;
char
reflen
;
size_t
reflen
;
char
*
ptr
;
int
i
;
...
...
@@ -141,7 +141,7 @@ asn1f_printable_value(asn1p_value_t *v) {
*
ptr
++
=
*
nc
;
}
*
ptr
++
=
'\0'
;
assert
(
reflen
==
(
ptr
-
managedptr
));
assert
(
reflen
==
(
size_t
)
(
ptr
-
managedptr
));
return
managedptr
;
}
case
ATV_CHOICE_IDENTIFIER
:
...
...
@@ -158,7 +158,7 @@ asn1f_printable_value(asn1p_value_t *v) {
ret
=
snprintf
(
managedptr
,
managedptr_len
+
1
,
"%s: %s"
,
cid
,
val
);
assert
(
ret
>=
0
&&
ret
<=
managedptr_len
);
assert
(
ret
>=
0
&&
(
size_t
)
ret
<=
managedptr_len
);
free
(
val
);
return
managedptr
;
}
...
...
libasn1fix/check_fixer.c
View file @
4efbfb7e
#undef NDEBUG
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "asn1fix_internal.h"
#ifdef WIN32
#include <io.h>
#include <direct.h>
#define chdir _chdir
#else
#include <dirent.h>
#include <errno.h>
#include <sysexits.h>
#endif
#include <errno.h>
#include "asn1fix.h"
#include "asn1fix_internal.h"
static
int
check
(
const
char
*
fname
,
enum
asn1p_flags
parser_flags
,
...
...
@@ -19,12 +21,19 @@ static int post_fix_check_element(asn1p_module_t *mod, asn1p_expr_t *expr);
int
main
(
int
ac
,
char
**
av
)
{
#ifdef WIN32
intptr_t
dir
;
struct
_finddata_t
c_file
;
#else
struct
dirent
*
dp
;
DIR
*
dir
;
#endif
int
failed
=
0
;
int
completed
=
0
;
enum
asn1p_flags
parser_flags
=
A1P_NOFLAGS
;
enum
asn1f_flags
fixer_flags
=
A1F_NOFLAGS
;
const
char
*
filename
;
int
len
;
int
ret
;
/*
...
...
@@ -44,8 +53,13 @@ main(int ac, char **av) {
fprintf
(
stderr
,
"Testing in ./tests...
\n
"
);
ret
=
chdir
(
"../tests"
);
assert
(
ret
==
0
);
#ifdef WIN32
dir
=
_findfirst
(
"*.asn1"
,
&
c_file
);
assert
(
dir
!=
-
1L
);
#else
dir
=
opendir
(
"."
);
assert
(
dir
);
#endif
/* WIN32 */
}
else
{
dir
=
0
;
}
...
...
@@ -54,21 +68,31 @@ main(int ac, char **av) {
* Scan every *.asn1 file and try to parse and fix it.
*/
if
(
dir
)
{
#ifdef WIN32
do
{
filename
=
c_file
.
name
;
#else
while
((
dp
=
readdir
(
dir
)))
{
int
len
=
strlen
(
dp
->
d_name
);
if
(
len
&&
strcmp
(
dp
->
d_name
+
len
-
5
,
".asn1"
)
==
0
)
{
ret
=
check
(
dp
->
d_name
,
parser_flags
,
fixer_flags
);
filename
=
dp
->
d_name
;
#endif
/* WIN32 */
int
len
=
strlen
(
filename
);
if
(
len
&&
strcmp
(
filename
+
len
-
5
,
".asn1"
)
==
0
)
{
ret
=
check
(
filename
,
parser_flags
,
fixer_flags
);
if
(
ret
)
{
fprintf
(
stderr
,
"FAILED: %s
\n
"
,
dp
->
d_name
);
fprintf
(
stderr
,
"FAILED: %s
\n
"
,
filename
);
failed
++
;
}
completed
++
;
}
#ifdef WIN32
}
while
(
_findnext
(
dir
,
&
c_file
)
==
0
);
_findclose
(
dir
);
#else
}
closedir
(
dir
);
#endif
/* WIN32 */
fprintf
(
stderr
,
"Tests COMPLETED: %d
\n
"
...
...
libasn1parser/Makefile.in
View file @
4efbfb7e
...
...
@@ -447,9 +447,9 @@ distclean-generic:
maintainer-clean-generic
:
@
echo
"This command is intended for maintainers to use"
@
echo
"it deletes files that may require special tools to rebuild."
-
rm
-f
asn1p_l.c
-
rm
-f
asn1p_y.c
-
rm
-f
asn1p_y.h
-
rm
-f
asn1p_l.c
clean
:
clean-am
clean-am
:
clean-generic clean-libtool clean-noinstLTLIBRARIES
\
...
...
libasn1parser/asn1p_expr2uclass.h
View file @
4efbfb7e
#ifndef ASN1_PARSER_EXPR2UCLASS_H
#define ASN1_PARSER_EXPR2UCLASS_H
#ifndef __GNUC__
#define __attribute__(x)
/* unused */
#endif
static
int
expr_type2uclass_value
[
ASN_EXPR_TYPE_MAX
]
__attribute__
((
unused
))
=
{
[
ASN_BASIC_BOOLEAN
]
=
1
,
...
...
libasn1parser/asn1p_expr_str.h
View file @
4efbfb7e
...
...
@@ -5,6 +5,10 @@
#ifndef ASN1_PARSER_EXPR_STR_H
#define ASN1_PARSER_EXPR_STR_H
#ifndef __GNUC__
#define __attribute__(x)
/* unused */
#endif
static
char
*
asn1p_expr_type2str
[]
__attribute__
((
unused
))
=
{
[
ASN_CONSTR_SEQUENCE
]
=
"SEQUENCE"
,
[
ASN_CONSTR_CHOICE
]
=
"CHOICE"
,
...
...
libasn1parser/asn1p_list.h
View file @
4efbfb7e
...
...
@@ -37,11 +37,11 @@
for((var) = TQ_FIRST((head)); \
(var); (var) = TQ_NEXT((var), field))
/* MSVC does not have typeof(), cannot prevent side effects! */
#define TQ_ADD(head, xel, field) do { \
typeof(xel) __el = xel; \
assert(TQ_NEXT((__el), field) == 0); \
*(head)->tq_tail = (__el); \
(head)->tq_tail = &TQ_NEXT((__el), field); \
assert(TQ_NEXT((xel), field) == 0); \
*(head)->tq_tail = (xel); \
(head)->tq_tail = &TQ_NEXT((xel), field); \
} while(0)
/*
...
...
Prev
1
2
Next
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