Blame src/ath.c

Packit Service 672cf4
/* ath.c - Thread-safeness library.
Packit Service 6c01f9
   Copyright (C) 2002, 2003, 2004 g10 Code GmbH
Packit Service 6c01f9
Packit Service 6c01f9
   This file is part of GPGME.
Packit Service 6c01f9
Packit Service 6c01f9
   GPGME is free software; you can redistribute it and/or modify it
Packit Service 6c01f9
   under the terms of the GNU Lesser General Public License as
Packit Service 6c01f9
   published by the Free Software Foundation; either version 2.1 of
Packit Service 6c01f9
   the License, or (at your option) any later version.
Packit Service 6c01f9
Packit Service 6c01f9
   GPGME is distributed in the hope that it will be useful, but
Packit Service 6c01f9
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 6c01f9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 6c01f9
   Lesser General Public License for more details.
Packit Service 6c01f9
Packit Service 6c01f9
   You should have received a copy of the GNU Lesser General Public
Packit Service 6c01f9
   License along with this program; if not, write to the Free Software
Packit Service 6c01f9
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
Packit Service 6c01f9
   02111-1307, USA.  */
Packit Service 672cf4
Packit Service 672cf4
#ifdef HAVE_CONFIG_H
Packit Service 672cf4
#include <config.h>
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
#include <assert.h>
Packit Service 672cf4
#ifdef HAVE_UNISTD_H
Packit Service 672cf4
# include <unistd.h>
Packit Service 672cf4
#endif
Packit Service 672cf4
#ifdef HAVE_SYS_SELECT_H
Packit Service 672cf4
# include <sys/select.h>
Packit Service 672cf4
#else
Packit Service 672cf4
# ifdef HAVE_SYS_TIME_H
Packit Service 672cf4
#  include <sys/time.h>
Packit Service 672cf4
# endif
Packit Service 672cf4
#endif
Packit Service 672cf4
#ifdef HAVE_SYS_TYPES_H
Packit Service 672cf4
# include <sys/types.h>
Packit Service 672cf4
#endif
Packit Service 672cf4
#ifndef HAVE_W32_SYSTEM
Packit Service 672cf4
#include <sys/wait.h>
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
#include "gpgme.h"
Packit Service 672cf4
Packit Service 672cf4
#ifdef _MSC_VER
Packit Service 672cf4
  typedef int  pid_t;
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
#include "ath.h"
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
#ifdef HAVE_W32_SYSTEM
Packit Service 672cf4
#include <windows.h>
Packit Service 672cf4
uintptr_t
Packit Service 672cf4
ath_self (void)
Packit Service 672cf4
{
Packit Service 672cf4
  return (uintptr_t) GetCurrentThreadId ();
Packit Service 672cf4
}
Packit Service 672cf4
#else
Packit Service 672cf4
# ifdef __linux
Packit Service 672cf4
#include <sys/syscall.h>
Packit Service 672cf4
uintptr_t
Packit Service 672cf4
ath_self (void)
Packit Service 672cf4
{
Packit Service 672cf4
  /* Just to catch users who don't use gpgme-pthread.  */
Packit Service 672cf4
  return (uintptr_t) syscall (__NR_gettid);
Packit Service 672cf4
}
Packit Service 672cf4
# else
Packit Service 672cf4
uintptr_t
Packit Service 672cf4
ath_self (void)
Packit Service 672cf4
{
Packit Service 672cf4
  return (uintptr_t) getpid ();
Packit Service 672cf4
}
Packit Service 672cf4
# endif
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
gpgme_ssize_t
Packit Service 672cf4
ath_read (int fd, void *buf, size_t nbytes)
Packit Service 672cf4
{
Packit Service 6c01f9
#if defined(HAVE_W32CE_SYSTEM) && defined(_MSC_VER)
Packit Service 6c01f9
  return -1; /* Not supported. */
Packit Service 6c01f9
#else
Packit Service 672cf4
  return read (fd, buf, nbytes);
Packit Service 6c01f9
#endif
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
gpgme_ssize_t
Packit Service 672cf4
ath_write (int fd, const void *buf, size_t nbytes)
Packit Service 672cf4
{
Packit Service 6c01f9
#if defined(HAVE_W32CE_SYSTEM) && defined(_MSC_VER)
Packit Service 6c01f9
  return -1; /* Not supported. */
Packit Service 6c01f9
#else
Packit Service 672cf4
  return write (fd, buf, nbytes);
Packit Service 6c01f9
#endif
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
gpgme_ssize_t
Packit Service 672cf4
ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset,
Packit Service 672cf4
	    struct timeval *timeout)
Packit Service 672cf4
{
Packit Service 672cf4
#ifdef HAVE_W32_SYSTEM
Packit Service 672cf4
  return -1; /* Not supported. */
Packit Service 672cf4
#else
Packit Service 672cf4
  return select (nfd, rset, wset, eset, timeout);
Packit Service 672cf4
#endif
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
gpgme_ssize_t
Packit Service 672cf4
ath_waitpid (pid_t pid, int *status, int options)
Packit Service 672cf4
{
Packit Service 672cf4
#ifdef HAVE_W32_SYSTEM
Packit Service 672cf4
  return -1; /* Not supported. */
Packit Service 672cf4
#else
Packit Service 672cf4
  return waitpid (pid, status, options);
Packit Service 672cf4
#endif
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
int
Packit Service 672cf4
ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr)
Packit Service 672cf4
{
Packit Service 672cf4
#ifdef HAVE_W32_SYSTEM
Packit Service 672cf4
  return -1; /* Not supported. */
Packit Service 672cf4
#else
Packit Service 672cf4
  return accept (s, addr, length_ptr);
Packit Service 672cf4
#endif
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
int
Packit Service 672cf4
ath_connect (int s, const struct sockaddr *addr, socklen_t length)
Packit Service 672cf4
{
Packit Service 672cf4
#ifdef HAVE_W32_SYSTEM
Packit Service 672cf4
  return -1; /* Not supported. */
Packit Service 672cf4
#else
Packit Service 672cf4
  return connect (s, addr, length);
Packit Service 672cf4
#endif
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
int
Packit Service 672cf4
ath_sendmsg (int s, const struct msghdr *msg, int flags)
Packit Service 672cf4
{
Packit Service 672cf4
#ifdef HAVE_W32_SYSTEM
Packit Service 672cf4
  return -1; /* Not supported. */
Packit Service 672cf4
#else
Packit Service 672cf4
  return sendmsg (s, msg, flags);
Packit Service 672cf4
#endif
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
int
Packit Service 672cf4
ath_recvmsg (int s, struct msghdr *msg, int flags)
Packit Service 672cf4
{
Packit Service 672cf4
#ifdef HAVE_W32_SYSTEM
Packit Service 672cf4
  return -1; /* Not supported. */
Packit Service 672cf4
#else
Packit Service 672cf4
  return recvmsg (s, msg, flags);
Packit Service 672cf4
#endif
Packit Service 672cf4
}