2 * Copyright (C) 2006-2009 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 */
19 #include "file_write.cmdline.h"
22 /** data specific to the file writer */
23 struct private_file_write_data
{
24 /** the file descriptor of the output file */
26 /** non-zero if \a fd was added to the write fd set */
30 static int file_write_open(struct writer_node
*wn
)
32 struct private_file_write_data
*pfwd
= para_calloc(
33 sizeof(struct private_file_write_data
));
34 struct file_write_args_info
*conf
= wn
->conf
;
36 if (conf
->filename_given
)
37 filename
= conf
->filename_arg
;
39 char *tmp
= para_tmpname(), *home
= para_homedir();
40 filename
= make_message("%s/.paraslash/%s", home
, tmp
);
44 wn
->private_data
= pfwd
;
45 pfwd
->fd
= open(filename
, O_WRONLY
| O_CREAT
, S_IRUSR
| S_IWUSR
);
46 if (!conf
->filename_given
)
54 static int file_write_pre_select(struct sched
*s
, struct writer_node
*wn
)
56 struct private_file_write_data
*pfwd
= wn
->private_data
;
57 struct writer_node_group
*wng
= wn
->wng
;
64 para_fd_set(pfwd
->fd
, &s
->wfds
, &s
->max_fileno
);
69 static int file_write_post_select(struct sched
*s
, struct writer_node
*wn
)
71 struct private_file_write_data
*pfwd
= wn
->private_data
;
72 struct writer_node_group
*wng
= wn
->wng
;
77 if (*wng
->loaded
<= wn
->written
)
79 if (!FD_ISSET(pfwd
->fd
, &s
->wfds
))
81 // PARA_INFO_LOG("writing %zd\n", *wng->loaded);
82 ret
= write(pfwd
->fd
, *wng
->bufp
+ wn
->written
,
83 *wng
->loaded
- wn
->written
);
90 static void file_write_close(struct writer_node
*wn
)
92 struct private_file_write_data
*pfwd
= wn
->private_data
;
97 __malloc
static void *file_write_parse_config(const char *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");
103 PARA_INFO_LOG("conf->filename_given: %d\n", conf
->filename_given
);
110 /** the init function of the file writer */
111 void file_write_init(struct writer
*w
)
113 struct file_write_args_info dummy
;
115 file_cmdline_parser_init(&dummy
);
116 w
->open
= file_write_open
;
117 w
->pre_select
= file_write_pre_select
;
118 w
->post_select
= file_write_post_select
;
119 w
->parse_config
= file_write_parse_config
;
120 w
->close
= file_write_close
;
121 w
->shutdown
= NULL
; /* nothing to do */
122 w
->help
= (struct ggo_help
) {
123 .short_help
= file_write_args_info_help
,
124 .detailed_help
= file_write_args_info_detailed_help
126 file_cmdline_parser_free(&dummy
);