Path: blob/main/crypto/libecc/src/external_deps/time.c
34878 views
/*1* Copyright (C) 2017 - This file is part of libecc project2*3* Authors:4* Ryad BENADJILA <[email protected]>5* Arnaud EBALARD <[email protected]>6* Jean-Pierre FLORI <[email protected]>7*8* Contributors:9* Nicolas VIVET <[email protected]>10* Karim KHALFALLAH <[email protected]>11*12* This software is licensed under a dual BSD and GPL v2 license.13* See LICENSE file at the root folder of the project.14*/1516#include <libecc/external_deps/time.h>1718/* Unix and compatible case (including macOS) */19#if defined(WITH_STDLIB) && (defined(__unix__) || defined(__APPLE__))20#include <stddef.h>21#include <sys/time.h>2223int get_ms_time(u64 *time)24{25struct timeval tv;26int ret;2728if (time == NULL) {29ret = -1;30goto err;31}3233ret = gettimeofday(&tv, NULL);34if (ret < 0) {35ret = -1;36goto err;37}3839(*time) = (u64)(((tv.tv_sec) * 1000) + ((tv.tv_usec) / 1000));40ret = 0;4142err:43return ret;44}4546/* Windows case */47#elif defined(WITH_STDLIB) && defined(__WIN32__)48#include <stddef.h>49#include <windows.h>50int get_ms_time(u64 *time)51{52int ret;53SYSTEMTIME st;5455if (time == NULL) {56ret = -1;57goto err;58}5960GetSystemTime(&st);61(*time) = (u64)((((st.wMinute * 60) + st.wSecond) * 1000) + st.wMilliseconds);62ret = 0;6364err:65return ret;66}6768/* No platform detected, the used must provide an implementation! */69#else70#error "time.c: you have to implement get_ms_time()"71#endif727374