- size_t rec_width = fh_get_record_width (w->fh);
- if (w->bounce == NULL)
- w->bounce = xmalloc (rec_width);
- memcpy (w->bounce, rec, len);
- memset (&w->bounce[len], 0, rec_width - len);
- rec = w->bounce;
- len = rec_width;
+ case FH_MODE_TEXT:
+ fwrite (rec, len, 1, w->file);
+ putc ('\n', w->file);
+ break;
+
+ case FH_MODE_BINARY:
+ {
+ size_t record_width = fh_get_record_width (w->fh);
+ size_t write_bytes = MIN (len, record_width);
+ size_t pad_bytes = record_width - write_bytes;
+ fwrite (rec, write_bytes, 1, w->file);
+ while (pad_bytes > 0)
+ {
+ static const char spaces[32] = " ";
+ size_t chunk = MIN (pad_bytes, sizeof spaces);
+ fwrite (spaces, chunk, 1, w->file);
+ pad_bytes -= chunk;
+ }
+ }
+ break;
+
+ default:
+ NOT_REACHED ();