summaryrefslogtreecommitdiff
path: root/src/asn1Decoding.c
diff options
context:
space:
mode:
authorPawel Kowalski <p.kowalski2@partner.samsung.com>2019-08-28 14:31:23 +0200
committerPawel Kowalski <p.kowalski2@partner.samsung.com>2019-08-28 16:56:31 +0200
commitdee455252ad321c660b411b4ecd65aa5e08f8fc1 (patch)
treeb55f9ec039e963e42605e9e9bdc186354cf9df42 /src/asn1Decoding.c
parent5c7e0aaf17a296535495e3431db6a86ad64064b3 (diff)
parent26bea900a531662c6028ecc06f4adea825658434 (diff)
downloadlibtasn1-tizen_6.0_hotfix.tar.gz
libtasn1-tizen_6.0_hotfix.tar.bz2
libtasn1-tizen_6.0_hotfix.zip
Change-Id: I6d4b47b2072db8e7c45daa6e269e2f0cc6f54a7f
Diffstat (limited to 'src/asn1Decoding.c')
-rw-r--r--src/asn1Decoding.c56
1 files changed, 48 insertions, 8 deletions
diff --git a/src/asn1Decoding.c b/src/asn1Decoding.c
index 65456bf..b864768 100644
--- a/src/asn1Decoding.c
+++ b/src/asn1Decoding.c
@@ -25,14 +25,15 @@
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <libtasn1.h>
-#include <progname.h>
-#include <version-etc.h>
-#include <read-file.h>
#include "benchmark.h"
+#define program_name "asn1Decoding"
+
static int decode (asn1_node definitions, const char *typeName, void *der,
int der_len, int benchmark, int strict);
@@ -62,11 +63,51 @@ described in ASN.1 DEFINITIONS file, and print decoded structures.\n\
-t, --no-time-strict use strict DER decoding but not in time fields\n\
-h, --help display this help and exit\n\
-v, --version output version information and exit\n");
- emit_bug_reporting_address ();
+ printf ("Report bugs to "PACKAGE_BUGREPORT);
}
exit (status);
}
+static char *read_binary_file(const char *file, size_t *l)
+{
+ FILE *fp;
+ struct stat st;
+ char *out;
+
+ if (stat(file, &st) == -1)
+ {
+ fprintf(stderr, "Error reading file size!\n");
+ exit(1);
+ }
+
+ fp = fopen(file, "rb");
+ if (fp == NULL)
+ {
+ fprintf(stderr, "Error reading file!\n");
+ exit(1);
+ }
+
+ out = malloc(st.st_size+1);
+ if (out == NULL)
+ {
+ fprintf(stderr, "Memory error!\n");
+ exit(1);
+ }
+
+ *l = fread(out, 1, st.st_size, fp);
+ if (*l != st.st_size)
+ {
+ fprintf(stderr, "Error reading contents (got: %ld, expected %ld)!\n",
+ (long)*l, (long)st.st_size);
+ exit(1);
+ }
+
+ out[*l] = 0;
+
+ fclose(fp);
+ return out;
+}
+
int
main (int argc, char *argv[])
{
@@ -92,8 +133,6 @@ main (int argc, char *argv[])
int flags = 0, debug = 0;
/* FILE *outputFile; */
- set_program_name (argv[0]);
-
opterr = 0; /* disable error messages from getopt */
while (1)
@@ -123,8 +162,9 @@ main (int argc, char *argv[])
flags |= ASN1_DECODE_FLAG_ALLOW_INCORRECT_TIME;
break;
case 'v': /* VERSION */
- version_etc (stdout, program_name, PACKAGE, VERSION,
- "Fabio Fiorina", NULL);
+ printf(program_name" "PACKAGE" " VERSION"\n");
+ printf("Copyright (C) 2017-2019 Free Software Foundation, Inc.\n\n");
+ printf("Written by Fabio Fiorina\n");
exit (0);
break;
case '?': /* UNKNOW OPTION */