#include "xmalloc.h"
#include "mlmmj.h"
#include "send_list.h"
-#include "strgen.h"
#include "log_error.h"
#include "chomp.h"
#include "mygetline.h"
static const char *get_sub(void *state)
{
subs_list_state *s = (subs_list_state *)state;
- char *filename;
struct dirent *dp;
+ int fd;
if (s == NULL) return NULL;
if (s->dirp == NULL) return NULL;
+ fd = open(s->dirname, O_DIRECTORY);
+ if (fd == -1) return NULL;
if (s->line != NULL) {
free(s->line);
if (dp == NULL) {
closedir(s->dirp);
s->dirp = NULL;
+ close(fd);
return NULL;
}
if ((strcmp(dp->d_name, "..") == 0) ||
(strcmp(dp->d_name, ".") == 0))
continue;
- filename = concatstr(2, s->dirname, dp->d_name);
- s->fd = open(filename, O_RDONLY);
+ s->fd = openat(fd, dp->d_name, O_RDONLY);
if(s->fd < 0) {
log_error(LOG_ARGS,
- "Could not open %s for reading",
- filename);
- free(filename);
+ "Could not open %s/%s for reading",
+ s->dirname, dp->d_name);
continue;
}
- free(filename);
}
s->line = mygetline(s->fd);
if (s->line == NULL) {
continue;
}
chomp(s->line);
+ close(fd);
return s->line;
}
}