summaryrefslogtreecommitdiff
path: root/src/libstddjb/ipc_connect.c
blob: 9aa4dd9a225847249d89f948caa99987fc70f7ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* ISC license. */

#include <skalibs/nonposix.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <string.h>
#include <skalibs/error.h>
#include <skalibs/webipc.h>

int ipc_connect (int s, char const *p)
{
  struct sockaddr_un sa ;
  size_t l = strlen(p) ;
  if (l > IPCPATH_MAX) return (errno = EPROTO, 0) ;
  memset(&sa, 0, sizeof sa) ;
  sa.sun_family = AF_UNIX ;
  memcpy(sa.sun_path, p, l+1) ;
  if (connect(s, (struct sockaddr *)&sa, sizeof sa) == -1)
  {
    if (errno == EINTR) errno = EINPROGRESS ;
    return 0 ;
  }
  return 1 ;
}