Files
adsb-tools/adsbus/file.c

38 lines
1010 B
C
Raw Normal View History

2016-02-29 20:49:36 -08:00
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "flow.h"
#include "receive.h"
#include "send.h"
#include "file.h"
2016-03-02 13:16:18 -08:00
static void file_open_new(char *path, struct flow *flow, void *passthrough, int flags) {
int fd = open(path, flags | O_CLOEXEC, S_IRUSR | S_IWUSR);
if (fd == -1) {
// TODO: log error; retry?
return;
}
file_fd_new(fd, flow, passthrough);
}
2016-02-29 20:49:36 -08:00
void file_fd_new(int fd, struct flow *flow, void *passthrough) {
flow->new(fd, passthrough, NULL);
// TODO: log error; retry?
flow_hello(fd, flow, passthrough);
}
void file_read_new(char *path, struct flow *flow, void *passthrough) {
2016-03-02 13:16:18 -08:00
file_open_new(path, flow, passthrough, O_RDONLY);
2016-02-29 20:49:36 -08:00
}
void file_write_new(char *path, struct flow *flow, void *passthrough) {
2016-03-02 13:16:18 -08:00
file_open_new(path, flow, passthrough, O_WRONLY | O_CREAT | O_NOFOLLOW | O_TRUNC);
2016-02-29 20:49:36 -08:00
}
void file_append_new(char *path, struct flow *flow, void *passthrough) {
2016-03-02 13:16:18 -08:00
file_open_new(path, flow, passthrough, O_WRONLY | O_CREAT | O_NOFOLLOW);
2016-02-29 20:49:36 -08:00
}