thr_mattr_init.c revision 156611
1219019Sgabor/*
2219019Sgabor * Copyright (c) 1996 Jeffrey Hsu <hsu@freebsd.org>.
3219019Sgabor * All rights reserved.
4219019Sgabor *
5219019Sgabor * Redistribution and use in source and binary forms, with or without
6219019Sgabor * modification, are permitted provided that the following conditions
7219019Sgabor * are met:
8219019Sgabor * 1. Redistributions of source code must retain the above copyright
9219019Sgabor *    notice, this list of conditions and the following disclaimer.
10219019Sgabor * 2. Redistributions in binary form must reproduce the above copyright
11219019Sgabor *    notice, this list of conditions and the following disclaimer in the
12219019Sgabor *    documentation and/or other materials provided with the distribution.
13219019Sgabor * 3. All advertising materials mentioning features or use of this software
14219019Sgabor *    must display the following acknowledgement:
15219019Sgabor *	This product includes software developed by John Birrell.
16219019Sgabor * 4. Neither the name of the author nor the names of any co-contributors
17219019Sgabor *    may be used to endorse or promote products derived from this software
18219019Sgabor *    without specific prior written permission.
19219019Sgabor *
20219019Sgabor * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
21219019Sgabor * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22219019Sgabor * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23219019Sgabor * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24219019Sgabor * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25219019Sgabor * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26219019Sgabor * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27219019Sgabor * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28219019Sgabor * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29219019Sgabor * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30219019Sgabor * SUCH DAMAGE.
31219019Sgabor *
32219019Sgabor * $FreeBSD: head/lib/libkse/thread/thr_mattr_init.c 156611 2006-03-13 00:59:51Z deischen $
33219019Sgabor */
34219019Sgabor#include <string.h>
35219019Sgabor#include <stdlib.h>
36219019Sgabor#include <errno.h>
37219019Sgabor#include <pthread.h>
38219019Sgabor#include "thr_private.h"
39219019Sgabor
40219019SgaborLT10_COMPAT_PRIVATE(_pthread_mutexattr_init);
41219019SgaborLT10_COMPAT_DEFAULT(pthread_mutexattr_init);
42219019Sgabor
43219019Sgabor__weak_reference(_pthread_mutexattr_init, pthread_mutexattr_init);
44219019Sgabor
45219019Sgaborint
46219019Sgabor_pthread_mutexattr_init(pthread_mutexattr_t *attr)
47219019Sgabor{
48219019Sgabor	int ret;
49219019Sgabor	pthread_mutexattr_t pattr;
50219019Sgabor
51219019Sgabor	if ((pattr = (pthread_mutexattr_t)
52219019Sgabor	    malloc(sizeof(struct pthread_mutex_attr))) == NULL) {
53219019Sgabor		ret = ENOMEM;
54219019Sgabor	} else {
55219019Sgabor		memcpy(pattr, &_pthread_mutexattr_default,
56219019Sgabor		    sizeof(struct pthread_mutex_attr));
57219019Sgabor		*attr = pattr;
58219019Sgabor		ret = 0;
59219019Sgabor	}
60219019Sgabor	return (ret);
61219019Sgabor}
62219019Sgabor