1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. 2 // This source code is licensed under both the GPLv2 (found in the 3 // COPYING file in the root directory) and Apache 2.0 License 4 // (found in the LICENSE.Apache file in the root directory). 5 // 6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 7 // Use of this source code is governed by a BSD-style license that can be 8 // found in the LICENSE file. See the AUTHORS file for names of contributors. 9 10 // This file is a portable substitute for sys/time.h which does not exist on 11 // Windows 12 13 #pragma once 14 15 #if defined(OS_WIN) && defined(_MSC_VER) 16 17 #include <time.h> 18 19 #include "rocksdb/rocksdb_namespace.h" 20 21 namespace ROCKSDB_NAMESPACE { 22 23 namespace port { 24 25 // Avoid including winsock2.h for this definition 26 typedef struct timeval { 27 long tv_sec; 28 long tv_usec; 29 } timeval; 30 31 void gettimeofday(struct timeval* tv, struct timezone* tz); 32 localtime_r(const time_t * timep,struct tm * result)33inline struct tm* localtime_r(const time_t* timep, struct tm* result) { 34 errno_t ret = localtime_s(result, timep); 35 return (ret == 0) ? result : NULL; 36 } 37 } 38 39 using port::timeval; 40 using port::gettimeofday; 41 using port::localtime_r; 42 } // namespace ROCKSDB_NAMESPACE 43 44 #else 45 #include <time.h> 46 #include <sys/time.h> 47 #endif 48