1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include "sys-file-writer.h"
23 #include "sfm-private.h"
33 #include <libpspp/alloc.h>
34 #include <libpspp/hash.h>
35 #include <libpspp/magic.h>
36 #include <libpspp/message.h>
37 #include <libpspp/misc.h>
38 #include <libpspp/str.h>
39 #include <libpspp/version.h>
42 #include "dictionary.h"
43 #include "file-handle-def.h"
45 #include "value-labels.h"
48 #include "stat-macros.h"
52 #define _(msgid) gettext (msgid)
54 /* Compression bias used by PSPP. Values between (1 -
55 COMPRESSION_BIAS) and (251 - COMPRESSION_BIAS) inclusive can be
57 #define COMPRESSION_BIAS 100
59 /* System file writer. */
62 struct file_handle *fh; /* File handle. */
63 FILE *file; /* File stream. */
65 int needs_translation; /* 0=use fast path, 1=translation needed. */
66 int compress; /* 1=compressed, 0=not compressed. */
67 int case_cnt; /* Number of cases written so far. */
68 size_t flt64_cnt; /* Number of flt64 elements in case. */
69 bool has_vls; /* Does the dict have very long strings? */
71 /* Compression buffering. */
72 flt64 *buf; /* Buffered data. */
73 flt64 *end; /* Buffer end. */
74 flt64 *ptr; /* Current location in buffer. */
75 unsigned char *x; /* Location in current instruction octet. */
76 unsigned char *y; /* End of instruction octet. */
79 struct sfm_var *vars; /* Variables. */
80 size_t var_cnt; /* Number of variables. */
81 size_t var_cnt_vls; /* Number of variables including
82 very long string components. */
85 /* A variable in a system file. */
88 int width; /* 0=numeric, otherwise string width. */
89 int fv; /* Index into case. */
90 size_t flt64_cnt; /* Number of flt64 elements. */
93 static char *append_string_max (char *, const char *, const char *);
94 static void write_header (struct sfm_writer *, const struct dictionary *);
95 static void buf_write (struct sfm_writer *, const void *, size_t);
96 static void write_variable (struct sfm_writer *, const struct variable *);
97 static void write_value_labels (struct sfm_writer *,
98 struct variable *, int idx);
99 static void write_rec_7_34 (struct sfm_writer *);
101 static void write_longvar_table (struct sfm_writer *w,
102 const struct dictionary *dict);
104 static void write_vls_length_table (struct sfm_writer *w,
105 const struct dictionary *dict);
108 static void write_variable_display_parameters (struct sfm_writer *w,
109 const struct dictionary *dict);
111 static void write_documents (struct sfm_writer *, const struct dictionary *);
114 var_flt64_cnt (const struct variable *v)
116 assert(sizeof(flt64) == MAX_SHORT_STRING);
117 return width_to_bytes(v->width) / MAX_SHORT_STRING ;
121 var_flt64_cnt_nom (const struct variable *v)
123 return v->type == NUMERIC ? 1 : DIV_RND_UP (v->width, sizeof (flt64));
127 /* Returns default options for writing a system file. */
128 struct sfm_write_options
129 sfm_writer_default_options (void)
131 struct sfm_write_options opts;
132 opts.create_writeable = true;
133 opts.compress = get_scompression ();
139 /* Return a short variable name to be used as the continuation of the
140 variable with the short name SN.
142 FIXME: Need to resolve clashes somehow.
146 cont_var_name(const char *sn, int idx)
148 static char s[SHORT_NAME_LEN + 1];
150 char abb[SHORT_NAME_LEN + 1 - 3]= {0};
152 strncpy(abb, sn, SHORT_NAME_LEN - 3);
154 snprintf(s, SHORT_NAME_LEN + 1, "%s%03d", abb, idx);
160 /* Opens the system file designated by file handle FH for writing
161 cases from dictionary D according to the given OPTS. If
162 COMPRESS is nonzero, the system file will be compressed.
164 No reference to D is retained, so it may be modified or
165 destroyed at will after this function returns. D is not
166 modified by this function, except to assign short names. */
168 sfm_open_writer (struct file_handle *fh, struct dictionary *d,
169 struct sfm_write_options opts)
171 struct sfm_writer *w = NULL;
178 if (opts.version != 2 && opts.version != 3)
180 msg (ME, _("Unknown system file version %d. Treating as version %d."),
186 mode = S_IRUSR | S_IRGRP | S_IROTH;
187 if (opts.create_writeable)
188 mode |= S_IWUSR | S_IWGRP | S_IWOTH;
189 fd = open (fh_get_file_name (fh), O_WRONLY | O_CREAT | O_TRUNC, mode);
193 /* Open file handle. */
194 if (!fh_open (fh, FH_REF_FILE, "system file", "we"))
197 /* Create and initialize writer. */
198 w = xmalloc (sizeof *w);
200 w->file = fdopen (fd, "w");
202 w->needs_translation = dict_compacting_would_change (d);
203 w->compress = opts.compress;
208 w->buf = w->end = w->ptr = NULL;
211 w->var_cnt = dict_get_var_cnt (d);
212 w->var_cnt_vls = w->var_cnt;
213 w->vars = xnmalloc (w->var_cnt, sizeof *w->vars);
214 for (i = 0; i < w->var_cnt; i++)
216 const struct variable *dv = dict_get_var (d, i);
217 struct sfm_var *sv = &w->vars[i];
218 sv->width = dv->width;
219 /* spss compatibility nonsense */
220 if ( dv->width > MAX_LONG_STRING )
224 sv->flt64_cnt = var_flt64_cnt (dv);
227 /* Check that file create succeeded. */
234 /* Write the file header. */
237 /* Write basic variable info. */
238 dict_assign_short_names (d);
239 for (i = 0; i < dict_get_var_cnt (d); i++)
242 const struct variable *v = dict_get_var(d, i);
243 int wcount = v->width;
246 struct variable var_cont = *v;
247 if ( v->type == ALPHA)
251 mv_init(&var_cont.miss, 0);
252 strcpy(var_cont.short_name,
253 cont_var_name(v->short_name, count));
254 var_cont.label = NULL;
258 if ( wcount > MAX_LONG_STRING )
260 var_cont.width = MAX_LONG_STRING;
261 wcount -= EFFECTIVE_LONG_STRING_LENGTH;
265 var_cont.width = wcount;
266 wcount -= var_cont.width;
269 var_cont.write.w = var_cont.width;
270 var_cont.print.w = var_cont.width;
273 write_variable (w, &var_cont);
277 /* Write out value labels. */
278 for (idx = i = 0; i < dict_get_var_cnt (d); i++)
280 struct variable *v = dict_get_var (d, i);
282 write_value_labels (w, v, idx);
283 idx += var_flt64_cnt (v);
286 if (dict_get_documents (d) != NULL)
287 write_documents (w, d);
291 write_variable_display_parameters (w, d);
293 if (opts.version >= 3)
294 write_longvar_table (w, d);
296 write_vls_length_table(w, d);
298 /* Write end-of-headers record. */
304 } ATTRIBUTE((packed))
307 rec_999.rec_type = 999;
310 buf_write (w, &rec_999, sizeof rec_999);
315 w->buf = xnmalloc (128, sizeof *w->buf);
317 w->end = &w->buf[128];
318 w->x = (unsigned char *) w->ptr++;
319 w->y = (unsigned char *) w->ptr;
322 if (sfm_write_error (w))
328 sfm_close_writer (w);
332 msg (ME, _("Error opening \"%s\" for writing as a system file: %s."),
333 fh_get_file_name (fh), strerror (errno));
337 /* Returns value of X truncated to two least-significant digits. */
348 /* Write the sysfile_header header to system file W. */
350 write_header (struct sfm_writer *w, const struct dictionary *d)
352 struct sysfile_header hdr;
358 memcpy (hdr.rec_type, "$FL2", 4);
360 p = stpcpy (hdr.prod_name, "@(#) SPSS DATA FILE ");
361 p = append_string_max (p, version, &hdr.prod_name[60]);
362 p = append_string_max (p, " - ", &hdr.prod_name[60]);
363 p = append_string_max (p, host_system, &hdr.prod_name[60]);
364 memset (p, ' ', &hdr.prod_name[60] - p);
369 for (i = 0; i < dict_get_var_cnt (d); i++)
371 w->flt64_cnt += var_flt64_cnt (dict_get_var (d, i));
373 hdr.nominal_case_size = w->flt64_cnt;
375 hdr.compress = w->compress;
377 if (dict_get_weight (d) != NULL)
379 const struct variable *weight_var;
380 int recalc_weight_idx = 1;
383 weight_var = dict_get_weight (d);
386 struct variable *v = dict_get_var (d, i);
389 recalc_weight_idx += var_flt64_cnt (v);
391 hdr.weight_idx = recalc_weight_idx;
397 hdr.bias = COMPRESSION_BIAS;
399 if (time (&t) == (time_t) -1)
401 memcpy (hdr.creation_date, "01 Jan 70", 9);
402 memcpy (hdr.creation_time, "00:00:00", 8);
406 static const char *month_name[12] =
408 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
409 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
411 struct tm *tmp = localtime (&t);
412 int day = rerange (tmp->tm_mday);
413 int mon = rerange (tmp->tm_mon + 1);
414 int year = rerange (tmp->tm_year);
415 int hour = rerange (tmp->tm_hour + 1);
416 int min = rerange (tmp->tm_min + 1);
417 int sec = rerange (tmp->tm_sec + 1);
420 sprintf (buf, "%02d %s %02d", day, month_name[mon - 1], year);
421 memcpy (hdr.creation_date, buf, sizeof hdr.creation_date);
422 sprintf (buf, "%02d:%02d:%02d", hour - 1, min - 1, sec - 1);
423 memcpy (hdr.creation_time, buf, sizeof hdr.creation_time);
427 const char *label = dict_get_label (d);
431 buf_copy_str_rpad (hdr.file_label, sizeof hdr.file_label, label);
434 memset (hdr.padding, 0, sizeof hdr.padding);
436 buf_write (w, &hdr, sizeof hdr);
439 /* Translates format spec from internal form in SRC to system file
442 write_format_spec (const struct fmt_spec *src, int32_t *dest)
444 assert (fmt_check_output (src));
445 *dest = (fmt_to_io (src->type) << 16) | (src->w << 8) | src->d;
448 /* Write the variable record(s) for primary variable P and secondary
449 variable S to system file W. */
451 write_variable (struct sfm_writer *w, const struct variable *v)
453 struct sysfile_variable sv;
455 /* Missing values. */
456 struct missing_values mv;
457 flt64 m[3]; /* Missing value values. */
458 int nm; /* Number of missing values, possibly negative. */
461 sv.type = MIN(v->width, MAX_LONG_STRING);
462 sv.has_var_label = (v->label != NULL);
464 mv_copy (&mv, &v->miss);
466 if (mv_has_range (&mv))
469 mv_pop_range (&mv, &x, &y);
470 m[nm++] = x == LOWEST ? second_lowest_flt64 : x;
471 m[nm++] = y == HIGHEST ? FLT64_MAX : y;
473 while (mv_has_value (&mv))
476 mv_pop_value (&mv, &value);
477 if (v->type == NUMERIC)
480 buf_copy_rpad ((char *) &m[nm], sizeof m[nm], value.s, v->width);
483 if (mv_has_range (&v->miss))
486 sv.n_missing_values = nm;
487 write_format_spec (&v->print, &sv.print);
488 write_format_spec (&v->write, &sv.write);
489 buf_copy_str_rpad (sv.name, sizeof sv.name, v->short_name);
490 buf_write (w, &sv, sizeof sv);
498 } ATTRIBUTE((packed))
503 l.label_len = MIN (strlen (v->label), 255);
504 ext_len = ROUND_UP (l.label_len, sizeof l.label_len);
505 memcpy (l.label, v->label, l.label_len);
506 memset (&l.label[l.label_len], ' ', ext_len - l.label_len);
508 buf_write (w, &l, offsetof (struct label, label) + ext_len);
512 buf_write (w, m, sizeof *m * abs (nm));
514 if (v->type == ALPHA && v->width > (int) sizeof (flt64))
520 sv.has_var_label = 0;
521 sv.n_missing_values = 0;
522 memset (&sv.print, 0, sizeof sv.print);
523 memset (&sv.write, 0, sizeof sv.write);
524 memset (&sv.name, 0, sizeof sv.name);
526 pad_count = DIV_RND_UP (MIN(v->width, MAX_LONG_STRING),
527 (int) sizeof (flt64)) - 1;
528 for (i = 0; i < pad_count; i++)
529 buf_write (w, &sv, sizeof sv);
533 /* Writes the value labels for variable V having system file
534 variable index IDX to system file W. */
536 write_value_labels (struct sfm_writer *w, struct variable *v, int idx)
538 struct value_label_rec
543 } ATTRIBUTE((packed));
550 } ATTRIBUTE((packed));
552 struct val_labs_iterator *i;
553 struct value_label_rec *vlr;
554 struct var_idx_rec vir;
559 if (!val_labs_count (v->val_labs))
562 /* Pass 1: Count bytes. */
563 vlr_size = (sizeof (struct value_label_rec)
564 + sizeof (flt64) * (val_labs_count (v->val_labs) - 1));
565 for (vl = val_labs_first (v->val_labs, &i); vl != NULL;
566 vl = val_labs_next (v->val_labs, &i))
567 vlr_size += ROUND_UP (strlen (vl->label) + 1, sizeof (flt64));
569 /* Pass 2: Copy bytes. */
570 vlr = xmalloc (vlr_size);
572 vlr->n_labels = val_labs_count (v->val_labs);
574 for (vl = val_labs_first_sorted (v->val_labs, &i); vl != NULL;
575 vl = val_labs_next (v->val_labs, &i))
577 size_t len = strlen (vl->label);
579 *loc++ = vl->value.f;
580 *(unsigned char *) loc = len;
581 memcpy (&((char *) loc)[1], vl->label, len);
582 memset (&((char *) loc)[1 + len], ' ',
583 REM_RND_UP (len + 1, sizeof (flt64)));
584 loc += DIV_RND_UP (len + 1, sizeof (flt64));
587 buf_write (w, vlr, vlr_size);
592 vir.vars[0] = idx + 1;
593 buf_write (w, &vir, sizeof vir);
596 /* Writes record type 6, document record. */
598 write_documents (struct sfm_writer *w, const struct dictionary *d)
602 int32_t rec_type ; /* Always 6. */
603 int32_t n_lines ; /* Number of lines of documents. */
604 } ATTRIBUTE((packed)) rec_6;
606 const char *documents;
609 documents = dict_get_documents (d);
610 n_lines = strlen (documents) / 80;
613 rec_6.n_lines = n_lines;
614 buf_write (w, &rec_6, sizeof rec_6);
615 buf_write (w, documents, 80 * n_lines);
618 /* Write the alignment, width and scale values */
620 write_variable_display_parameters (struct sfm_writer *w,
621 const struct dictionary *dict)
631 } ATTRIBUTE((packed)) vdp_hdr;
633 vdp_hdr.rec_type = 7;
634 vdp_hdr.subtype = 11;
635 vdp_hdr.elem_size = 4;
636 vdp_hdr.n_elem = w->var_cnt_vls * 3;
638 buf_write (w, &vdp_hdr, sizeof vdp_hdr);
640 for ( i = 0 ; i < w->var_cnt ; ++i )
648 } ATTRIBUTE((packed)) params;
650 v = dict_get_var(dict, i);
652 params.measure = v->measure;
653 params.width = v->display_width;
654 params.align = v->alignment;
656 buf_write (w, ¶ms, sizeof(params));
658 if ( v->width > MAX_LONG_STRING )
660 int wcount = v->width - EFFECTIVE_LONG_STRING_LENGTH ;
664 params.width = wcount > MAX_LONG_STRING ? 32 : wcount;
666 buf_write (w, ¶ms, sizeof(params));
668 wcount -= EFFECTIVE_LONG_STRING_LENGTH ;
674 /* Writes the table of lengths for Very Long String Variables */
676 write_vls_length_table (struct sfm_writer *w,
677 const struct dictionary *dict)
686 } ATTRIBUTE((packed)) vls_hdr;
688 struct string vls_length_map;
690 ds_init_empty (&vls_length_map);
692 vls_hdr.rec_type = 7;
693 vls_hdr.subtype = 14;
694 vls_hdr.elem_size = 1;
697 for (i = 0; i < dict_get_var_cnt (dict); ++i)
699 const struct variable *v = dict_get_var (dict, i);
701 if ( v->width <= MAX_LONG_STRING )
704 ds_put_format (&vls_length_map, "%s=%05d", v->short_name, v->width);
705 ds_put_char (&vls_length_map, '\0');
706 ds_put_char (&vls_length_map, '\t');
709 vls_hdr.n_elem = ds_length (&vls_length_map);
711 if ( vls_hdr.n_elem > 0 )
713 buf_write (w, &vls_hdr, sizeof vls_hdr);
714 buf_write (w, ds_data (&vls_length_map), ds_length (&vls_length_map));
717 ds_destroy (&vls_length_map);
720 /* Writes the long variable name table */
722 write_longvar_table (struct sfm_writer *w, const struct dictionary *dict)
730 } ATTRIBUTE((packed)) lv_hdr;
732 struct string long_name_map;
735 ds_init_empty (&long_name_map);
736 for (i = 0; i < dict_get_var_cnt (dict); i++)
738 struct variable *v = dict_get_var (dict, i);
741 ds_put_char (&long_name_map, '\t');
742 ds_put_format (&long_name_map, "%s=%s", v->short_name, v->name);
747 lv_hdr.elem_size = 1;
748 lv_hdr.n_elem = ds_length (&long_name_map);
750 buf_write (w, &lv_hdr, sizeof lv_hdr);
751 buf_write (w, ds_data (&long_name_map), ds_length (&long_name_map));
753 ds_destroy (&long_name_map);
756 /* Writes record type 7, subtypes 3 and 4. */
758 write_rec_7_34 (struct sfm_writer *w)
764 int32_t data_type_3 ;
769 int32_t data_type_4 ;
772 } ATTRIBUTE((packed)) rec_7;
774 /* Components of the version number, from major to minor. */
775 int version_component[3];
777 /* Used to step through the version string. */
780 /* Parses the version string, which is assumed to be of the form
781 #.#x, where each # is a string of digits, and x is a single
783 version_component[0] = strtol (bare_version, &p, 10);
786 version_component[1] = strtol (bare_version, &p, 10);
787 version_component[2] = (isalpha ((unsigned char) *p)
788 ? tolower ((unsigned char) *p) - 'a' : 0);
790 rec_7.rec_type_3 = 7;
792 rec_7.data_type_3 = sizeof (int32_t);
794 rec_7.elem_3[0] = version_component[0];
795 rec_7.elem_3[1] = version_component[1];
796 rec_7.elem_3[2] = version_component[2];
797 rec_7.elem_3[3] = -1;
799 /* PORTME: 1=IEEE754, 2=IBM 370, 3=DEC VAX E. */
806 /* PORTME: 1=big-endian, 2=little-endian. */
813 /* PORTME: 1=EBCDIC, 2=7-bit ASCII, 3=8-bit ASCII, 4=DEC Kanji. */
816 rec_7.rec_type_4 = 7;
818 rec_7.data_type_4 = sizeof (flt64);
820 rec_7.elem_4[0] = -FLT64_MAX;
821 rec_7.elem_4[1] = FLT64_MAX;
822 rec_7.elem_4[2] = second_lowest_flt64;
824 buf_write (w, &rec_7, sizeof rec_7);
827 /* Write NBYTES starting at BUF to the system file represented by
830 buf_write (struct sfm_writer *w, const void *buf, size_t nbytes)
832 assert (buf != NULL);
833 fwrite (buf, nbytes, 1, w->file);
836 /* Copies string DEST to SRC with the proviso that DEST does not reach
837 byte END; no null terminator is copied. Returns a pointer to the
838 byte after the last byte copied. */
840 append_string_max (char *dest, const char *src, const char *end)
842 int nbytes = MIN (end - dest, (int) strlen (src));
843 memcpy (dest, src, nbytes);
844 return dest + nbytes;
847 /* Makes certain that the compression buffer of H has room for another
848 element. If there's not room, pads out the current instruction
849 octet with zero and dumps out the buffer. */
851 ensure_buf_space (struct sfm_writer *w)
853 if (w->ptr >= w->end)
855 memset (w->x, 0, w->y - w->x);
858 buf_write (w, w->buf, sizeof *w->buf * 128);
862 static void write_compressed_data (struct sfm_writer *w, const flt64 *elem);
864 /* Writes case C to system file W.
865 Returns 1 if successful, 0 if an I/O error occurred. */
867 sfm_write_case (struct sfm_writer *w, const struct ccase *c)
869 if (ferror (w->file))
874 if (!w->needs_translation && !w->compress
875 && sizeof (flt64) == sizeof (union value) && ! w->has_vls )
877 /* Fast path: external and internal representations are the
878 same and the dictionary is properly ordered. Write
880 buf_write (w, case_data_all (c), sizeof (union value) * w->flt64_cnt);
884 /* Slow path: internal and external representations differ.
885 Write into a bounce buffer, then write to W. */
892 bounce_size = sizeof *bounce * w->flt64_cnt;
893 bounce = bounce_cur = local_alloc (bounce_size);
894 bounce_end = bounce + bounce_size;
896 for (i = 0; i < w->var_cnt; i++)
898 struct sfm_var *v = &w->vars[i];
900 memset(bounce_cur, ' ', v->flt64_cnt * sizeof (flt64));
904 *bounce_cur = case_num (c, v->fv);
905 bounce_cur += v->flt64_cnt;
909 while (ofs < v->width)
911 int chunk = MIN (MAX_LONG_STRING, v->width - ofs);
912 int nv = DIV_RND_UP (chunk, sizeof (flt64));
913 buf_copy_rpad ((char *) bounce_cur, nv * sizeof (flt64),
914 case_data (c, v->fv)->s + ofs, chunk);
923 buf_write (w, bounce, bounce_size);
925 write_compressed_data (w, bounce);
930 return !sfm_write_error (w);
934 put_instruction (struct sfm_writer *w, unsigned char instruction)
938 ensure_buf_space (w);
939 w->x = (unsigned char *) w->ptr++;
940 w->y = (unsigned char *) w->ptr;
942 *w->x++ = instruction;
946 put_element (struct sfm_writer *w, const flt64 *elem)
948 ensure_buf_space (w);
949 memcpy (w->ptr++, elem, sizeof *elem);
953 write_compressed_data (struct sfm_writer *w, const flt64 *elem)
957 for (i = 0; i < w->var_cnt; i++)
959 struct sfm_var *v = &w->vars[i];
963 if (*elem == -FLT64_MAX)
964 put_instruction (w, 255);
965 else if (*elem >= 1 - COMPRESSION_BIAS
966 && *elem <= 251 - COMPRESSION_BIAS
967 && *elem == (int) *elem)
968 put_instruction (w, (int) *elem + COMPRESSION_BIAS);
971 put_instruction (w, 253);
972 put_element (w, elem);
980 for (j = 0; j < v->flt64_cnt; j++, elem++)
982 if (!memcmp (elem, " ", sizeof (flt64)))
983 put_instruction (w, 254);
986 put_instruction (w, 253);
987 put_element (w, elem);
994 /* Returns true if an I/O error has occurred on WRITER, false otherwise. */
996 sfm_write_error (const struct sfm_writer *writer)
998 return ferror (writer->file);
1001 /* Closes a system file after we're done with it.
1002 Returns true if successful, false if an I/O error occurred. */
1004 sfm_close_writer (struct sfm_writer *w)
1012 if (w->file != NULL)
1015 if (w->buf != NULL && w->ptr > w->buf)
1017 memset (w->x, 0, w->y - w->x);
1018 buf_write (w, w->buf, (w->ptr - w->buf) * sizeof *w->buf);
1022 ok = !sfm_write_error (w);
1024 /* Seek back to the beginning and update the number of cases.
1025 This is just a courtesy to later readers, so there's no need
1026 to check return values or report errors. */
1027 if (ok && !fseek (w->file, offsetof (struct sysfile_header, case_cnt),
1030 int32_t case_cnt = w->case_cnt;
1031 fwrite (&case_cnt, sizeof case_cnt, 1, w->file);
1035 if (fclose (w->file) == EOF)
1039 msg (ME, _("An I/O error occurred writing system file \"%s\"."),
1040 fh_get_file_name (w->fh));
1043 fh_close (w->fh, "system file", "we");