summaryrefslogtreecommitdiff
path: root/src/rost.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2023-10-22 12:21:44 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2023-10-22 12:21:44 (GMT)
commit98dab5148243637a4f2d19a7c44b0e643a0e0f8c (patch)
treeaa5f22f47e01f5ff7f2e0239cae9949ab6354ac9 /src/rost.c
parentc370bb014b20654a2b7351b2a9d7e1e5a3ce92cc (diff)
Provide the size of a rule without recomputing it.
Diffstat (limited to 'src/rost.c')
-rw-r--r--src/rost.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/rost.c b/src/rost.c
index 1bcca6b..e9a7ccb 100644
--- a/src/rost.c
+++ b/src/rost.c
@@ -34,7 +34,6 @@
#include <i18n.h>
-
#include "gleak.h"
#include "analysis/contents/file.h"
#include "analysis/scan/options.h"
@@ -56,7 +55,7 @@ static void show_rost_help(const char *);
static void show_rost_version(void);
/* Récupère un contenu à traiter depuis l'entrée standard. */
-static void *get_input_data_from_stdin(void);
+static void *get_input_data_from_stdin(size_t *);
@@ -150,7 +149,7 @@ static void show_rost_version(void)
/******************************************************************************
* *
-* Paramètres : - *
+* Paramètres : length = taille de la définition lue. [OUT] *
* *
* Description : Récupère un contenu à traiter depuis l'entrée standard. *
* *
@@ -160,23 +159,22 @@ static void show_rost_version(void)
* *
******************************************************************************/
-static void *get_input_data_from_stdin(void)
+static void *get_input_data_from_stdin(size_t *length)
{
char *result; /* Espace mémoire à retourner */
- size_t length; /* Taille de ce contenu */
ssize_t got; /* Quantité d'octets lus */
result = NULL;
- length = 0;
+ *length = 0;
#define ALLOC_SIZE 2048
while (true)
{
- result = realloc(result, (length + ALLOC_SIZE) * sizeof(char));
+ result = realloc(result, (*length + ALLOC_SIZE) * sizeof(char));
- got = read(STDIN_FILENO, result + length, ALLOC_SIZE);
+ got = read(STDIN_FILENO, result + *length, ALLOC_SIZE);
if (got == -1)
{
@@ -184,7 +182,7 @@ static void *get_input_data_from_stdin(void)
goto exit_with_error;
}
- length += got;
+ *length += got;
if (got < ALLOC_SIZE)
break;
@@ -228,6 +226,7 @@ int main(int argc, char **argv)
char *edir; /* Répertoire de base effectif */
char *rules; /* Définition de règles */
char *target; /* Cible communiquée */
+ size_t rule_length; /* Taille d'un contenu */
void *rule_content; /* Contenu à traduire */
GContentScanner *scanner; /* Encadrement d'une recherche */
GBinContent *content; /* Contenu à analyser */
@@ -407,11 +406,11 @@ int main(int argc, char **argv)
if (rules == NULL)
{
- rule_content = get_input_data_from_stdin();
+ rule_content = get_input_data_from_stdin(&rule_length);
if (rule_content != NULL)
{
- scanner = g_content_scanner_new_from_text(rule_content);
+ scanner = g_content_scanner_new_from_text(rule_content, rule_length);
free(rule_content);
}
else