Menu

#24 Global symbol ::timezone is non-portable, correct way is to call localtime()

None
closed-fixed
nobody
None
5
2017-03-04
2014-09-10
No

In 0.13.1beta (src/misc/clocks.cpp), in get_timezone_offset(), you get current timezone from global variable timezone, which is not guaranteed to exist by POSIX and thus code that uses it is not portable (e.g. ReZound now does not build on FreeBSD). Correct way to obtain timezone is to call localtime() as shown below:

time_t date = time(NULL);
int ret = localtime(&date)->tm_gmtoff;    // localtime() will call tzset() itself

This should work everywhere (e.g. both under GNU/Linux and *BSD). Patch is attached. Another bonus is that now you don't have to invert the sign. You might want to explicitly cast long tm_gmtoff to int at your discretion.

1 Attachments

Discussion

  • Davy Durham

    Davy Durham - 2017-03-04
    • status: open --> closed-fixed
    • Group: -->
     
  • Davy Durham

    Davy Durham - 2017-03-04

    was fixed in a previous patch

     

Log in to post a comment.