X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fpor-file-writer.c;h=f3a1101cf9801aeae0d90c7d8c36f0f33b178066;hb=e1fb96f07a06f3133f54702ed8706493989789fe;hp=27f7c5c4f57ef15879a6cd2d8e1b5de273593db8;hpb=a0f88151da33f2537632898156c32a7009178d50;p=pspp-builds.git diff --git a/src/data/por-file-writer.c b/src/data/por-file-writer.c index 27f7c5c4..f3a1101c 100644 --- a/src/data/por-file-writer.c +++ b/src/data/por-file-writer.c @@ -19,20 +19,19 @@ #include #include -#include #include #include #include #include #include #include -#include #include #include #include #include #include +#include #include #include #include @@ -109,30 +108,31 @@ pfm_open_writer (struct file_handle *fh, struct dictionary *dict, { struct pfm_writer *w = NULL; mode_t mode; - int fd; + FILE *file; size_t i; + /* Open file handle. */ + if (!fh_open (fh, FH_REF_FILE, "portable file", "we")) + return NULL; + /* Create file. */ mode = S_IRUSR | S_IRGRP | S_IROTH; if (opts.create_writeable) mode |= S_IWUSR | S_IWGRP | S_IWOTH; - fd = open (fh_get_file_name (fh), O_WRONLY | O_CREAT | O_TRUNC, mode); - if (fd < 0) - goto open_error; - - /* Open file handle. */ - if (!fh_open (fh, FH_REF_FILE, "portable file", "we")) - goto error; + file = create_stream (fh_get_file_name (fh), "w", mode); + if (file == NULL) + { + fh_close (fh, "portable file", "we"); + msg (ME, _("An error occurred while opening \"%s\" for writing " + "as a portable file: %s."), + fh_get_file_name (fh), strerror (errno)); + return NULL; + } /* Initialize data structures. */ w = xmalloc (sizeof *w); w->fh = fh; - w->file = fdopen (fd, "w"); - if (w->file == NULL) - { - close (fd); - goto open_error; - } + w->file = file; w->lc = 0; w->var_cnt = 0; @@ -165,19 +165,12 @@ pfm_open_writer (struct file_handle *fh, struct dictionary *dict, write_documents (w, dict); buf_write (w, "F", 1); if (ferror (w->file)) - goto error; + { + close_writer (w); + return NULL; + } return casewriter_create (dict_get_next_value_idx (dict), &por_file_casewriter_class, w); - - error: - close_writer (w); - return NULL; - - open_error: - msg (ME, _("An error occurred while opening \"%s\" for writing " - "as a portable file: %s."), - fh_get_file_name (fh), strerror (errno)); - goto error; } /* Write NBYTES starting at BUF to the portable file represented by