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