LCOV - code coverage report
Current view: top level - builds/gnutls/coverage/gnutls-git/lib - system.c (source / functions) Hit Total Coverage
Test: GnuTLS-3.6.14 Code Coverage Lines: 14 14 100.0 %
Date: 2020-10-30 04:50:48 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 2010-2016 Free Software Foundation, Inc.
       3             :  * Copyright (C) 2015-2016 Red Hat, Inc.
       4             :  *
       5             :  * Author: Nikos Mavrogiannopoulos
       6             :  *
       7             :  * This file is part of GnuTLS.
       8             :  *
       9             :  * The GnuTLS is free software; you can redistribute it and/or
      10             :  * modify it under the terms of the GNU Lesser General Public License
      11             :  * as published by the Free Software Foundation; either version 2.1 of
      12             :  * the License, or (at your option) any later version.
      13             :  *
      14             :  * This library is distributed in the hope that it will be useful, but
      15             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17             :  * Lesser General Public License for more details.
      18             :  *
      19             :  * You should have received a copy of the GNU Lesser General Public License
      20             :  * along with this program.  If not, see <https://www.gnu.org/licenses/>
      21             :  *
      22             :  */
      23             : 
      24             : #include <config.h>
      25             : #include <system.h>
      26             : #include "gnutls_int.h"
      27             : #include "errors.h"
      28             : 
      29             : #include <sys/socket.h>
      30             : #include <errno.h>
      31             : #include <sys/stat.h>
      32             : #include <sys/types.h>
      33             : #include <time.h>
      34             : 
      35             : #ifdef _WIN32
      36             : # include <windows.h>
      37             : # include <wincrypt.h>
      38             : # if defined(NEED_CERT_ENUM_CRLS)
      39             : CertEnumCRLsInStoreFunc pCertEnumCRLsInStore;
      40             : static HMODULE Crypt32_dll;
      41             : # endif
      42             : #endif
      43             : 
      44             : /* System specific function wrappers for certificate stores.
      45             :  */
      46             : gnutls_time_func gnutls_time;
      47             : gnutls_gettime_func gnutls_gettime;
      48             : 
      49             : /* emulate gnulib's gettime using gettimeofday to avoid linking to
      50             :  * librt */
      51    31457000 : static void _gnutls_gettime(struct timespec *t)
      52             : {
      53             : #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
      54    31457000 :         clock_gettime(CLOCK_REALTIME, t);
      55             : #else
      56             :         struct timeval tv;
      57             :         gettimeofday(&tv, NULL);
      58             :         t->tv_sec = tv.tv_sec;
      59             :         t->tv_nsec = tv.tv_usec * 1000;
      60             : #endif
      61    31457000 : }
      62             : 
      63         657 : void _gnutls_global_set_gettime_function(gnutls_gettime_func gettime_func)
      64             : {
      65         657 :         gnutls_gettime = gettime_func;
      66         657 : }
      67             : 
      68        3387 : int gnutls_system_global_init(void)
      69             : {
      70             : #if defined(_WIN32) && defined(NEED_CERT_ENUM_CRLS)
      71             :         /* used in system/certs.c */
      72             :         HMODULE crypto;
      73             :         crypto = LoadLibrary(TEXT("Crypt32.dll"));
      74             : 
      75             :         if (crypto == NULL)
      76             :                 return GNUTLS_E_CRYPTO_INIT_FAILED;
      77             : 
      78             :         pCertEnumCRLsInStore =
      79             :             (CertEnumCRLsInStoreFunc) GetProcAddress(crypto,
      80             :                                                       "CertEnumCRLsInStore");
      81             :         if (pCertEnumCRLsInStore == NULL) {
      82             :                 FreeLibrary(crypto);
      83             :                 return GNUTLS_E_CRYPTO_INIT_FAILED;
      84             :         }
      85             : 
      86             :         Crypt32_dll = crypto;
      87             : #endif
      88        3387 :         gnutls_time = time;
      89        3387 :         gnutls_gettime = _gnutls_gettime;
      90        3387 :         return 0;
      91             : }
      92             : 
      93        2185 : void gnutls_system_global_deinit(void)
      94             : {
      95             : #if defined(_WIN32) && defined(NEED_CERT_ENUM_CRLS)
      96             :         FreeLibrary(Crypt32_dll);
      97             : #endif
      98        2185 :         gnutls_time = time;
      99        2185 :         gnutls_gettime = _gnutls_gettime;
     100        2185 : }
     101             : 
     102             : 

Generated by: LCOV version 1.14