Ejemplo n.º 1
0
static int
klibc_dup2dirfd (int fd, int desired_fd)
{
  int tempfd;
  int dupfd;

  tempfd = open ("NUL", O_RDONLY);
  if (tempfd == -1)
    return -1;

  if (tempfd == desired_fd)
    {
      close (tempfd);

      char path[_MAX_PATH];
      if (__libc_Back_ioFHToPath (fd, path, sizeof (path)))
        return -1;

      return open(path, O_RDONLY);
    }

  dupfd = klibc_dup2dirfd (fd, desired_fd);

  close (tempfd);

  return dupfd;
}
Ejemplo n.º 2
0
static int
dup_nothrow (int fd)
{
  int dupfd;
  struct stat sbuf;

  dupfd = dup (fd);
  if (dupfd == -1 && errno == ENOTSUP \
      && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode))
    {
      char path[_MAX_PATH];

      /* Get a path from fd */
      if (!__libc_Back_ioFHToPath (fd, path, sizeof (path)))
        dupfd = open (path, O_RDONLY);
    }

  return dupfd;
}