elf: Always provide _dl_get_dl_main_map in libc.a
[glibc.git] / nptl / pthread_attr_copy.c
bloba0fb3294ac8a8b86c8e152398cadc8348f63ba2d
1 /* Deep copy of a pthread_attr_t object.
2 Copyright (C) 2020-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <pthreadP.h>
21 #include <stdlib.h>
23 int
24 __pthread_attr_copy (pthread_attr_t *target, const pthread_attr_t *source)
26 /* Avoid overwriting *TARGET until all allocations have
27 succeeded. */
28 union pthread_attr_transparent temp;
29 temp.external = *source;
31 /* Force new allocation. This function has full ownership of temp. */
32 temp.internal.extension = NULL;
34 int ret = 0;
36 struct pthread_attr *isource = (struct pthread_attr *) source;
38 if (isource->extension != NULL)
40 /* Propagate affinity mask information. */
41 if (isource->extension->cpusetsize > 0)
42 ret = __pthread_attr_setaffinity_np (&temp.external,
43 isource->extension->cpusetsize,
44 isource->extension->cpuset);
46 /* Propagate the signal mask information. */
47 if (ret == 0 && isource->extension->sigmask_set)
48 ret = __pthread_attr_setsigmask_internal ((pthread_attr_t *) &temp,
49 &isource->extension->sigmask);
52 if (ret != 0)
54 /* Deallocate because we have ownership. */
55 __pthread_attr_destroy (&temp.external);
56 return ret;
59 /* Transfer ownership. *target is not assumed to have been
60 initialized. */
61 *target = temp.external;
62 return 0;
64 libc_hidden_def (__pthread_attr_copy)