# HG changeset patch # User Mike Miller # Date 1437748805 14400 # Node ID 6bc09e953927d8a9052e88ba71ad7cd5ce54ae8b # Parent c16c446204e5564d26051f8884f39ba5e55ed9d0 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. diff --git a/libinterp/corefcn/load-save.cc b/libinterp/corefcn/load-save.cc --- a/libinterp/corefcn/load-save.cc +++ b/libinterp/corefcn/load-save.cc @@ -1204,16 +1204,17 @@ { char const * versionmagic; int16_t number = *(reinterpret_cast("\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 (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