Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add accept4, a tiny wrapper around paccept.



details:   https://anonhg.NetBSD.org/src/rev/e14c8dce234b
branches:  trunk
changeset: 821519:e14c8dce234b
user:      maya <maya%NetBSD.org@localhost>
date:      Wed Feb 08 17:58:41 2017 +0000

description:
Add accept4, a tiny wrapper around paccept.

accept4 is a syscall in Linux, FreeBSD and OpenBSD. It is used in
LLVM, zeromq, and probably others. paccept is a superset of it.

adding it to libc ensures it is used by programs and prevents the
need to define the same wrapper in every program.

diffstat:

 lib/libc/sys/Makefile.inc |   4 +-
 lib/libc/sys/accept4.c    |  84 +++++++++++++++++++++++++++++++++++++++++++++++
 sys/sys/socket.h          |   3 +-
 3 files changed, 88 insertions(+), 3 deletions(-)

diffs (123 lines):

diff -r 45826b2571f0 -r e14c8dce234b lib/libc/sys/Makefile.inc
--- a/lib/libc/sys/Makefile.inc Wed Feb 08 17:51:21 2017 +0000
+++ b/lib/libc/sys/Makefile.inc Wed Feb 08 17:58:41 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.233 2017/02/08 17:30:27 maya Exp $
+#      $NetBSD: Makefile.inc,v 1.234 2017/02/08 17:58:41 maya Exp $
 #      @(#)Makefile.inc        8.3 (Berkeley) 10/24/94
 
 # sys sources
@@ -9,7 +9,7 @@
 # glue to offer userland wrappers for some syscalls
 SRCS+= posix_fadvise.c posix_madvise.c sched.c sigqueue.c sigtimedwait.c \
        sigwait.c sigwaitinfo.c statvfs.c swapon.c semctl.c \
-       clock_getcpuclockid.c
+       clock_getcpuclockid.c accept4.c
 
 .if ${RUMPRUN} != "yes"
 # modules with non-default implementations on at least one architecture:
diff -r 45826b2571f0 -r e14c8dce234b lib/libc/sys/accept4.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/sys/accept4.c    Wed Feb 08 17:58:41 2017 +0000
@@ -0,0 +1,84 @@
+/*     $NetBSD: accept4.c,v 1.1 2017/02/08 17:58:41 maya Exp $ */
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: accept4.c,v 1.1 2017/02/08 17:58:41 maya Exp $");
+
+#include "namespace.h"
+#include <sys/socket.h>
+
+#include <stddef.h>
+
+int
+accept4(int s, struct sockaddr * restrict addr, socklen_t * restrict addrlen,
+    int flags)
+{
+       return paccept(s, addr, addrlen, NULL, flags);
+}
+/*     $NetBSD: accept4.c,v 1.1 2017/02/08 17:58:41 maya Exp $ */
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: accept4.c,v 1.1 2017/02/08 17:58:41 maya Exp $");
+
+#include "namespace.h"
+#include <sys/socket.h>
+
+#include <stddef.h>
+
+int
+accept4(int s, struct sockaddr * restrict addr, socklen_t * restrict addrlen,
+    int flags)
+{
+       return paccept(s, addr, addrlen, NULL, flags);
+}
diff -r 45826b2571f0 -r e14c8dce234b sys/sys/socket.h
--- a/sys/sys/socket.h  Wed Feb 08 17:51:21 2017 +0000
+++ b/sys/sys/socket.h  Wed Feb 08 17:58:41 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: socket.h,v 1.120 2016/09/21 10:50:23 roy Exp $ */
+/*     $NetBSD: socket.h,v 1.121 2017/02/08 17:58:41 maya Exp $        */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -644,6 +644,7 @@
 
 __BEGIN_DECLS
 int    accept(int, struct sockaddr * __restrict, socklen_t * __restrict);
+int    accept4(int, struct sockaddr * __restrict, socklen_t * __restrict, int);
 int    bind(int, const struct sockaddr *, socklen_t);
 int    connect(int, const struct sockaddr *, socklen_t);
 int    getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);



Home | Main Index | Thread Index | Old Index