- struct file_write_args_info *conf = wn->conf;
- char *filename;
- int ret;
- struct private_file_write_data *pfwd = para_calloc(sizeof(*pfwd));
-
- if (conf->filename_given)
- filename = conf->filename_arg;
- else
- filename = random_filename();
- ret = para_open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
- if (!conf->filename_given)
- free(filename);
- if (ret < 0)
- goto out;
- pfwd->fd = ret;
- ret = mark_fd_blocking(pfwd->fd);
+ const unsigned flags = O_WRONLY | O_CREAT, mode = S_IRUSR | S_IWUSR;
+ int ret, fd;
+ struct private_file_write_data *pfwd;
+
+
+ if (WRITE_CMD_OPT_GIVEN(FILE, FILENAME, wn->lpr)) {
+ const char *path = WRITE_CMD_OPT_STRING_VAL(FILE, FILENAME,
+ wn->lpr);
+ ret = para_open(path, flags, mode);
+ } else {
+ char *path = random_filename();
+ ret = para_open(path, flags, mode);
+ free(path);
+ }