Sync usage with man page.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / util / sane_socketpair.c
blob679290d7a979b91887a5e960cbac5708112cc25b
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* sane_socketpair 3
6 /* SUMMARY
7 /* sanitize socketpair() error returns
8 /* SYNOPSIS
9 /* #include <sane_socketpair.h>
11 /* int sane_socketpair(domain, type, protocol, result)
12 /* int domain;
13 /* int type;
14 /* int protocol;
15 /* int *result;
16 /* DESCRIPTION
17 /* sane_socketpair() implements the socketpair(2) socket call, and
18 /* skips over silly error results such as EINTR.
19 /* BUGS
20 /* Bizarre systems may have other harmless error results. Such
21 /* systems encourage programmers to ignore error results, and
22 /* penalize programmers who code defensively.
23 /* LICENSE
24 /* .ad
25 /* .fi
26 /* The Secure Mailer license must be distributed with this software.
27 /* AUTHOR(S)
28 /* Wietse Venema
29 /* IBM T.J. Watson Research
30 /* P.O. Box 704
31 /* Yorktown Heights, NY 10598, USA
32 /*--*/
34 /* System library. */
36 #include "sys_defs.h"
37 #include <sys/socket.h>
38 #include <unistd.h>
39 #include <errno.h>
41 /* Utility library. */
43 #include "msg.h"
44 #include "sane_socketpair.h"
46 /* sane_socketpair - sanitize socketpair() error returns */
48 int sane_socketpair(int domain, int type, int protocol, int *result)
50 static int socketpair_ok_errors[] = {
51 EINTR,
54 int count;
55 int err;
56 int ret;
59 * Solaris socketpair() can fail with EINTR.
61 while ((ret = socketpair(domain, type, protocol, result)) < 0) {
62 for (count = 0; /* void */ ; count++) {
63 if ((err = socketpair_ok_errors[count]) == 0)
64 return (ret);
65 if (errno == err) {
66 msg_warn("socketpair: %m (trying again)");
67 sleep(1);
68 break;
72 return (ret);