HP 3000 Manuals

dup, dup2 [ MPE/iX Developer's Kit Reference Manual Volume I ] MPE/iX 5.0 Documentation


MPE/iX Developer's Kit Reference Manual Volume I

dup, dup2 

Duplicates an open file descriptor. 

Syntax 

     #include <unistd.h>
     int dup (int fildes);

     int dup2(iint fildes, int fildes2)

Parameters 

fildes     An open file descriptor.

Return Values 

>=0        Success.  A new file descriptor is returned.

-1         An error occurred.  the open file descriptor is not
           duplicated, and errno is set to indicate the error condition.

Description 

The dup() and dup2 functions return the lowest numbered file descriptor
not currentely open by the calling process.  The file descriptors
returned by dup() and dup2() refer to the same open file description as
fildes and share any locks.

The dup() and dup2() functions ignore file access permission bits when
attempting to duplicate an open file descriptor.

Implementation Considerations 

Refer to the EEXCL and ESYSERR error descriptions below.

Signals generated for the calling process during execution of dup() re
deferred from delivery until completion of this function.

Errors 

If an error occurs, errno is set to one of the following values:

EBADF             CAUSE           The parameter fildes is not a valid open file
                                  descriptor.
                  ACTION          Check to see if the value passed in fildes has been
                                  altered or whether the file indicated by fildes was
                                  ever opened.

EEXCL             CAUSE           The specified file descriptor is opened for exclusive
                                  access.
                  ACTION          Do not attempt to duplicate a file descriptor that is
                                  opened for exclusive access.

EMFILE            CAUSE           The number of open files and directories would exceed
                                  {OPEN_MAX}, the limit of opened files per process.
                  ACTION          Check process limit in <limits.h>.  Close a file.

ESYSERR           CAUSE           An operating system error has occurred that does not
                                  map directly to any of the above errors.
                  ACTION          Examine the MPE/iX error stack for the type of system
                                  error.

See Also 

close(), creat(), execl(), execv(), open(), POSIX.1 (Section 6.2.1)



MPE/iX 5.0 Documentation