Blame elf/dl-write.c

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