X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fsys-file-writer.c;h=7a0fb5a691280ca3e4c542c1dbc3a9ebc09e92c3;hb=bd5e8f74de87b9061ff62615f48fb378e844e87d;hp=7f0c8c056abb1d0f39bb564bd62ae5d2f4f4d17a;hpb=3dd0f6ae0d5eb73a2270a243e443c4ae03c2c16e;p=pspp diff --git a/src/data/sys-file-writer.c b/src/data/sys-file-writer.c index 7f0c8c056a..7a0fb5a691 100644 --- a/src/data/sys-file-writer.c +++ b/src/data/sys-file-writer.c @@ -365,8 +365,6 @@ write_header (struct sfm_writer *w, const struct dictionary *d) { const char *dict_encoding = dict_get_encoding (d); char prod_name[61]; - char creation_date[10]; - char creation_time[9]; const char *file_label; struct variable *weight; @@ -409,10 +407,11 @@ write_header (struct sfm_writer *w, const struct dictionary *d) write_float (w, COMPRESSION_BIAS); /* Creation date and time. */ + char *creation_date, *creation_time; if (time (&t) == (time_t) -1) { - strcpy (creation_date, "01 Jan 70"); - strcpy (creation_time, "00:00:00"); + creation_date = xstrdup ("01 Jan 70"); + creation_time = xstrdup ("00:00:00"); } else { @@ -429,13 +428,14 @@ write_header (struct sfm_writer *w, const struct dictionary *d) int min = rerange (tmp->tm_min + 1); int sec = rerange (tmp->tm_sec + 1); - snprintf (creation_date, sizeof creation_date, - "%02d %s %02d", day, month_name[mon - 1], year); - snprintf (creation_time, sizeof creation_time, - "%02d:%02d:%02d", hour - 1, min - 1, sec - 1); + creation_date = xasprintf ("%02d %s %02d", + day, month_name[mon - 1], year); + creation_time = xasprintf ("%02d:%02d:%02d", hour - 1, min - 1, sec - 1); } write_utf8_string (w, dict_encoding, creation_date, 9); write_utf8_string (w, dict_encoding, creation_time, 8); + free (creation_time); + free (creation_date); /* File label. */ file_label = dict_get_label (d); @@ -507,6 +507,7 @@ write_variable (struct sfm_writer *w, const struct variable *v) Missing values for long string variables are written in a separate record. */ + enum { MAX_SHORT_STRING = 8 }; if (width <= MAX_SHORT_STRING) { const struct missing_values *mv = var_get_missing_values (v); @@ -853,8 +854,7 @@ write_mrsets (struct sfm_writer *w, const struct dictionary *dict, if (mrset->width == 0) counted = xasprintf ("%.0f", mrset->counted.f); else - counted = xmemdup0 (value_str (&mrset->counted, mrset->width), - mrset->width); + counted = xmemdup0 (mrset->counted.s, mrset->width); ds_put_format (&s, "%zu %s", strlen (counted), counted); free (counted); } @@ -953,7 +953,6 @@ write_long_string_value_labels (struct sfm_writer *w, const char *encoding = dict_get_encoding (dict); size_t n_vars = dict_get_var_cnt (dict); size_t size, i; - off_t start UNUSED; /* Figure out the size in advance. */ size = 0; @@ -985,7 +984,6 @@ write_long_string_value_labels (struct sfm_writer *w, write_int (w, 1); /* Data item (byte) size. */ write_int (w, size); /* Number of data items. */ - start = ftello (w->file); for (i = 0; i < n_vars; i++) { struct variable *var = dict_get_var (dict, i); @@ -1011,8 +1009,7 @@ write_long_string_value_labels (struct sfm_writer *w, size_t len; write_int (w, width); - write_bytes (w, value_str (val_lab_get_value (val_lab), width), - width); + write_bytes (w, val_lab_get_value (val_lab)->s, width); label = recode_string (var_get_encoding (var), "UTF-8", val_lab_get_escaped_label (val_lab), -1); @@ -1022,7 +1019,6 @@ write_long_string_value_labels (struct sfm_writer *w, free (label); } } - assert (ftello (w->file) == start + size); } static void @@ -1032,7 +1028,6 @@ write_long_string_missing_values (struct sfm_writer *w, const char *encoding = dict_get_encoding (dict); size_t n_vars = dict_get_var_cnt (dict); size_t size, i; - off_t start UNUSED; /* Figure out the size in advance. */ size = 0; @@ -1058,7 +1053,6 @@ write_long_string_missing_values (struct sfm_writer *w, write_int (w, 1); /* Data item (byte) size. */ write_int (w, size); /* Number of data items. */ - start = ftello (w->file); for (i = 0; i < n_vars; i++) { struct variable *var = dict_get_var (dict, i); @@ -1084,10 +1078,9 @@ write_long_string_missing_values (struct sfm_writer *w, const union value *value = mv_get_value (mv, j); write_int (w, 8); - write_bytes (w, value_str (value, width), 8); + write_bytes (w, value->s, 8); } } - assert (ftello (w->file) == start + size); } static void @@ -1598,7 +1591,7 @@ write_value (struct sfm_writer *w, const union value *value, int width) write_float (w, value->f); else { - write_bytes (w, value_str (value, width), width); + write_bytes (w, value->s, width); write_zeros (w, 8 - width); } }