X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fmsglog.c;h=ef2cf6b007deef169f6481b32ef7d5c80352479c;hb=f8cba0fb13cceeac43fe4b15e2d5b48798ab1a6e;hp=a3f195410406b70c6f18c00d57578d9cf6cf8fd6;hpb=fce028c380d496e42823fd24774e0159ed7cc110;p=pspp diff --git a/src/output/msglog.c b/src/output/msglog.c index a3f1954104..ef2cf6b007 100644 --- a/src/output/msglog.c +++ b/src/output/msglog.c @@ -24,6 +24,7 @@ #include #include "data/file-name.h" +#include "data/file-handle-def.h" #include "data/settings.h" #include "libpspp/cast.h" #include "libpspp/message.h" @@ -40,8 +41,7 @@ struct msglog_driver { struct output_driver driver; FILE *file; - char *file_name; - char *command_name; + struct file_handle *handle; }; static const struct output_driver_class msglog_class; @@ -60,7 +60,9 @@ msglog_create (const char *file_name) struct msglog_driver *ml; FILE *file; - file = fn_open (file_name, "w"); + struct file_handle *handle = fh_create_file (NULL, file_name, NULL, fh_default_properties ()); + + file = fn_open (handle, "w"); if (file == NULL) { msg_error (errno, _("error opening output file `%s'"), file_name); @@ -72,10 +74,9 @@ msglog_create (const char *file_name) : SETTINGS_DEVICE_UNFILTERED); ml = xzalloc (sizeof *ml); + ml->handle = handle; output_driver_init (&ml->driver, &msglog_class, file_name, type); ml->file = file; - ml->file_name = xstrdup (file_name); - ml->command_name = NULL; output_driver_register (&ml->driver); @@ -87,9 +88,8 @@ msglog_destroy (struct output_driver *driver) { struct msglog_driver *ml = msglog_driver_cast (driver); - fn_close (ml->file_name, ml->file); - free (ml->file_name); - free (ml->command_name); + fn_close (ml->handle, ml->file); + fh_unref (ml->handle); free (ml); } @@ -98,13 +98,10 @@ msglog_submit (struct output_driver *driver, const struct output_item *item) { struct msglog_driver *ml = msglog_driver_cast (driver); - output_driver_track_current_command (item, &ml->command_name); - if (is_message_item (item)) { const struct message_item *message_item = to_message_item (item); - const struct msg *msg = message_item_get_msg (message_item); - char *s = msg_to_string (msg, ml->command_name); + char *s = msg_to_string (message_item_get_msg (message_item)); fprintf (ml->file, "%s\n", s); free (s); }