From 29f62852bda546248a2f3c8cb0f8cbbc7d6acc9f Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 27 Oct 2017 00:08:00 -0500 Subject: [PATCH] New port: MIT gettimeofday implementation (#2063) * [gettimeofday] create CONTROL * [gettimeofday] add source file * [gettimeofday] add header * [gettimeofday] create portfile * [gettimeofday] add cmakelists.txt * [gettimeofday/portfile] require static * [gettimeofday/portfile] set source path * [gettimeofday] create license * [gettimeofday] remove duplicate headers --- ports/gettimeofday/CMakeLists.txt | 14 ++++++ ports/gettimeofday/CONTROL | 3 ++ ports/gettimeofday/LICENSE | 33 ++++++++++++++ ports/gettimeofday/gettimeofday.c | 67 +++++++++++++++++++++++++++++ ports/gettimeofday/gettimeofday.def | 2 + ports/gettimeofday/gettimeofday.h | 16 +++++++ ports/gettimeofday/portfile.cmake | 11 +++++ 7 files changed, 146 insertions(+) create mode 100644 ports/gettimeofday/CMakeLists.txt create mode 100644 ports/gettimeofday/CONTROL create mode 100644 ports/gettimeofday/LICENSE create mode 100644 ports/gettimeofday/gettimeofday.c create mode 100644 ports/gettimeofday/gettimeofday.def create mode 100644 ports/gettimeofday/gettimeofday.h create mode 100644 ports/gettimeofday/portfile.cmake diff --git a/ports/gettimeofday/CMakeLists.txt b/ports/gettimeofday/CMakeLists.txt new file mode 100644 index 000000000..4ec5b43a0 --- /dev/null +++ b/ports/gettimeofday/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.8) +project(gettimeofday C) + +add_library(gettimeofday gettimeofday.c gettimeofday.def) + +install(TARGETS gettimeofday + RUNTIME DESTINATION bin + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib +) + +if(CMAKE_BUILD_TYPE STREQUAL "Release") + install(FILES gettimeofday.h DESTINATION include) +endif() diff --git a/ports/gettimeofday/CONTROL b/ports/gettimeofday/CONTROL new file mode 100644 index 000000000..2ec81c8a0 --- /dev/null +++ b/ports/gettimeofday/CONTROL @@ -0,0 +1,3 @@ +Source: gettimeofday +Version: 2017-10-14-1 +Description: An implementation of gettimeofday for WIN32 diff --git a/ports/gettimeofday/LICENSE b/ports/gettimeofday/LICENSE new file mode 100644 index 000000000..57c986d30 --- /dev/null +++ b/ports/gettimeofday/LICENSE @@ -0,0 +1,33 @@ +/* + * Copied from PostgreSQL source: + * http://doxygen.postgresql.org/gettimeofday_8c_source.html + * + */ + +/* + * gettimeofday.c + * Win32 gettimeofday() replacement + * + * src/port/gettimeofday.c + * + * Copyright (c) 2003 SRA, Inc. + * Copyright (c) 2003 SKC, Inc. + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose, without fee, and without a + * written agreement is hereby granted, provided that the above + * copyright notice and this paragraph and the following two + * paragraphs appear in all copies. + * + * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, + * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING + * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS + * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS + * IS" BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, + * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + */ diff --git a/ports/gettimeofday/gettimeofday.c b/ports/gettimeofday/gettimeofday.c new file mode 100644 index 000000000..62abf344a --- /dev/null +++ b/ports/gettimeofday/gettimeofday.c @@ -0,0 +1,67 @@ +/* + * Copied from PostgreSQL source: + * http://doxygen.postgresql.org/gettimeofday_8c_source.html + * + */ + +/* + * gettimeofday.c + * Win32 gettimeofday() replacement + * + * src/port/gettimeofday.c + * + * Copyright (c) 2003 SRA, Inc. + * Copyright (c) 2003 SKC, Inc. + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose, without fee, and without a + * written agreement is hereby granted, provided that the above + * copyright notice and this paragraph and the following two + * paragraphs appear in all copies. + * + * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, + * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING + * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS + * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS + * IS" BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, + * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + */ + +#ifdef _MSC_VER + +#include + + +/* FILETIME of Jan 1 1970 00:00:00. */ +static const unsigned __int64 epoch = 116444736000000000Ui64; + +/* + * timezone information is stored outside the kernel so tzp isn't used anymore. + * + * Note: this function is not for Win32 high precision timing purpose. See + * elapsed_time(). + */ +int +gettimeofday(struct timeval * tp, struct timezone * tzp) +{ + FILETIME file_time; + SYSTEMTIME system_time; + ULARGE_INTEGER ularge; + + GetSystemTime(&system_time); + SystemTimeToFileTime(&system_time, &file_time); + ularge.LowPart = file_time.dwLowDateTime; + ularge.HighPart = file_time.dwHighDateTime; + + tp->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L); + tp->tv_usec = (long) (system_time.wMilliseconds * 1000); + + return 0; +} + +#endif /* _MSC_VER */ diff --git a/ports/gettimeofday/gettimeofday.def b/ports/gettimeofday/gettimeofday.def new file mode 100644 index 000000000..7a46b866b --- /dev/null +++ b/ports/gettimeofday/gettimeofday.def @@ -0,0 +1,2 @@ +EXPORTS + gettimeofday diff --git a/ports/gettimeofday/gettimeofday.h b/ports/gettimeofday/gettimeofday.h new file mode 100644 index 000000000..94c58ea73 --- /dev/null +++ b/ports/gettimeofday/gettimeofday.h @@ -0,0 +1,16 @@ +#ifndef _MY_GETTIMEOFDAY_H_ +#define _MY_GETTIMEOFDAY_H_ + +#ifdef _MSC_VER + +#include +int gettimeofday(struct timeval * tp, struct timezone * tzp); + +struct timespec { + time_t tv_sec; + time_t tv_nsec; +}; + +#endif /* _MSC_VER */ + +#endif /* _MY_GETTIMEOFDAY_H_ */ diff --git a/ports/gettimeofday/portfile.cmake b/ports/gettimeofday/portfile.cmake new file mode 100644 index 000000000..51c88c989 --- /dev/null +++ b/ports/gettimeofday/portfile.cmake @@ -0,0 +1,11 @@ +include(vcpkg_common_functions) + +vcpkg_configure_cmake( + SOURCE_PATH ${CMAKE_CURRENT_LIST_DIR} + PREFER_NINJA +) + +vcpkg_install_cmake() +vcpkg_copy_pdbs() + +file(INSTALL ${CMAKE_CURRENT_LIST_DIR}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/gettimeofday RENAME copyright)