|
Packit Bot |
c7bb52 |
/* Implementation of the _dl_write function. Generic version.
|
|
Packit Bot |
c7bb52 |
Copyright (C) 2020 Free Software Foundation, Inc.
|
|
Packit Bot |
c7bb52 |
This file is part of the GNU C Library.
|
|
Packit Bot |
c7bb52 |
|
|
Packit Bot |
c7bb52 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Bot |
c7bb52 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Bot |
c7bb52 |
License as published by the Free Software Foundation; either
|
|
Packit Bot |
c7bb52 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Bot |
c7bb52 |
|
|
Packit Bot |
c7bb52 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Bot |
c7bb52 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Bot |
c7bb52 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Bot |
c7bb52 |
Lesser General Public License for more details.
|
|
Packit Bot |
c7bb52 |
|
|
Packit Bot |
c7bb52 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Bot |
c7bb52 |
License along with the GNU C Library; if not, see
|
|
Packit Bot |
c7bb52 |
<https://www.gnu.org/licenses/>. */
|
|
Packit Bot |
c7bb52 |
|
|
Packit Bot |
c7bb52 |
#include <errno.h>
|
|
Packit Bot |
c7bb52 |
#include <ldsodefs.h>
|
|
Packit Bot |
c7bb52 |
#include <libc-lock.h>
|
|
Packit Bot |
c7bb52 |
#include <sys/uio.h>
|
|
Packit Bot |
c7bb52 |
|
|
Packit Bot |
c7bb52 |
ssize_t
|
|
Packit Bot |
c7bb52 |
_dl_write (int fd, const void *buffer, size_t length)
|
|
Packit Bot |
c7bb52 |
{
|
|
Packit Bot |
c7bb52 |
struct iovec iov = { .iov_base = (void *) buffer, .iov_len = length };
|
|
Packit Bot |
c7bb52 |
ssize_t ret;
|
|
Packit Bot |
c7bb52 |
|
|
Packit Bot |
c7bb52 |
#if RTLD_PRIVATE_ERRNO
|
|
Packit Bot |
c7bb52 |
/* We have to take this lock just to be sure we don't clobber the private
|
|
Packit Bot |
c7bb52 |
errno when it's being used by another thread that cares about it.
|
|
Packit Bot |
c7bb52 |
Yet we must be sure not to try calling the lock functions before
|
|
Packit Bot |
c7bb52 |
the thread library is fully initialized. */
|
|
Packit Bot |
c7bb52 |
if (__glibc_unlikely (_dl_starting_up))
|
|
Packit Bot |
c7bb52 |
{
|
|
Packit Bot |
c7bb52 |
ret = __writev (fd, &iov, 1);
|
|
Packit Bot |
c7bb52 |
if (ret < 0)
|
|
Packit Bot |
c7bb52 |
ret = -errno;
|
|
Packit Bot |
c7bb52 |
}
|
|
Packit Bot |
c7bb52 |
else
|
|
Packit Bot |
c7bb52 |
{
|
|
Packit Bot |
c7bb52 |
__rtld_lock_lock_recursive (GL(dl_load_lock));
|
|
Packit Bot |
b4b6db |
ret = __writev (fd, &iov, 1);
|
|
Packit Bot |
c7bb52 |
if (ret < 0)
|
|
Packit Bot |
c7bb52 |
ret = -errno;
|
|
Packit Bot |
c7bb52 |
__rtld_lock_unlock_recursive (GL(dl_load_lock));
|
|
Packit Bot |
c7bb52 |
}
|
|
Packit Bot |
c7bb52 |
#else
|
|
Packit Bot |
c7bb52 |
ret = __writev (fd, &iov, 1);
|
|
Packit Bot |
c7bb52 |
if (ret < 0)
|
|
Packit Bot |
c7bb52 |
ret = -errno;
|
|
Packit Bot |
c7bb52 |
#endif
|
|
Packit Bot |
c7bb52 |
|
|
Packit Bot |
c7bb52 |
return ret;
|
|
Packit Bot |
c7bb52 |
}
|