-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.c
53 lines (45 loc) · 894 Bytes
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include "file.h"
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#define LINE_CNT 40000
int main (int argc, char **argv)
{
uint32_t n = LINE_CNT;
char *fpath = NULL;
int c;
int err;
FILE *fptr;
while ((c = getopt (argc, argv, "n:f:")) != -1)
{
switch (c)
{
case 'n':
n = (uint32_t)atoi(optarg);
break;
case 'f':
fpath = optarg;
break;
case '?':
if (isprint (optopt))fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
return 1;
default: abort ();
}
}
if ( fpath == NULL ){
fprintf(stderr, "Missing file path, option -f\n");
return 1;
}
// open file
fptr = fopen(fpath,"rb");
if ( fptr != NULL ){
err = read_bin_file(fptr, n);
fclose(fptr);
}else {
fprintf(stderr,"File open failed\n");
return 1;
}
return err;
}