Added a --enable-debug option to configure and
[pspp-builds.git] / src / sfm-write.c
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
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.
9
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.
14
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., 59 Temple Place - Suite 330, Boston, MA
18    02111-1307, USA. */
19
20 /* AIX requires this to be the first thing in the file.  */
21 #include <config.h>
22 #if __GNUC__
23 #define alloca __builtin_alloca
24 #else
25 #if HAVE_ALLOCA_H
26 #include <alloca.h>
27 #else
28 #ifdef _AIX
29 #pragma alloca
30 #else
31 #ifndef alloca                  /* predefined by HP cc +Olibcalls */
32 char *alloca ();
33 #endif
34 #endif
35 #endif
36 #endif
37
38 #include <assert.h>
39 #include <stdlib.h>
40 #include <ctype.h>
41 #include <errno.h>
42 #include <time.h>
43 #if HAVE_UNISTD_H
44 #include <unistd.h>     /* Required by SunOS4. */
45 #endif
46 #include "alloc.h"
47 #include "approx.h"
48 #include "avl.h"
49 #include "error.h"
50 #include "file-handle.h"
51 #include "getline.h"
52 #include "magic.h"
53 #include "misc.h"
54 #include "sfm.h"
55 #include "sfmP.h"
56 #include "str.h"
57 #include "var.h"
58 #include "version.h"
59
60 #include "debug-print.h"
61
62 /* PORTME: This file may require substantial revision for those
63    systems that don't meet the typical 32-bit integer/64-bit double
64    model.  It's kinda hard to tell without having one of them on my
65    desk.  */
66
67 /* Compression bias used by PSPP.  Values between (1 -
68    COMPRESSION_BIAS) and (251 - COMPRESSION_BIAS) inclusive can be
69    compressed. */
70 #define COMPRESSION_BIAS 100
71
72 /* sfm writer file_handle extension. */
73 struct sfm_fhuser_ext
74   {
75     FILE *file;                 /* Actual file. */
76
77     int compressed;             /* 1=compressed, 0=not compressed. */
78     flt64 *buf;                 /* Buffered data. */
79     flt64 *end;                 /* Buffer end. */
80     flt64 *ptr;                 /* Current location in buffer. */
81     unsigned char *x;           /* Location in current instruction octet. */
82     unsigned char *y;           /* End of instruction octet. */
83     int n_cases;                /* Number of cases written so far. */
84
85     char *elem_type;            /* ALPHA or NUMERIC for each flt64 element. */
86   };
87
88 static struct fh_ext_class sfm_w_class;
89
90 static char *append_string_max (char *, const char *, const char *);
91 static int write_header (struct sfm_write_info *inf);
92 static int bufwrite (struct file_handle *h, const void *buf, size_t nbytes);
93 static int write_variable (struct sfm_write_info *inf, struct variable *v);
94 static int write_value_labels (struct sfm_write_info *inf, struct variable * s, int index);
95 static int write_rec_7_34 (struct sfm_write_info *inf);
96 static int write_documents (struct sfm_write_info *inf);
97
98 /* Writes the dictionary INF->dict to system file INF->h.  The system
99    file is compressed if INF->compress is nonzero.  INF->case_size is
100    set to the number of flt64 elements in a single case.  Returns
101    nonzero only if successful. */
102 int
103 sfm_write_dictionary (struct sfm_write_info *inf)
104 {
105   struct dictionary *d = inf->dict;
106   struct sfm_fhuser_ext *ext;
107   int i;
108   int index;
109
110   if (inf->h->class != NULL)
111     {
112       msg (ME, _("Cannot write file %s as system file: already opened for %s."),
113            fh_handle_name (inf->h), inf->h->class->name);
114       return 0;
115     }
116
117   msg (VM (1), _("%s: Opening system-file handle %s for writing."),
118        fh_handle_filename (inf->h), fh_handle_name (inf->h));
119   
120   /* Open the physical disk file. */
121   inf->h->class = &sfm_w_class;
122   inf->h->ext = ext = xmalloc (sizeof (struct sfm_fhuser_ext));
123   ext->file = fopen (inf->h->norm_fn, "wb");
124   ext->elem_type = NULL;
125   if (ext->file == NULL)
126     {
127       msg (ME, _("An error occurred while opening \"%s\" for writing "
128            "as a system file: %s."), inf->h->fn, strerror (errno));
129       err_cond_fail ();
130       free (ext);
131       return 0;
132     }
133
134   /* Initialize the sfm_fhuser_ext structure. */
135   ext->compressed = inf->compress;
136   ext->buf = ext->ptr = NULL;
137   ext->x = ext->y = NULL;
138   ext->n_cases = 0;
139
140   /* Write the file header. */
141   if (!write_header (inf))
142     goto lossage;
143
144   /* Write basic variable info. */
145   for (i = 0; i < d->nvar; i++)
146     write_variable (inf, d->var[i]);
147
148   /* Write out value labels. */
149   for (index = i = 0; i < d->nvar; i++)
150     {
151       struct variable *v = d->var[i];
152
153       if (!write_value_labels (inf, v, index))
154         goto lossage;
155       index += (v->type == NUMERIC ? 1
156                 : DIV_RND_UP (v->width, sizeof (flt64)));
157     }
158
159   if (d->documents != NULL && !write_documents (inf))
160     goto lossage;
161   if (!write_rec_7_34 (inf))
162     goto lossage;
163
164   /* Write record 999. */
165   {
166     struct
167       {
168         int32 rec_type P;
169         int32 filler P;
170       }
171     rec_999;
172
173     rec_999.rec_type = 999;
174     rec_999.filler = 0;
175
176     if (!bufwrite (inf->h, &rec_999, sizeof rec_999))
177       goto lossage;
178   }
179
180   msg (VM (2), _("Wrote system-file header successfully."));
181   
182   return 1;
183
184 lossage:
185   msg (VM (1), _("Error writing system-file header."));
186   fclose (ext->file);
187   inf->h->class = NULL;
188   inf->h->ext = NULL;
189   free (ext->elem_type);
190   ext->elem_type = NULL;
191   return 0;
192 }
193
194 /* Returns value of X truncated to two least-significant digits. */
195 static int
196 rerange (int x)
197 {
198   if (x < 0)
199     x = -x;
200   if (x >= 100)
201     x %= 100;
202   return x;
203 }
204
205 /* Write the sysfile_header header to the system file represented by
206    INF. */
207 static int
208 write_header (struct sfm_write_info *inf)
209 {
210   struct dictionary *d = inf->dict;
211   struct sfm_fhuser_ext *ext = inf->h->ext;
212   struct sysfile_header hdr;
213   char *p;
214   int i;
215
216   time_t t;
217
218   memcpy (hdr.rec_type, "$FL2", 4);
219
220   p = stpcpy (hdr.prod_name, "@(#) SPSS DATA FILE ");
221   p = append_string_max (p, version, &hdr.prod_name[60]);
222   p = append_string_max (p, " - ", &hdr.prod_name[60]);
223   p = append_string_max (p, host_system, &hdr.prod_name[60]);
224   memset (p, ' ', &hdr.prod_name[60] - p);
225
226   hdr.layout_code = 2;
227
228   hdr.case_size = 0;
229   for (i = 0; i < d->nvar; i++)
230     {
231       struct variable *v = d->var[i];
232       hdr.case_size += (v->type == NUMERIC ? 1
233                         : DIV_RND_UP (v->width, sizeof (flt64)));
234     }
235   inf->case_size = hdr.case_size;
236
237   p = ext->elem_type = xmalloc (inf->case_size);
238   for (i = 0; i < d->nvar; i++)
239     {
240       struct variable *v = d->var[i];
241       int count = (v->type == NUMERIC ? 1
242                    : DIV_RND_UP (v->width, sizeof (flt64)));
243       while (count--)
244         *p++ = v->type;
245     }
246
247   hdr.compressed = inf->compress;
248
249   update_weighting (d);
250   if (d->weight_index != -1)
251     {
252       int recalc_weight_index = 1;
253
254       for (i = 0; i < d->weight_index; i++)
255         {
256           struct variable *v = d->var[i];
257           recalc_weight_index += (v->type == NUMERIC ? 1
258                                   : DIV_RND_UP (v->width, sizeof (flt64)));
259         }
260       hdr.weight_index = recalc_weight_index;
261     }
262   else
263     hdr.weight_index = 0;
264
265   hdr.ncases = -1;
266   hdr.bias = COMPRESSION_BIAS;
267
268   if ((time_t) - 1 == time (&t))
269     {
270       memcpy (hdr.creation_date, "01 Jan 70", 9);
271       memcpy (hdr.creation_time, "00:00:00", 8);
272     }
273   else
274     {
275       static const char *month_name[12] =
276       {
277         "Jan", "Feb", "Mar", "Apr", "May", "Jun",
278         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
279       };
280       struct tm *tmp = localtime (&t);
281       int day = rerange (tmp->tm_mday);
282       int mon = rerange (tmp->tm_mon + 1);
283       int year = rerange (tmp->tm_year);
284       int hour = rerange (tmp->tm_hour + 1);
285       int min = rerange (tmp->tm_min + 1);
286       int sec = rerange (tmp->tm_sec + 1);
287       char buf[10];
288
289       sprintf (buf, "%02d %s %02d", day, month_name[mon - 1], year);
290       memcpy (hdr.creation_date, buf, sizeof hdr.creation_date);
291       sprintf (buf, "%02d:%02d:%02d", hour - 1, min - 1, sec - 1);
292       memcpy (hdr.creation_time, buf, sizeof hdr.creation_time);
293     }
294
295   st_bare_pad_copy (hdr.file_label, d->label ? d->label : "",
296                     sizeof hdr.file_label);
297   memset (hdr.padding, 0, sizeof hdr.padding);
298
299   if (!bufwrite (inf->h, &hdr, sizeof hdr))
300     return 0;
301   return 1;
302 }
303
304 /* Translates format spec from internal form in SRC to system file
305    format in DEST. */
306 static inline void
307 write_format_spec (struct fmt_spec *src, int32 *dest)
308 {
309   *dest = (formats[src->type].spss << 16) | (src->w << 8) | src->d;
310 }
311
312 /* Write the variable record(s) for primary variable P and secondary
313    variable S to the system file represented by INF. */
314 static int
315 write_variable (struct sfm_write_info *inf, struct variable *v)
316 {
317   struct sysfile_variable sv;
318
319   /* Missing values. */
320   flt64 m[3];                   /* Missing value values. */
321   int nm;                       /* Number of missing values, possibly negative. */
322
323   sv.rec_type = 2;
324   sv.type = (v->type == NUMERIC ? 0 : v->width);
325   sv.has_var_label = (v->label != NULL);
326
327   switch (v->miss_type)
328     {
329     case MISSING_NONE:
330       nm = 0;
331       break;
332     case MISSING_1:
333     case MISSING_2:
334     case MISSING_3:
335       for (nm = 0; nm < v->miss_type; nm++)
336         m[nm] = v->missing[nm].f;
337       break;
338     case MISSING_RANGE:
339       m[0] = v->missing[0].f;
340       m[1] = v->missing[1].f;
341       nm = -2;
342       break;
343     case MISSING_LOW:
344       m[0] = second_lowest_flt64;
345       m[1] = v->missing[0].f;
346       nm = -2;
347       break;
348     case MISSING_HIGH:
349       m[0] = v->missing[0].f;
350       m[1] = FLT64_MAX;
351       nm = -2;
352       break;
353     case MISSING_RANGE_1:
354       m[0] = v->missing[0].f;
355       m[1] = v->missing[1].f;
356       m[2] = v->missing[2].f;
357       nm = -3;
358       break;
359     case MISSING_LOW_1:
360       m[0] = second_lowest_flt64;
361       m[1] = v->missing[0].f;
362       m[2] = v->missing[1].f;
363       nm = -3;
364       break;
365     case MISSING_HIGH_1:
366       m[0] = v->missing[0].f;
367       m[1] = second_lowest_flt64;
368       m[2] = v->missing[1].f;
369       nm = -3;
370       break;
371     default:
372       assert (0);
373     }
374
375   sv.n_missing_values = nm;
376   write_format_spec (&v->print, &sv.print);
377   write_format_spec (&v->write, &sv.write);
378   memcpy (sv.name, v->name, strlen (v->name));
379   memset (&sv.name[strlen (v->name)], ' ', 8 - strlen (v->name));
380   if (!bufwrite (inf->h, &sv, sizeof sv))
381     return 0;
382
383   if (v->label)
384     {
385       struct label
386         {
387           int32 label_len P;
388           char label[120] P;
389         }
390       l;
391
392       int ext_len;
393
394       l.label_len = min (strlen (v->label), 120);
395       ext_len = ROUND_UP (l.label_len, sizeof l.label_len);
396       memcpy (l.label, v->label, l.label_len);
397       memset (&l.label[l.label_len], ' ', ext_len - l.label_len);
398
399       if (!bufwrite (inf->h, &l, offsetof (struct label, label) + ext_len))
400           return 0;
401     }
402
403   if (nm && !bufwrite (inf->h, m, sizeof *m * nm))
404     return 0;
405
406   if (v->type == ALPHA && v->width > (int) sizeof (flt64))
407     {
408       int i;
409       int pad_count;
410
411       sv.type = -1;
412       sv.has_var_label = 0;
413       sv.n_missing_values = 0;
414       memset (&sv.print, 0, sizeof sv.print);
415       memset (&sv.write, 0, sizeof sv.write);
416       memset (&sv.name, 0, sizeof sv.name);
417
418       pad_count = DIV_RND_UP (v->width, (int) sizeof (flt64)) - 1;
419       for (i = 0; i < pad_count; i++)
420         if (!bufwrite (inf->h, &sv, sizeof sv))
421           return 0;
422     }
423
424   return 1;
425 }
426
427 /* Writes the value labels for variable V having system file variable
428    index INDEX to the system file associated with INF.  Returns
429    nonzero only if successful. */
430 static int
431 write_value_labels (struct sfm_write_info * inf, struct variable *v, int index)
432 {
433   struct value_label_rec
434     {
435       int32 rec_type P;
436       int32 n_labels P;
437       flt64 labels[1] P;
438     };
439
440   struct variable_index_rec
441     {
442       int32 rec_type P;
443       int32 n_vars P;
444       int32 vars[1] P;
445     };
446
447   avl_traverser i;
448   struct value_label_rec *vlr;
449   struct variable_index_rec vir;
450   struct value_label *vl;
451   size_t vlr_size;
452   flt64 *loc;
453   avl_traverser_init (i);
454
455   if (v->val_lab == NULL || avl_count (v->val_lab) == 0)
456     return 1;
457
458   /* Pass 1: Count bytes. */
459   vlr_size = (sizeof (struct value_label_rec)
460               + sizeof (flt64) * (avl_count (v->val_lab) - 1));
461   while (NULL != (vl = avl_traverse (v->val_lab, &i)))
462     vlr_size += ROUND_UP (strlen (vl->s) + 1, sizeof (flt64));
463
464   /* Pass 2: Copy bytes. */
465   vlr = local_alloc (vlr_size);
466   vlr->rec_type = 3;
467   vlr->n_labels = avl_count (v->val_lab);
468   loc = vlr->labels;
469   while (NULL != (vl = avl_traverse (v->val_lab, &i)))
470     {
471       int len = strlen (vl->s);
472
473       *loc++ = vl->v.f;
474       *(unsigned char *) loc = len;
475       memcpy (&((unsigned char *) loc)[1], vl->s, len);
476       memset (&((unsigned char *) loc)[1 + len], ' ',
477               REM_RND_UP (len + 1, sizeof (flt64)));
478       loc += DIV_RND_UP (len + 1, sizeof (flt64));
479     }
480   
481   if (!bufwrite (inf->h, vlr, vlr_size))
482     {
483       local_free (vlr);
484       return 0;
485     }
486   local_free (vlr);
487
488   vir.rec_type = 4;
489   vir.n_vars = 1;
490   vir.vars[0] = index + 1;
491   if (!bufwrite (inf->h, &vir, sizeof vir))
492     return 0;
493
494   return 1;
495 }
496
497 /* Writes record type 6, document record. */
498 static int
499 write_documents (struct sfm_write_info * inf)
500 {
501   struct dictionary *d = inf->dict;
502   struct
503   {
504     int32 rec_type P;           /* Always 6. */
505     int32 n_lines P;            /* Number of lines of documents. */
506   }
507   rec_6;
508
509   rec_6.rec_type = 6;
510   rec_6.n_lines = d->n_documents;
511   if (!bufwrite (inf->h, &rec_6, sizeof rec_6))
512     return 0;
513   if (!bufwrite (inf->h, d->documents, 80 * d->n_documents))
514     return 0;
515
516   return 1;
517 }
518
519 /* Writes record type 7, subtypes 3 and 4. */
520 static int
521 write_rec_7_34 (struct sfm_write_info * inf)
522 {
523   struct
524     {
525       int32 rec_type_3 P;
526       int32 subtype_3 P;
527       int32 data_type_3 P;
528       int32 n_elem_3 P;
529       int32 elem_3[8] P;
530       int32 rec_type_4 P;
531       int32 subtype_4 P;
532       int32 data_type_4 P;
533       int32 n_elem_4 P;
534       flt64 elem_4[3] P;
535     }
536   rec_7;
537
538   /* Components of the version number, from major to minor. */
539   int version_component[3];
540   
541   /* Used to step through the version string. */
542   char *p;
543
544   /* Parses the version string, which is assumed to be of the form
545      #.#x, where each # is a string of digits, and x is a single
546      letter. */
547   version_component[0] = strtol (bare_version, &p, 10);
548   if (*p == '.')
549     p++;
550   version_component[1] = strtol (bare_version, &p, 10);
551   version_component[2] = (isalpha ((unsigned char) *p)
552                           ? tolower ((unsigned char) *p) - 'a' : 0);
553     
554   rec_7.rec_type_3 = 7;
555   rec_7.subtype_3 = 3;
556   rec_7.data_type_3 = sizeof (int32);
557   rec_7.n_elem_3 = 8;
558   rec_7.elem_3[0] = version_component[0];
559   rec_7.elem_3[1] = version_component[1];
560   rec_7.elem_3[2] = version_component[2];
561   rec_7.elem_3[3] = -1;
562
563   /* PORTME: 1=IEEE754, 2=IBM 370, 3=DEC VAX E. */
564 #ifdef FPREP_IEEE754
565   rec_7.elem_3[4] = 1;
566 #endif
567
568   rec_7.elem_3[5] = 1;
569
570   /* PORTME: 1=big-endian, 2=little-endian. */
571 #if WORDS_BIGENDIAN
572   rec_7.elem_3[6] = 1;
573 #else
574   rec_7.elem_3[6] = 2;
575 #endif
576
577   /* PORTME: 1=EBCDIC, 2=7-bit ASCII, 3=8-bit ASCII, 4=DEC Kanji. */
578   rec_7.elem_3[7] = 2;
579
580   rec_7.rec_type_4 = 7;
581   rec_7.subtype_4 = 4;
582   rec_7.data_type_4 = sizeof (flt64);
583   rec_7.n_elem_4 = 3;
584   rec_7.elem_4[0] = -FLT64_MAX;
585   rec_7.elem_4[1] = FLT64_MAX;
586   rec_7.elem_4[2] = second_lowest_flt64;
587
588   if (!bufwrite (inf->h, &rec_7, sizeof rec_7))
589     return 0;
590   return 1;
591 }
592
593 /* Write NBYTES starting at BUF to the system file represented by
594    H. */
595 static int
596 bufwrite (struct file_handle * h, const void *buf, size_t nbytes)
597 {
598   struct sfm_fhuser_ext *ext = h->ext;
599
600   assert (buf);
601   if (1 != fwrite (buf, nbytes, 1, ext->file))
602     {
603       msg (ME, _("%s: Writing system file: %s."), h->fn, strerror (errno));
604       return 0;
605     }
606   return 1;
607 }
608
609 /* Copies string DEST to SRC with the proviso that DEST does not reach
610    byte END; no null terminator is copied.  Returns a pointer to the
611    byte after the last byte copied. */
612 static char *
613 append_string_max (char *dest, const char *src, const char *end)
614 {
615   int nbytes = min (end - dest, (int) strlen (src));
616   memcpy (dest, src, nbytes);
617   return dest + nbytes;
618 }
619
620 /* Makes certain that the compression buffer of H has room for another
621    element.  If there's not room, pads out the current instruction
622    octet with zero and dumps out the buffer. */
623 static inline int
624 ensure_buf_space (struct file_handle *h)
625 {
626   struct sfm_fhuser_ext *ext = h->ext;
627
628   if (ext->ptr >= ext->end)
629     {
630       memset (ext->x, 0, ext->y - ext->x);
631       ext->x = ext->y;
632       ext->ptr = ext->buf;
633       if (!bufwrite (h, ext->buf, sizeof *ext->buf * 128))
634         return 0;
635     }
636   return 1;
637 }
638
639 /* Writes case ELEM consisting of N_ELEM flt64 elements to the system
640    file represented by H.  Return success. */
641 int
642 sfm_write_case (struct file_handle * h, const flt64 *elem, int n_elem)
643 {
644   struct sfm_fhuser_ext *ext = h->ext;
645   const flt64 *end_elem = &elem[n_elem];
646   char *elem_type = ext->elem_type;
647
648   ext->n_cases++;
649
650   if (ext->compressed == 0)
651     return bufwrite (h, elem, sizeof *elem * n_elem);
652
653   if (ext->buf == NULL)
654     {
655       ext->buf = xmalloc (sizeof *ext->buf * 128);
656       ext->ptr = ext->buf;
657       ext->end = &ext->buf[128];
658       ext->x = (unsigned char *) (ext->ptr++);
659       ext->y = (unsigned char *) (ext->ptr);
660     }
661   for (; elem < end_elem; elem++, elem_type++)
662     {
663       if (ext->x >= ext->y)
664         {
665           if (!ensure_buf_space (h))
666             return 0;
667           ext->x = (unsigned char *) (ext->ptr++);
668           ext->y = (unsigned char *) (ext->ptr);
669         }
670
671       if (*elem_type == NUMERIC)
672         {
673           if (*elem == -FLT64_MAX)
674             {
675               *ext->x++ = 255;
676               continue;
677             }
678           else
679             {
680               int value = *elem < 0 ? *elem - EPSILON : *elem + EPSILON;
681
682               if (value >= 1 - COMPRESSION_BIAS
683                   && value <= 251 - COMPRESSION_BIAS
684                   && approx_eq (value, *elem))
685                 {
686                   *ext->x++ = value + COMPRESSION_BIAS;
687                   continue;
688                 }
689             }
690         }
691       else
692         {
693           if (0 == memcmp ((char *) elem,
694                            "                                           ",
695                            sizeof (flt64)))
696             {
697               *ext->x++ = 254;
698               continue;
699             }
700         }
701       
702       *ext->x++ = 253;
703       if (!ensure_buf_space (h))
704         return 0;
705       *ext->ptr++ = *elem;
706     }
707
708   return 1;
709 }
710
711 /* Closes a system file after we're done with it. */
712 static void
713 sfm_close (struct file_handle * h)
714 {
715   struct sfm_fhuser_ext *ext = h->ext;
716
717   if (ext->buf != NULL && ext->ptr > ext->buf)
718     {
719       memset (ext->x, 0, ext->y - ext->x);
720       bufwrite (h, ext->buf, (ext->ptr - ext->buf) * sizeof *ext->buf);
721     }
722
723   /* Attempt to seek back to the beginning in order to write the
724      number of cases.  If that's not possible (i.e., we're writing to
725      a tty or a pipe), then it's not a big deal because we wrote the
726      code that indicates an unknown number of cases. */
727   if (0 == fseek (ext->file, offsetof (struct sysfile_header, ncases),
728                   SEEK_SET))
729     {
730       int32 n_cases = ext->n_cases;
731
732       /* I don't really care about the return value: it doesn't matter
733          whether this data is written.  This is the only situation in
734          which you will see me fail to check a return value. */
735       fwrite (&n_cases, sizeof n_cases, 1, ext->file);
736     }
737
738   if (EOF == fclose (ext->file))
739     msg (ME, _("%s: Closing system file: %s."), h->fn, strerror (errno));
740   free (ext->buf);
741
742   free (ext->elem_type);
743   free (ext);
744 }
745
746 static struct fh_ext_class sfm_w_class =
747 {
748   4,
749   N_("writing as a system file"),
750   sfm_close,
751 };