thr_attr_getdetachstate.c revision 103388
1177633Sdfr/*
2177633Sdfr * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
3177633Sdfr * All rights reserved.
4177633Sdfr *
5177633Sdfr * Redistribution and use in source and binary forms, with or without
6177633Sdfr * modification, are permitted provided that the following conditions
7177633Sdfr * are met:
8177633Sdfr * 1. Redistributions of source code must retain the above copyright
9177633Sdfr *    notice, this list of conditions and the following disclaimer.
10177633Sdfr * 2. Redistributions in binary form must reproduce the above copyright
11177633Sdfr *    notice, this list of conditions and the following disclaimer in the
12177633Sdfr *    documentation and/or other materials provided with the distribution.
13177633Sdfr * 3. All advertising materials mentioning features or use of this software
14177633Sdfr *    must display the following acknowledgement:
15177633Sdfr *	This product includes software developed by John Birrell.
16177633Sdfr * 4. Neither the name of the author nor the names of any co-contributors
17177633Sdfr *    may be used to endorse or promote products derived from this software
18177633Sdfr *    without specific prior written permission.
19177633Sdfr *
20177633Sdfr * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
21177633Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22177633Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23177633Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24177633Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25177633Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26177633Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27177633Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28177633Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29177633Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30177633Sdfr * SUCH DAMAGE.
31177633Sdfr *
32177633Sdfr * $FreeBSD: head/lib/libkse/thread/thr_attr_getdetachstate.c 103388 2002-09-16 08:45:36Z mini $
33177633Sdfr */
34177633Sdfr#include <errno.h>
35177633Sdfr#include <pthread.h>
36177633Sdfr#include "thr_private.h"
37177633Sdfr
38177633Sdfr__weak_reference(_pthread_attr_getdetachstate, pthread_attr_getdetachstate);
39177633Sdfr
40177685Sdfrint
41177685Sdfr_pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
42177633Sdfr{
43177633Sdfr	int	ret;
44177633Sdfr
45177633Sdfr	/* Check for invalid arguments: */
46177633Sdfr	if (attr == NULL || *attr == NULL || detachstate == NULL)
47177633Sdfr		ret = EINVAL;
48177633Sdfr	else {
49177633Sdfr		/* Check if the detached flag is set: */
50177633Sdfr		if ((*attr)->flags & PTHREAD_DETACHED)
51177633Sdfr			/* Return detached: */
52177633Sdfr			*detachstate = PTHREAD_CREATE_DETACHED;
53177633Sdfr		else
54177633Sdfr			/* Return joinable: */
55177633Sdfr			*detachstate = PTHREAD_CREATE_JOINABLE;
56177633Sdfr		ret = 0;
57177633Sdfr	}
58177633Sdfr	return(ret);
59177633Sdfr}
60177633Sdfr