Blame elf/dl-write.c

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