Browse Source

* source/files : use 'flexible array' for init string in config struct

master
Alex 'AdUser' Z 3 months ago
parent
commit
d81fda45a7
  1. 20
      src/sources/files.c

20
src/sources/files.c

@ -32,7 +32,7 @@ struct _config {
f2b_file_t *current;
int flags;
bool missingok;
char path[256];
char path[];
};
#include "source.c"
@ -88,7 +88,7 @@ file_rotated(const cfg_t *cfg, f2b_file_t *file) {
return true;
if (stat(file->path, &st) != 0) {
log_msg(cfg, error, "file stat error: %s", strerror(errno));
log_msg(cfg, error, "stat(): %s -- %s", file->path, strerror(errno));
return true;
}
@ -130,15 +130,21 @@ file_getline(const cfg_t *cfg, f2b_file_t *file, char *buf, size_t bufsize) {
cfg_t *
create(const char *init) {
cfg_t *cfg = NULL;
if ((cfg = calloc(1, sizeof(cfg_t))) == NULL)
if (init == NULL) return NULL;
size_t ilen = strlen(init) + 1;
if (ilen <= 1) return NULL;
if ((cfg = calloc(1, sizeof(cfg_t) + ilen)) == NULL)
return NULL;
cfg->logcb = &logcb_stub;
cfg->flags |= MOD_TYPE_SOURCE;
cfg->flags |= MOD_NEED_FILTER;
if (init != NULL && strlen(init) > 0) {
strlcpy(cfg->path, init, sizeof(cfg->path));
cfg->logcb = &logcb_stub;
strlcpy(cfg->path, init, ilen);
cfg->flags |= MOD_IS_READY;
}
return cfg;
}

Loading…
Cancel
Save