Ignore:
Timestamp:
Feb 3, 2017, 2:02:34 PM (8 years ago)
Author:
Silvan Scherrer
Message:

cpio: update vendor to version 2.12

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified cpio/vendor/current/gnu/dup2.c

    r118 r1964  
    1 /* -*- buffer-read-only: t -*- vi: set ro: */
    2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
    31/* Duplicate an open file descriptor to a specified file descriptor.
    42
    5    Copyright (C) 1999, 2004-2007, 2009-2010 Free Software Foundation, Inc.
     3   Copyright (C) 1999, 2004-2007, 2009-2015 Free Software Foundation, Inc.
    64
    75   This program is free software: you can redistribute it and/or modify
     
    2826#include <fcntl.h>
    2927
    30 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
    31 /* Get declarations of the Win32 API functions.  */
    32 # define WIN32_LEAN_AND_MEAN
    33 # include <windows.h>
    34 #endif
    35 
    3628#if HAVE_DUP2
    3729
    3830# undef dup2
    3931
    40 int
    41 rpl_dup2 (int fd, int desired_fd)
     32# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
     33
     34/* Get declarations of the native Windows API functions.  */
     35#  define WIN32_LEAN_AND_MEAN
     36#  include <windows.h>
     37
     38#  include "msvc-inval.h"
     39
     40/* Get _get_osfhandle.  */
     41#  include "msvc-nothrow.h"
     42
     43static int
     44ms_windows_dup2 (int fd, int desired_fd)
    4245{
    4346  int result;
    44 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
     47
    4548  /* If fd is closed, mingw hangs on dup2 (fd, fd).  If fd is open,
    4649     dup2 (fd, fd) returns 0, but all further attempts to use fd in
     
    5558      return fd;
    5659    }
     60
    5761  /* Wine 1.0.1 return 0 when desired_fd is negative but not -1:
    5862     http://bugs.winehq.org/show_bug.cgi?id=21289 */
     
    6266      return -1;
    6367    }
    64 # endif
    65   result = dup2 (fd, desired_fd);
    66 # ifdef __linux__
    67   /* Correct a Linux return value.
    68      <http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.30.y.git;a=commitdiff;h=2b79bc4f7ebbd5af3c8b867968f9f15602d5f802>
    69    */
    70   if (fd == desired_fd && result == (unsigned int) -EBADF)
     68
     69  TRY_MSVC_INVAL
     70    {
     71      result = dup2 (fd, desired_fd);
     72    }
     73  CATCH_MSVC_INVAL
    7174    {
    7275      errno = EBADF;
    7376      result = -1;
    7477    }
    75 # endif
     78  DONE_MSVC_INVAL;
     79
    7680  if (result == 0)
    7781    result = desired_fd;
    78   /* Correct a cygwin 1.5.x errno value.  */
    79   else if (result == -1 && errno == EMFILE)
     82
     83  return result;
     84}
     85
     86#  define dup2 ms_windows_dup2
     87
     88# endif
     89
     90int
     91rpl_dup2 (int fd, int desired_fd)
     92{
     93  int result;
     94
     95# ifdef F_GETFL
     96  /* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF.
     97     On Cygwin 1.5.x, dup2 (1, 1) returns 0.
     98     On Cygwin 1.7.17, dup2 (1, -1) dumps core.
     99     On Cygwin 1.7.25, dup2 (1, 256) can dump core.
     100     On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC.  */
     101#  if HAVE_SETDTABLESIZE
     102  setdtablesize (desired_fd + 1);
     103#  endif
     104  if (desired_fd < 0)
     105    fd = desired_fd;
     106  if (fd == desired_fd)
     107    return fcntl (fd, F_GETFL) == -1 ? -1 : fd;
     108# endif
     109
     110  result = dup2 (fd, desired_fd);
     111
     112  /* Correct an errno value on FreeBSD 6.1 and Cygwin 1.5.x.  */
     113  if (result == -1 && errno == EMFILE)
    80114    errno = EBADF;
    81115# if REPLACE_FCHDIR
Note: See TracChangeset for help on using the changeset viewer.