]> git.tdb.fi Git - libs/core.git/blobdiff - source/time/timezone.cpp
Variable length arrays on stack are not valid C++
[libs/core.git] / source / time / timezone.cpp
index 0ec9d2b8e4137300f3139bfb2f5661e7fe3a0764..a2cd7a3f772743c7fe9ac06fde3042fd6ab28d98 100644 (file)
@@ -1,18 +1,12 @@
-/* $Id$
-
-This file is part of libmspcore
-Copyright © 2008-2009  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <cstdlib>
 #ifdef WIN32
 #include <windows.h>
 #else
+#include <unistd.h>
 #include <fcntl.h>
 #endif
 #include <msp/strings/format.h>
-#include "../core/except.h"
+#include <msp/core/systemerror.h>
 #include "timestamp.h"
 #include "timezone.h"
 #include "units.h"
@@ -40,7 +34,7 @@ TimeZone get_local_timezone()
        TIME_ZONE_INFORMATION tzinfo;
        DWORD dst = GetTimeZoneInformation(&tzinfo);
        if(dst==TIME_ZONE_ID_INVALID)
-               throw Msp::SystemError("Failed to get time zone information", GetLastError());
+               throw Msp::system_error("GetTimeZoneInformation");
 
        int offset = tzinfo.Bias;
        if(dst==TIME_ZONE_ID_STANDARD)
@@ -51,7 +45,7 @@ TimeZone get_local_timezone()
        return TimeZone(offset);
 #else
        int fd = open("/etc/localtime", O_RDONLY);
-       if(fd>=-1)
+       if(fd!=-1)
        {
                char hdr[44];
                int len = read(fd, hdr, sizeof(hdr));
@@ -67,7 +61,7 @@ TimeZone get_local_timezone()
                        long typecnt = get_long(ptr);
                        long charcnt = get_long(ptr);
                        int size = timecnt*5+typecnt*6+isgmtcnt+isstdcnt+leapcnt*8+charcnt;
-                       char buf[size];
+                       char *buf = new char[size];
                        len = read(fd, buf, size);
                        if(len==size)
                        {
@@ -97,6 +91,7 @@ TimeZone get_local_timezone()
 
                                name = ptr+abbrind;
                        }
+                       delete[] buf;
                }
                close(fd);