sys_time.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. // This file is a portable substitute for sys/time.h which does not exist on
  10. // Windows
  11. #pragma once
  12. #if defined(OS_WIN) && defined(_MSC_VER)
  13. #include <time.h>
  14. #include "rocksdb/rocksdb_namespace.h"
  15. namespace ROCKSDB_NAMESPACE {
  16. namespace port {
  17. // Avoid including winsock2.h for this definition
  18. typedef struct timeval {
  19. long tv_sec;
  20. long tv_usec;
  21. } timeval;
  22. void gettimeofday(struct timeval* tv, struct timezone* tz);
  23. inline struct tm* localtime_r(const time_t* timep, struct tm* result) {
  24. errno_t ret = localtime_s(result, timep);
  25. return (ret == 0) ? result : NULL;
  26. }
  27. }
  28. using port::timeval;
  29. using port::gettimeofday;
  30. using port::localtime_r;
  31. } // namespace ROCKSDB_NAMESPACE
  32. #else
  33. #include <time.h>
  34. #include <sys/time.h>
  35. #endif