From 4efbfb7e5553b41f4d725479823705aa6ef073cc Mon Sep 17 00:00:00 2001 From: Lev Walkin Date: Fri, 25 Feb 2005 14:20:30 +0000 Subject: portability fixes --- libasn1fix/asn1fix.c | 7 +---- libasn1fix/asn1fix_constraint.c | 6 ++-- libasn1fix/asn1fix_constraint_compat.c | 4 +-- libasn1fix/asn1fix_crange.c | 6 ++-- libasn1fix/asn1fix_cstring.c | 4 +-- libasn1fix/asn1fix_export.h | 2 +- libasn1fix/asn1fix_internal.h | 18 +++++++++++- libasn1fix/asn1fix_misc.c | 14 ++++----- libasn1fix/check_fixer.c | 52 +++++++++++++++++++++++++--------- 9 files changed, 74 insertions(+), 39 deletions(-) (limited to 'libasn1fix') diff --git a/libasn1fix/asn1fix.c b/libasn1fix/asn1fix.c index f120853c..22cd3671 100644 --- a/libasn1fix/asn1fix.c +++ b/libasn1fix/asn1fix.c @@ -1,10 +1,5 @@ -#include -#include -#include -#include - -#include "asn1fix.h" #include "asn1fix_internal.h" +#include "asn1fix.h" /* Print everything to stderr */ static void _default_error_logger(int _severity, const char *fmt, ...); diff --git a/libasn1fix/asn1fix_constraint.c b/libasn1fix/asn1fix_constraint.c index 8c6c73ca..9a32b49f 100644 --- a/libasn1fix/asn1fix_constraint.c +++ b/libasn1fix/asn1fix_constraint.c @@ -1,6 +1,6 @@ -#include -#include -#include +#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); diff --git a/libasn1fix/asn1fix_constraint_compat.c b/libasn1fix/asn1fix_constraint_compat.c index effa0ad5..5eb93f0b 100644 --- a/libasn1fix/asn1fix_constraint_compat.c +++ b/libasn1fix/asn1fix_constraint_compat.c @@ -1,5 +1,5 @@ -#include -#include +#include "asn1fix_internal.h" +#include "asn1fix_crange.h" /* * Check that a specific constraint is compatible diff --git a/libasn1fix/asn1fix_crange.c b/libasn1fix/asn1fix_crange.c index 974aa21c..1e6a0d08 100644 --- a/libasn1fix/asn1fix_crange.c +++ b/libasn1fix/asn1fix_crange.c @@ -1,6 +1,6 @@ -#include -#include -#include +#include "asn1fix_internal.h" +#include "asn1fix_constraint.h" +#include "asn1fix_crange.h" #undef FATAL #define FATAL(fmt, args...) do { \ diff --git a/libasn1fix/asn1fix_cstring.c b/libasn1fix/asn1fix_cstring.c index b8a38833..9cbb42cf 100644 --- a/libasn1fix/asn1fix_cstring.c +++ b/libasn1fix/asn1fix_cstring.c @@ -2,7 +2,7 @@ struct _cstring_pattern { char *start; - int 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; } diff --git a/libasn1fix/asn1fix_export.h b/libasn1fix/asn1fix_export.h index 5879b93f..99d80b71 100644 --- a/libasn1fix/asn1fix_export.h +++ b/libasn1fix/asn1fix_export.h @@ -5,7 +5,7 @@ #ifndef _ASN1FIX_EXPORT_H_ #define _ASN1FIX_EXPORT_H_ -#include +#include "asn1fix_tags.h" /* * Create a human-readable representation of a reference and value. diff --git a/libasn1fix/asn1fix_internal.h b/libasn1fix/asn1fix_internal.h index 040750df..6b157785 100644 --- a/libasn1fix/asn1fix_internal.h +++ b/libasn1fix/asn1fix_internal.h @@ -10,13 +10,29 @@ */ #include #include +#include #include #include /* isupper() */ #include #include +#ifdef HAVE_UNISTD_H +#include +#endif + #include /* Our lovely ASN.1 parser module */ -#include +#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. diff --git a/libasn1fix/asn1fix_misc.c b/libasn1fix/asn1fix_misc.c index e9d156ce..15a16860 100644 --- a/libasn1fix/asn1fix_misc.c +++ b/libasn1fix/asn1fix_misc.c @@ -19,11 +19,11 @@ char const * asn1f_printable_value(asn1p_value_t *v) { static char buf[128]; static char *managedptr; - static int managedptr_len; + static size_t managedptr_len; int ret; #define ENSURE(len) do { \ - int __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; - int 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; } diff --git a/libasn1fix/check_fixer.c b/libasn1fix/check_fixer.c index 7129a563..8808f28d 100644 --- a/libasn1fix/check_fixer.c +++ b/libasn1fix/check_fixer.c @@ -1,15 +1,17 @@ #undef NDEBUG -#include -#include -#include -#include -#include +#include "asn1fix_internal.h" + +#ifdef WIN32 +#include +#include +#define chdir _chdir +#else #include -#include #include +#endif +#include #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" -- cgit v1.2.3