- fname_len = strlen(p) + strlen(path) + 2;
- fname = alloca(fname_len);
- snprintf(fname, fname_len, "%s/%s", path, p);
+ snprintf(args->output_file, PATH_MAX, "%s/%s", path, p);
free(p);
} else {
/* The declaration filename does not follow the
convention, so we will not use it as a template.
We just generate a filename using "$CPF.REC". */
free(p);
} else {
/* The declaration filename does not follow the
convention, so we will not use it as a template.
We just generate a filename using "$CPF.REC". */
- fname_len = strlen(cpf) + strlen(path) + sizeof(".REC") + 2;
- fname = alloca(fname_len);
- snprintf(fname, fname_len, "%s/%s.REC", path, cpf);
+ snprintf(args->output_file, PATH_MAX, "%s/%s.REC", path, cpf);
- fprintf(stderr, "Could not create receipt file \"%s\": %s\n", fname, strerror(errno));
- return;
+ fprintf(stderr, "Could not create receipt file \"%s\": %s\n",
+ args->output_file, strerror(errno));
do {
r = write(fd, buffer, len);
} while (r < 0 && errno == EAGAIN);
do {
r = write(fd, buffer, len);
} while (r < 0 && errno == EAGAIN);
- if (r != len)
- fprintf(stderr, "Could not write to receipt file: %s", strerror(errno));
- else
- fprintf(stderr, "Wrote the receipt file to %s.\n", fname);
- close(fd);
+ if (r != len) {
+ fprintf(stderr, "Could not write to receipt file: %s",
+ strerror(errno));
+ } else {
+ fprintf(stderr, "Wrote the receipt file to %s.\n",
+ args->output_file);
+ }
+ return r;
-static void handle_response_text_and_file(char *cpf, struct rnet_message *message, const struct rnetclient_args *args)
+static void handle_response_text_and_file(int fd, struct rnet_message *message, const struct rnetclient_args *args)
{
char *value;
int vlen;
if (!rnet_message_parse(message, "texto", &value, &vlen))
fprintf(stderr, "%.*s\n", vlen, value);
if (!rnet_message_parse(message, "arquivo", &value, &vlen))
{
char *value;
int vlen;
if (!rnet_message_parse(message, "texto", &value, &vlen))
fprintf(stderr, "%.*s\n", vlen, value);
if (!rnet_message_parse(message, "arquivo", &value, &vlen))
- save_rec_file(cpf, value, vlen, args);
+ save_rec_file(fd, value, vlen, args);
-static void handle_response_already_found(char *cpf, struct rnet_message *message, const struct rnetclient_args *args)
+static void handle_response_already_found(int fd, struct rnet_message *message, const struct rnetclient_args *args)
/* Parsing the command line arguments. The argp_parse
function calls exit() if there is some error during the
/* Parsing the command line arguments. The argp_parse
function calls exit() if there is some error during the