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 */
18 #include "file_write.cmdline.h"
21 /** data specific to the file writer */
22 struct private_file_write_data
{
23 /** the file descriptor of the output file */
25 /** non-zero if \a fd was added to the write fd set */
29 static int file_write_open(struct writer_node
*wn
)
31 struct private_file_write_data
*pfwd
= para_calloc(
32 sizeof(struct private_file_write_data
));
33 struct file_write_args_info
*conf
= wn
->conf
;
35 if (conf
->filename_given
)
36 filename
= conf
->filename_arg
;
38 char *tmp
= para_tmpname(), *home
= para_homedir();
39 filename
= make_message("%s/.paraslash/%s", home
, tmp
);
43 wn
->private_data
= pfwd
;
44 pfwd
->fd
= open(filename
, O_WRONLY
| O_CREAT
, S_IRUSR
| S_IWUSR
);
45 if (!conf
->filename_given
)
53 static int file_write_pre_select(struct sched
*s
, struct writer_node
*wn
)
55 struct private_file_write_data
*pfwd
= wn
->private_data
;
56 struct writer_node_group
*wng
= wn
->wng
;
63 para_fd_set(pfwd
->fd
, &s
->wfds
, &s
->max_fileno
);
68 static int file_write_post_select(struct sched
*s
, struct writer_node
*wn
)
70 struct private_file_write_data
*pfwd
= wn
->private_data
;
71 struct writer_node_group
*wng
= wn
->wng
;
76 if (*wng
->loaded
<= wn
->written
)
78 if (!FD_ISSET(pfwd
->fd
, &s
->wfds
))
80 // PARA_INFO_LOG("writing %zd\n", *wng->loaded);
81 ret
= write(pfwd
->fd
, wng
->buf
+ wn
->written
,
82 *wng
->loaded
- wn
->written
);
89 static void file_write_close(struct writer_node
*wn
)
91 struct private_file_write_data
*pfwd
= wn
->private_data
;
96 __malloc
static void *file_write_parse_config(const char *options
)
98 PARA_INFO_LOG("options: %s\n", options
);
99 struct file_write_args_info
*conf
100 = para_calloc(sizeof(struct file_write_args_info
));
101 int ret
= file_cmdline_parser_string(options
, conf
, "file_write");
102 PARA_INFO_LOG("conf->filename_given: %d\n", conf
->filename_given
);
109 /** the init function of the file writer */
110 void file_write_init(struct writer
*w
)
112 w
->open
= file_write_open
;
113 w
->pre_select
= file_write_pre_select
;
114 w
->post_select
= file_write_post_select
;
115 w
->parse_config
= file_write_parse_config
;
116 w
->close
= file_write_close
;
117 w
->shutdown
= NULL
; /* nothing to do */