X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fsys-file-writer.c;h=df5108e2a062758ae79d561f5d1ee51b29a1c152;hb=259b5c32c06fd93964720f4a0e7844b5a24c55db;hp=1cad0110f9e03266a7cc329a3f5a8c85dcde6224;hpb=f93d0472eae9d03fb4bcd26a3d7a6301e32fbdde;p=pspp diff --git a/src/data/sys-file-writer.c b/src/data/sys-file-writer.c index 1cad0110f9..df5108e2a0 100644 --- a/src/data/sys-file-writer.c +++ b/src/data/sys-file-writer.c @@ -33,7 +33,6 @@ #include "data/casewriter.h" #include "data/dictionary.h" #include "data/file-handle-def.h" -#include "data/file-name.h" #include "data/format.h" #include "data/make-file.h" #include "data/missing-values.h" @@ -366,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; @@ -410,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 { @@ -430,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); @@ -716,14 +715,14 @@ put_attrset (struct string *string, const struct attrset *attrs) struct attrset_iterator i; for (attr = attrset_first (attrs, &i); attr != NULL; - attr = attrset_next (attrs, &i)) + attr = attrset_next (attrs, &i)) { size_t n_values = attribute_get_n_values (attr); size_t j; ds_put_cstr (string, attribute_get_name (attr)); ds_put_byte (string, '('); - for (j = 0; j < n_values; j++) + for (j = 0; j < n_values; j++) ds_put_format (string, "'%s'\n", attribute_get_value (attr, j)); ds_put_byte (string, ')'); } @@ -788,7 +787,7 @@ write_variable_attributes (struct sfm_writer *w, const struct dictionary *d) size_t i; for (i = 0; i < n_vars; i++) - { + { struct variable *v = dict_get_var (d, i); struct attrset attrs; @@ -1421,6 +1420,7 @@ finish_zstream (struct sfm_writer *w) block = &w->blocks[w->n_blocks++]; block->uncompressed_size = w->zstream.total_in; block->compressed_size = w->zstream.total_out; + deflateEnd (&w->zstream); } static void