MCPcopy Create free account
hub / github.com/F-Stack/f-stack / cli_script_process

Function cli_script_process

dpdk/app/graph/cli.c:94–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94int
95cli_script_process(const char *file_name, size_t msg_in_len_max, size_t msg_out_len_max, void *obj)
96{
97 char *msg_in = NULL, *msg_out = NULL;
98 int rc = -EINVAL;
99 FILE *f = NULL;
100
101 /* Check input arguments */
102 if ((file_name == NULL) || (strlen(file_name) == 0) || (msg_in_len_max == 0) ||
103 (msg_out_len_max == 0))
104 return rc;
105
106 msg_in = malloc(msg_in_len_max + 1);
107 msg_out = malloc(msg_out_len_max + 1);
108 if ((msg_in == NULL) || (msg_out == NULL)) {
109 rc = -ENOMEM;
110 goto exit;
111 }
112
113 /* Open input file */
114 f = fopen(file_name, "r");
115 if (f == NULL) {
116 rc = -EIO;
117 goto exit;
118 }
119
120 /* Read file */
121 while (fgets(msg_in, msg_in_len_max, f) != NULL) {
122 msg_out[0] = 0;
123
124 cli_process(msg_in, msg_out, msg_out_len_max, obj);
125
126 if (strlen(msg_out))
127 printf("%s", msg_out);
128 }
129
130 /* Close file */
131 fclose(f);
132 rc = 0;
133
134exit:
135 free(msg_out);
136 free(msg_in);
137 return rc;
138}

Callers 1

mainFunction · 0.70

Calls 4

mallocFunction · 0.85
cli_processFunction · 0.70
printfFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected