thr_attr_getdetachstate.c revision 50476
117680Spst/*
239300Sfenner * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
317680Spst * All rights reserved.
417680Spst *
517680Spst * Redistribution and use in source and binary forms, with or without
617680Spst * modification, are permitted provided that the following conditions
717680Spst * are met:
817680Spst * 1. Redistributions of source code must retain the above copyright
917680Spst *    notice, this list of conditions and the following disclaimer.
1017680Spst * 2. Redistributions in binary form must reproduce the above copyright
1117680Spst *    notice, this list of conditions and the following disclaimer in the
1217680Spst *    documentation and/or other materials provided with the distribution.
1317680Spst * 3. All advertising materials mentioning features or use of this software
1417680Spst *    must display the following acknowledgement:
1517680Spst *	This product includes software developed by John Birrell.
1617680Spst * 4. Neither the name of the author nor the names of any co-contributors
1717680Spst *    may be used to endorse or promote products derived from this software
1817680Spst *    without specific prior written permission.
1917680Spst *
2056896Sfenner * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
2156896Sfenner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2217680Spst * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2317680Spst * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24276788Sdelphij * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2556896Sfenner * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2656896Sfenner * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2756896Sfenner * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2856896Sfenner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29127675Sbms * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3017680Spst * SUCH DAMAGE.
3117680Spst *
3217680Spst * $FreeBSD: head/lib/libkse/thread/thr_attr_getdetachstate.c 50476 1999-08-28 00:22:10Z peter $
33276788Sdelphij */
3417680Spst#include <errno.h>
3517680Spst#ifdef _THREAD_SAFE
3617680Spst#include <pthread.h>
3775118Sfenner#include "pthread_private.h"
38127675Sbms
3975118Sfennerint pthread_attr_getdetachstate(pthread_attr_t *attr, int *detachstate)
40276788Sdelphij{
41276788Sdelphij	int	ret;
42276788Sdelphij
43146778Ssam	/* Check for invalid arguments: */
44146778Ssam	if (attr == NULL || *attr == NULL || detachstate == NULL)
45146778Ssam		ret = EINVAL;
46146778Ssam	else {
47146778Ssam		/* Check if the detached flag is set: */
48146778Ssam		if ((*attr)->flags & PTHREAD_DETACHED)
49146778Ssam			/* Return detached: */
50146778Ssam			*detachstate = PTHREAD_CREATE_DETACHED;
51172686Smlaier		else
52146778Ssam			/* Return joinable: */
53146778Ssam			*detachstate = PTHREAD_CREATE_JOINABLE;
54146778Ssam		ret = 0;
5517680Spst	}
5617680Spst	return(ret);
5717680Spst}
5817680Spst#endif
59276788Sdelphij