Replace non-ANSI-C getline by fgets
This commit is contained in:
parent
0970559b97
commit
2316ad0815
1 changed files with 3 additions and 6 deletions
|
@ -122,9 +122,9 @@ int main(int argc, char *const argv[])
|
||||||
|
|
||||||
//File pointers for the keyfile
|
//File pointers for the keyfile
|
||||||
FILE * fp;
|
FILE * fp;
|
||||||
char * line = NULL;
|
char line[20];
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
ssize_t read;
|
char * read;
|
||||||
|
|
||||||
//Regexp declarations
|
//Regexp declarations
|
||||||
static const char *regex = "([0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f])";
|
static const char *regex = "([0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f])";
|
||||||
|
@ -157,9 +157,8 @@ int main(int argc, char *const argv[])
|
||||||
fprintf(stderr, "Cannot open keyfile: %s, exiting\n", optarg);
|
fprintf(stderr, "Cannot open keyfile: %s, exiting\n", optarg);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
while ((read = getline(&line, &len, fp)) != -1) {
|
while ((read = fgets(line, sizeof(line), fp)) != NULL) {
|
||||||
int i, j = 0, str_len = strlen(line);
|
int i, j = 0, str_len = strlen(line);
|
||||||
|
|
||||||
while (j < str_len &&
|
while (j < str_len &&
|
||||||
(i = slre_match(regex, line + j, str_len - j, caps, 500, 1)) > 0) {
|
(i = slre_match(regex, line + j, str_len - j, caps, 500, 1)) > 0) {
|
||||||
//We've found a key, let's add it to the structure.
|
//We've found a key, let's add it to the structure.
|
||||||
|
@ -177,8 +176,6 @@ int main(int argc, char *const argv[])
|
||||||
j += i;
|
j += i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (line)
|
|
||||||
free(line);
|
|
||||||
break;
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
// Add this key to the default keys
|
// Add this key to the default keys
|
||||||
|
|
Loading…
Reference in a new issue