xref: /openbsd-src/lib/libc/sys/w_vfork.c (revision fe38b55cb0aae270de3f844146814682e8cd345c)
1*fe38b55cSguenther /*	$OpenBSD: w_vfork.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */
2*fe38b55cSguenther /*
3*fe38b55cSguenther  * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
4*fe38b55cSguenther  *
5*fe38b55cSguenther  * Permission to use, copy, modify, and distribute this software for any
6*fe38b55cSguenther  * purpose with or without fee is hereby granted, provided that the above
7*fe38b55cSguenther  * copyright notice and this permission notice appear in all copies.
8*fe38b55cSguenther  *
9*fe38b55cSguenther  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*fe38b55cSguenther  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*fe38b55cSguenther  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*fe38b55cSguenther  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*fe38b55cSguenther  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*fe38b55cSguenther  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*fe38b55cSguenther  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*fe38b55cSguenther  */
17*fe38b55cSguenther 
18*fe38b55cSguenther #include <tib.h>
19*fe38b55cSguenther #include <unistd.h>
20*fe38b55cSguenther #include "thread_private.h"
21*fe38b55cSguenther 
22*fe38b55cSguenther pid_t
WRAP(vfork)23*fe38b55cSguenther WRAP(vfork)(void)
24*fe38b55cSguenther {
25*fe38b55cSguenther 	pid_t newid;
26*fe38b55cSguenther 
27*fe38b55cSguenther 	if (_thread_cb.tc_vfork != NULL)
28*fe38b55cSguenther 		return (_thread_cb.tc_vfork());
29*fe38b55cSguenther 	newid = vfork();
30*fe38b55cSguenther 	if (newid == 0)
31*fe38b55cSguenther 		TIB_GET()->tib_tid = getthrid();
32*fe38b55cSguenther 	return newid;
33*fe38b55cSguenther }
34*fe38b55cSguenther DEF_WRAP(vfork);
35