thr_attr_init.c revision 141822
1264601Sbz/*
2264601Sbz * Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
3264601Sbz * All rights reserved.
4264601Sbz *
5264601Sbz * Redistribution and use in source and binary forms, with or without
6264601Sbz * modification, are permitted provided that the following conditions
7264601Sbz * are met:
8264601Sbz * 1. Redistributions of source code must retain the above copyright
9264601Sbz *    notice, this list of conditions and the following disclaimer.
10264601Sbz * 2. Redistributions in binary form must reproduce the above copyright
11264601Sbz *    notice, this list of conditions and the following disclaimer in the
12264601Sbz *    documentation and/or other materials provided with the distribution.
13264601Sbz * 3. All advertising materials mentioning features or use of this software
14264601Sbz *    must display the following acknowledgement:
15264601Sbz *	This product includes software developed by John Birrell.
16264601Sbz * 4. Neither the name of the author nor the names of any co-contributors
17264601Sbz *    may be used to endorse or promote products derived from this software
18264601Sbz *    without specific prior written permission.
19264601Sbz *
20264601Sbz * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
21264601Sbz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22264601Sbz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23264601Sbz * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24264601Sbz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25264601Sbz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26264601Sbz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27264601Sbz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28264601Sbz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29264601Sbz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30264601Sbz * SUCH DAMAGE.
31264601Sbz *
32264601Sbz * $FreeBSD: head/lib/libkse/thread/thr_attr_init.c 141822 2005-02-13 18:38:06Z deischen $
33264601Sbz */
34264601Sbz#include <string.h>
35264601Sbz#include <stdlib.h>
36264601Sbz#include <errno.h>
37264601Sbz#include <pthread.h>
38264601Sbz#include "thr_private.h"
39264601Sbz
40264601Sbz__weak_reference(_pthread_attr_init, pthread_attr_init);
41264601Sbz
42264601Sbzint
43264601Sbz_pthread_attr_init(pthread_attr_t *attr)
44264601Sbz{
45264601Sbz	int	ret;
46264601Sbz	pthread_attr_t	pattr;
47264601Sbz
48264601Sbz	/* Allocate memory for the attribute object: */
49264601Sbz	if ((pattr = (pthread_attr_t) malloc(sizeof(struct pthread_attr))) == NULL)
50264601Sbz		/* Insufficient memory: */
51264601Sbz		ret = ENOMEM;
52264601Sbz	else {
53264601Sbz		/* Initialise the attribute object with the defaults: */
54264601Sbz		memcpy(pattr, &_pthread_attr_default,
55264601Sbz		    sizeof(struct pthread_attr));
56264601Sbz		pattr->guardsize_attr = _thr_guard_default;
57264601Sbz		pattr->stacksize_attr = _thr_stack_default;
58264601Sbz
59264601Sbz		/* Return a pointer to the attribute object: */
60264601Sbz		*attr = pattr;
61264601Sbz		ret = 0;
62264601Sbz	}
63264601Sbz	return(ret);
64264601Sbz}
65264601Sbz