LCOV - code coverage report
Current view: top level - src - ath.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 26 33 78.8 %
Date: 2016-09-12 12:35:26 Functions: 10 13 76.9 %

          Line data    Source code
       1             : /* ath.c - Thread-safeness library.
       2             :    Copyright (C) 2002, 2003, 2004 g10 Code GmbH
       3             : 
       4             :    This file is part of GPGME.
       5             : 
       6             :    GPGME is free software; you can redistribute it and/or modify it
       7             :    under the terms of the GNU Lesser General Public License as
       8             :    published by the Free Software Foundation; either version 2.1 of
       9             :    the License, or (at your option) any later version.
      10             : 
      11             :    GPGME is distributed in the hope that it will be useful, but
      12             :    WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :    Lesser General Public License for more details.
      15             : 
      16             :    You should have received a copy of the GNU Lesser General Public
      17             :    License along with this program; if not, write to the Free Software
      18             :    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
      19             :    02111-1307, USA.  */
      20             : 
      21             : #ifdef HAVE_CONFIG_H
      22             : #include <config.h>
      23             : #endif
      24             : 
      25             : #include <assert.h>
      26             : #ifdef HAVE_UNISTD_H
      27             : # include <unistd.h>
      28             : #endif
      29             : #ifdef HAVE_SYS_SELECT_H
      30             : # include <sys/select.h>
      31             : #else
      32             : # ifdef HAVE_SYS_TIME_H
      33             : #  include <sys/time.h>
      34             : # endif
      35             : #endif
      36             : #ifdef HAVE_SYS_TYPES_H
      37             : # include <sys/types.h>
      38             : #endif
      39             : #ifndef HAVE_W32_SYSTEM
      40             : #include <sys/wait.h>
      41             : #endif
      42             : 
      43             : #include "gpgme.h"
      44             : 
      45             : #ifdef _MSC_VER
      46             :   typedef int  pid_t;
      47             : #endif
      48             : 
      49             : #include "ath.h"
      50             : 
      51             : 
      52             : #define MUTEX_UNLOCKED  ((ath_mutex_t) 0)
      53             : #define MUTEX_LOCKED    ((ath_mutex_t) 1)
      54             : #define MUTEX_DESTROYED ((ath_mutex_t) 2)
      55             : 
      56             : 
      57             : #ifdef HAVE_W32_SYSTEM
      58             : #include <windows.h>
      59             : uintptr_t
      60             : ath_self (void)
      61             : {
      62             :   return (uintptr_t) GetCurrentThreadId ();
      63             : }
      64             : #else
      65             : # ifdef __linux
      66             : #include <sys/syscall.h>
      67             : uintptr_t
      68           0 : ath_self (void)
      69             : {
      70             :   /* Just to catch users who don't use gpgme-pthread.  */
      71           0 :   return (uintptr_t) syscall (__NR_gettid);
      72             : }
      73             : # else
      74             : uintptr_t
      75             : ath_self (void)
      76             : {
      77             :   return (uintptr_t) getpid ();
      78             : }
      79             : # endif
      80             : #endif
      81             : 
      82             : 
      83             : int
      84           0 : ath_mutex_init (ath_mutex_t *lock)
      85             : {
      86             : #ifndef NDEBUG
      87           0 :   *lock = MUTEX_UNLOCKED;
      88             : #endif
      89           0 :   return 0;
      90             : }
      91             : 
      92             : 
      93             : int
      94         145 : ath_mutex_destroy (ath_mutex_t *lock)
      95             : {
      96             : #ifndef NDEBUG
      97         145 :   assert (*lock == MUTEX_UNLOCKED);
      98             : 
      99         145 :   *lock = MUTEX_DESTROYED;
     100             : #endif
     101         145 :   return 0;
     102             : }
     103             : 
     104             : 
     105             : int
     106        7252 : ath_mutex_lock (ath_mutex_t *lock)
     107             : {
     108             : #ifndef NDEBUG
     109        7252 :   assert (*lock == MUTEX_UNLOCKED);
     110             : 
     111        7252 :   *lock = MUTEX_LOCKED;
     112             : #endif
     113        7252 :   return 0;
     114             : }
     115             : 
     116             : 
     117             : int
     118        7252 : ath_mutex_unlock (ath_mutex_t *lock)
     119             : {
     120             : #ifndef NDEBUG
     121        7252 :   assert (*lock == MUTEX_LOCKED);
     122             : 
     123        7252 :   *lock = MUTEX_UNLOCKED;
     124             : #endif
     125        7252 :   return 0;
     126             : }
     127             : 
     128             : 
     129             : gpgme_ssize_t
     130        2053 : ath_read (int fd, void *buf, size_t nbytes)
     131             : {
     132             : #if defined(HAVE_W32CE_SYSTEM) && defined(_MSC_VER)
     133             :   return -1; /* Not supported. */
     134             : #else
     135        2053 :   return read (fd, buf, nbytes);
     136             : #endif
     137             : }
     138             : 
     139             : 
     140             : gpgme_ssize_t
     141         494 : ath_write (int fd, const void *buf, size_t nbytes)
     142             : {
     143             : #if defined(HAVE_W32CE_SYSTEM) && defined(_MSC_VER)
     144             :   return -1; /* Not supported. */
     145             : #else
     146         494 :   return write (fd, buf, nbytes);
     147             : #endif
     148             : }
     149             : 
     150             : 
     151             : gpgme_ssize_t
     152        4288 : ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset,
     153             :             struct timeval *timeout)
     154             : {
     155             : #ifdef HAVE_W32_SYSTEM
     156             :   return -1; /* Not supported. */
     157             : #else
     158        4288 :   return select (nfd, rset, wset, eset, timeout);
     159             : #endif
     160             : }
     161             : 
     162             : 
     163             : gpgme_ssize_t
     164         513 : ath_waitpid (pid_t pid, int *status, int options)
     165             : {
     166             : #ifdef HAVE_W32_SYSTEM
     167             :   return -1; /* Not supported. */
     168             : #else
     169         513 :   return waitpid (pid, status, options);
     170             : #endif
     171             : }
     172             : 
     173             : 
     174             : int
     175           0 : ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr)
     176             : {
     177             : #ifdef HAVE_W32_SYSTEM
     178             :   return -1; /* Not supported. */
     179             : #else
     180           0 :   return accept (s, addr, length_ptr);
     181             : #endif
     182             : }
     183             : 
     184             : 
     185             : int
     186           1 : ath_connect (int s, const struct sockaddr *addr, socklen_t length)
     187             : {
     188             : #ifdef HAVE_W32_SYSTEM
     189             :   return -1; /* Not supported. */
     190             : #else
     191           1 :   return connect (s, addr, length);
     192             : #endif
     193             : }
     194             : 
     195             : 
     196             : int
     197         240 : ath_sendmsg (int s, const struct msghdr *msg, int flags)
     198             : {
     199             : #ifdef HAVE_W32_SYSTEM
     200             :   return -1; /* Not supported. */
     201             : #else
     202         240 :   return sendmsg (s, msg, flags);
     203             : #endif
     204             : }
     205             : 
     206             : 
     207             : int
     208         125 : ath_recvmsg (int s, struct msghdr *msg, int flags)
     209             : {
     210             : #ifdef HAVE_W32_SYSTEM
     211             :   return -1; /* Not supported. */
     212             : #else
     213         125 :   return recvmsg (s, msg, flags);
     214             : #endif
     215             : }

Generated by: LCOV version 1.11