Commit c8206faf authored by Alfred Perlstein's avatar Alfred Perlstein Committed by Facebook GitHub Bot

use folly_struct_timezone to avoid name collision on win32 for polyfill

Summary:
On some WIN32 platforms #defines `timezone` as such we get a compilation
error due to name collision.

To fix let's use a folly_ prefix on our polyfill.

Reviewed By: yfeldblum

Differential Revision: D27220643

fbshipit-source-id: ccd4fa971388d53b8c5e8fba9f217776573ea370
parent fb645211
......@@ -21,7 +21,7 @@
#include <cstdint>
extern "C" {
int gettimeofday(timeval* tv, struct timezone*) {
int gettimeofday(timeval* tv, folly_port_struct_timezone*) {
constexpr auto posixWinFtOffset = 116444736000000000ULL;
if (tv) {
......
......@@ -17,26 +17,34 @@
#pragma once
#ifndef _WIN32
#include <sys/time.h>
// win32 #defines timezone; this avoids collision
using folly_port_struct_timezone = struct timezone;
#else
// Someone decided this was a good place to define timeval.....
#include <folly/portability/Windows.h>
struct timezone {
struct folly_port_struct_timezone_ {
int tz_minuteswest;
int tz_dsttime;
};
using folly_port_struct_timezone = struct folly_port_struct_timezone_;
extern "C" {
// Note that this needs to explicitly be `struct timezone` due to the fact that
// the python 3 headers `#define timezone _timezone` on Windows. `_timezone` is
// a global field that contains information on the current timezone. By
// explicitly specifying that this is a `struct`, we ensure that it's treated as
// a type, regardless of what name that type actually is :)
// Note that this will break if `gettimeofday` ever becomes declared as anything
// other than `extern "C"`, as the mangled name would be dependent on whether
// python had been included before this header.
int gettimeofday(timeval* tv, struct timezone*);
// We use folly_port_struct_timezone due to issues with #defines on Windows
// platforms.
// The python 3 headers `#define timezone _timezone` on Windows. `_timezone` is
// a global field that contains information on the current timezone.
// As such "timezone" is not a good name to use inside of C/C++ code on
// Windows. Instead users should use folly_port_struct_timezone instead.
int gettimeofday(timeval* tv, folly_port_struct_timezone*);
void timeradd(timeval* a, timeval* b, timeval* res);
void timersub(timeval* a, timeval* b, timeval* res);
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment