]>
Commit | Line | Data |
---|---|---|
b31d4355 | 1 | /* Implementation of the _dl_write function. Generic version. |
dff8da6b | 2 | Copyright (C) 2020-2024 Free Software Foundation, Inc. |
b31d4355 FW |
3 | This file is part of the GNU C Library. |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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/>. */ | |
18 | ||
19 | #include <errno.h> | |
20 | #include <ldsodefs.h> | |
21 | #include <libc-lock.h> | |
22 | #include <sys/uio.h> | |
23 | ||
24 | ssize_t | |
25 | _dl_write (int fd, const void *buffer, size_t length) | |
26 | { | |
27 | struct iovec iov = { .iov_base = (void *) buffer, .iov_len = length }; | |
28 | ssize_t ret; | |
29 | ||
30 | #if RTLD_PRIVATE_ERRNO | |
31 | /* We have to take this lock just to be sure we don't clobber the private | |
32 | errno when it's being used by another thread that cares about it. | |
33 | Yet we must be sure not to try calling the lock functions before | |
34 | the thread library is fully initialized. */ | |
35 | if (__glibc_unlikely (_dl_starting_up)) | |
36 | { | |
37 | ret = __writev (fd, &iov, 1); | |
38 | if (ret < 0) | |
39 | ret = -errno; | |
40 | } | |
41 | else | |
42 | { | |
43 | __rtld_lock_lock_recursive (GL(dl_load_lock)); | |
df5f473e | 44 | ret = __writev (fd, &iov, 1); |
b31d4355 FW |
45 | if (ret < 0) |
46 | ret = -errno; | |
47 | __rtld_lock_unlock_recursive (GL(dl_load_lock)); | |
48 | } | |
49 | #else | |
50 | ret = __writev (fd, &iov, 1); | |
51 | if (ret < 0) | |
52 | ret = -errno; | |
53 | #endif | |
54 | ||
55 | return ret; | |
56 | } |