122315Sjulian/* 222315Sjulian * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. 322315Sjulian * All rights reserved. 422315Sjulian * 522315Sjulian * Redistribution and use in source and binary forms, with or without 622315Sjulian * modification, are permitted provided that the following conditions 722315Sjulian * are met: 822315Sjulian * 1. Redistributions of source code must retain the above copyright 922315Sjulian * notice, this list of conditions and the following disclaimer. 1022315Sjulian * 2. Redistributions in binary form must reproduce the above copyright 1122315Sjulian * notice, this list of conditions and the following disclaimer in the 1222315Sjulian * documentation and/or other materials provided with the distribution. 13165967Simp * 3. Neither the name of the author nor the names of any co-contributors 1422315Sjulian * may be used to endorse or promote products derived from this software 1522315Sjulian * without specific prior written permission. 1622315Sjulian * 1722315Sjulian * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 1822315Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1922315Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2049439Sdeischen * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2122315Sjulian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2222315Sjulian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2322315Sjulian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2422315Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2522315Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2622315Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2722315Sjulian * SUCH DAMAGE. 2822315Sjulian * 2950476Speter * $FreeBSD: releng/10.3/lib/libkse/thread/thr_attr_getdetachstate.c 174689 2007-12-16 23:29:57Z deischen $ 3022315Sjulian */ 31174112Sdeischen#include "namespace.h" 3222315Sjulian#include <errno.h> 3322315Sjulian#include <pthread.h> 34174112Sdeischen#include "un-namespace.h" 35103388Smini#include "thr_private.h" 3622315Sjulian 3775369Sdeischen__weak_reference(_pthread_attr_getdetachstate, pthread_attr_getdetachstate); 3871581Sdeischen 3960382Sbdeint 4071581Sdeischen_pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate) 4122315Sjulian{ 4222315Sjulian int ret; 4322315Sjulian 4422315Sjulian /* Check for invalid arguments: */ 4522315Sjulian if (attr == NULL || *attr == NULL || detachstate == NULL) 4622315Sjulian ret = EINVAL; 4722315Sjulian else { 4822315Sjulian /* Check if the detached flag is set: */ 4922315Sjulian if ((*attr)->flags & PTHREAD_DETACHED) 5022315Sjulian /* Return detached: */ 5122315Sjulian *detachstate = PTHREAD_CREATE_DETACHED; 5222315Sjulian else 5322315Sjulian /* Return joinable: */ 5422315Sjulian *detachstate = PTHREAD_CREATE_JOINABLE; 5522315Sjulian ret = 0; 5622315Sjulian } 5722315Sjulian return(ret); 5822315Sjulian} 59