X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fsfm-write.c;h=dcdab0b46d616dd6604adab4b33108fd69c80b5b;hb=92fb12eb06716d14c05b781f5d9dcde956d77c30;hp=bdde3cf642ee8982da2fb3b98273d51e09a261da;hpb=3417680e253b1bfc4519347ef06536378026be2a;p=pspp diff --git a/src/sfm-write.c b/src/sfm-write.c index bdde3cf642..dcdab0b46d 100644 --- a/src/sfm-write.c +++ b/src/sfm-write.c @@ -151,12 +151,12 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, mode = S_IRUSR | S_IRGRP | S_IROTH; if (opts.create_writeable) mode |= S_IWUSR | S_IWGRP | S_IWOTH; - fd = open (handle_get_filename (fh), O_WRONLY | O_CREAT | O_TRUNC, mode); + fd = open (fh_get_filename (fh), O_WRONLY | O_CREAT | O_TRUNC, mode); if (fd < 0) goto open_error; /* Open file handle. */ - if (!fh_open (fh, "system file", "we")) + if (!fh_open (fh, FH_REF_FILE, "system file", "we")) goto error; /* Create and initialize writer. */ @@ -173,7 +173,7 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, w->x = w->y = NULL; w->var_cnt = dict_get_var_cnt (d); - w->vars = xmalloc (sizeof *w->vars * w->var_cnt); + w->vars = xnmalloc (w->var_cnt, sizeof *w->vars); for (i = 0; i < w->var_cnt; i++) { const struct variable *dv = dict_get_var (d, i); @@ -242,7 +242,7 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, if (w->compress) { - w->buf = xmalloc (sizeof *w->buf * 128); + w->buf = xnmalloc (128, sizeof *w->buf); w->ptr = w->buf; w->end = &w->buf[128]; w->x = (unsigned char *) w->ptr++; @@ -257,7 +257,7 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, open_error: msg (ME, _("Error opening \"%s\" for writing as a system file: %s."), - handle_get_filename (w->fh), strerror (errno)); + fh_get_filename (fh), strerror (errno)); err_cond_fail (); goto error; } @@ -749,7 +749,7 @@ buf_write (struct sfm_writer *w, const void *buf, size_t nbytes) if (fwrite (buf, nbytes, 1, w->file) != 1) { msg (ME, _("%s: Writing system file: %s."), - handle_get_filename (w->fh), strerror (errno)); + fh_get_filename (w->fh), strerror (errno)); return 0; } return 1; @@ -788,7 +788,7 @@ static void write_compressed_data (struct sfm_writer *w, const flt64 *elem); /* Writes case C to system file W. Returns nonzero if successful. */ int -sfm_write_case (struct sfm_writer *w, struct ccase *c) +sfm_write_case (struct sfm_writer *w, const struct ccase *c) { w->case_cnt++; @@ -904,8 +904,6 @@ sfm_close_writer (struct sfm_writer *w) if (w == NULL) return; - fh_close (w->fh, "system file", "we"); - if (w->file != NULL) { /* Flush buffer. */ @@ -929,9 +927,11 @@ sfm_close_writer (struct sfm_writer *w) if (fclose (w->file) == EOF) msg (ME, _("%s: Closing system file: %s."), - handle_get_filename (w->fh), strerror (errno)); + fh_get_filename (w->fh), strerror (errno)); } + fh_close (w->fh, "system file", "we"); + free (w->buf); free (w->vars); free (w);