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 : #ifdef HAVE_W32_SYSTEM
53 : #include <windows.h>
54 : uintptr_t
55 : ath_self (void)
56 : {
57 : return (uintptr_t) GetCurrentThreadId ();
58 : }
59 : #else
60 : # ifdef __linux
61 : #include <sys/syscall.h>
62 : uintptr_t
63 0 : ath_self (void)
64 : {
65 : /* Just to catch users who don't use gpgme-pthread. */
66 0 : return (uintptr_t) syscall (__NR_gettid);
67 : }
68 : # else
69 : uintptr_t
70 : ath_self (void)
71 : {
72 : return (uintptr_t) getpid ();
73 : }
74 : # endif
75 : #endif
76 :
77 :
78 : gpgme_ssize_t
79 7230 : ath_read (int fd, void *buf, size_t nbytes)
80 : {
81 : #if defined(HAVE_W32CE_SYSTEM) && defined(_MSC_VER)
82 : return -1; /* Not supported. */
83 : #else
84 7230 : return read (fd, buf, nbytes);
85 : #endif
86 : }
87 :
88 :
89 : gpgme_ssize_t
90 804 : ath_write (int fd, const void *buf, size_t nbytes)
91 : {
92 : #if defined(HAVE_W32CE_SYSTEM) && defined(_MSC_VER)
93 : return -1; /* Not supported. */
94 : #else
95 804 : return write (fd, buf, nbytes);
96 : #endif
97 : }
98 :
99 :
100 : gpgme_ssize_t
101 12195 : ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset,
102 : struct timeval *timeout)
103 : {
104 : #ifdef HAVE_W32_SYSTEM
105 : return -1; /* Not supported. */
106 : #else
107 12195 : return select (nfd, rset, wset, eset, timeout);
108 : #endif
109 : }
110 :
111 :
112 : gpgme_ssize_t
113 1734 : ath_waitpid (pid_t pid, int *status, int options)
114 : {
115 : #ifdef HAVE_W32_SYSTEM
116 : return -1; /* Not supported. */
117 : #else
118 1734 : return waitpid (pid, status, options);
119 : #endif
120 : }
121 :
122 :
123 : int
124 0 : ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr)
125 : {
126 : #ifdef HAVE_W32_SYSTEM
127 : return -1; /* Not supported. */
128 : #else
129 0 : return accept (s, addr, length_ptr);
130 : #endif
131 : }
132 :
133 :
134 : int
135 12 : ath_connect (int s, const struct sockaddr *addr, socklen_t length)
136 : {
137 : #ifdef HAVE_W32_SYSTEM
138 : return -1; /* Not supported. */
139 : #else
140 12 : return connect (s, addr, length);
141 : #endif
142 : }
143 :
144 :
145 : int
146 240 : ath_sendmsg (int s, const struct msghdr *msg, int flags)
147 : {
148 : #ifdef HAVE_W32_SYSTEM
149 : return -1; /* Not supported. */
150 : #else
151 240 : return sendmsg (s, msg, flags);
152 : #endif
153 : }
154 :
155 :
156 : int
157 123 : ath_recvmsg (int s, struct msghdr *msg, int flags)
158 : {
159 : #ifdef HAVE_W32_SYSTEM
160 : return -1; /* Not supported. */
161 : #else
162 123 : return recvmsg (s, msg, flags);
163 : #endif
164 : }
|