changeset 20424:6bc09e953927

Use octave_gmtime to write timestamp to mat-file format * load-save.cc (write_header): Use octave_gmtime to write file header timestamp rather than call nstrftime directly.
author Mike Miller <mtmiller@octave.org>
date Fri, 24 Jul 2015 10:40:05 -0400
parents c16c446204e5
children 41d19a6ef55a
files libinterp/corefcn/load-save.cc
diffstat 1 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/load-save.cc	Thu Jul 23 22:35:34 2015 -0400
+++ b/libinterp/corefcn/load-save.cc	Fri Jul 24 10:40:05 2015 -0400
@@ -1204,16 +1204,17 @@
       {
         char const * versionmagic;
         int16_t number = *(reinterpret_cast<const int16_t *>("\x00\x01"));
-        struct tm bdt;
-        time_t now;
         char headertext[128];
+        octave_gmtime now;
 
-        time (&now);
-        bdt = *gnulib::gmtime (&now);
+        // ISO 8601 format date
+        const char *matlab_format = "MATLAB 5.0 MAT-file, written by Octave "
+            OCTAVE_VERSION ", %Y-%m-%d %T UTC";
+        std::string comment_string = now.strftime (matlab_format);
+
+        size_t len = std::min (comment_string.length (), static_cast<size_t> (124));
         memset (headertext, ' ', 124);
-        // ISO 8601 format date
-        nstrftime (headertext, 124, "MATLAB 5.0 MAT-file, written by Octave "
-                   OCTAVE_VERSION ", %Y-%m-%d %T UTC", &bdt, 1, 0);
+        memcpy (headertext, comment_string.data (), len);
 
         // The first pair of bytes give the version of the MAT file
         // format.  The second pair of bytes form a magic number which