2 * Copyright (C) 2006-2007 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file file_write.c simple output plugin for testing purposes */
15 #include "file_write.cmdline.h"
18 /** data specific to the file writer */
19 struct private_file_write_data {
20 /** the file descriptor of the output file */
22 /** non-zero if \a fd was added to the write fd set */
26 static int file_write_open(struct writer_node *wn)
28 struct private_file_write_data *pfwd = para_calloc(
29 sizeof(struct private_file_write_data));
30 struct file_write_args_info *conf = wn->conf;
32 if (conf->filename_given)
33 filename = conf->filename_arg;
35 char *tmp = para_tmpname(), *home = para_homedir();
36 filename = make_message("%s/.paraslash/%s", home, tmp);
40 wn->private_data = pfwd;
41 pfwd->fd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
42 if (!conf->filename_given)
50 static int file_write_pre_select(struct sched *s, struct writer_node *wn)
52 struct private_file_write_data *pfwd = wn->private_data;
53 struct writer_node_group *wng = wn->wng;
60 para_fd_set(pfwd->fd, &s->wfds, &s->max_fileno);
65 static int file_write_post_select(struct sched *s, struct writer_node *wn)
67 struct private_file_write_data *pfwd = wn->private_data;
68 struct writer_node_group *wng = wn->wng;
73 if (*wng->loaded <= wn->written)
75 if (!FD_ISSET(pfwd->fd, &s->wfds))
77 // PARA_INFO_LOG("writing %zd\n", *wng->loaded);
78 ret = write(pfwd->fd, wng->buf + wn->written,
79 *wng->loaded - wn->written);
86 static void file_write_close(struct writer_node *wn)
88 struct private_file_write_data *pfwd = wn->private_data;
93 __malloc static void *file_write_parse_config(const char *options)
95 PARA_INFO_LOG("options: %s\n", options);
96 struct file_write_args_info *conf
97 = para_calloc(sizeof(struct file_write_args_info));
98 int ret = file_cmdline_parser_string(options, conf, "file_write");
99 PARA_INFO_LOG("conf->filename_given: %d\n", conf->filename_given);
106 /** the init function of the file writer */
107 void file_write_init(struct writer *w)
109 w->open = file_write_open;
110 w->pre_select = file_write_pre_select;
111 w->post_select = file_write_post_select;
112 w->parse_config = file_write_parse_config;
113 w->close = file_write_close;
114 w->shutdown = NULL; /* nothing to do */