Unix-system-calls-dup

提供:Dev Guides
移動先:案内検索

[top]#

|http://www.google.com/[Google] | a|

Web This Site
  • 初心者向けのUnix *
  • 高度なUnix *

選択した読書

Copyright©2014 by finddevguides

[cols=",,,,,,,",]

| |  Home   | |  References   | |  Discussion Forums   | |  About TP  

[width="100%",cols="100%",]

a| == dup()-Unix、Linuxシステムコール

[[File:]] image :http://www.finddevguides.com/images/next.gif [next] image:http://www.finddevguides.com/add- this.gif [AddThisソーシャルブックマークボタン]

広告

NAME

dup、dup2-ファイル記述子を複製します

概要

#include <unistd.h> int dup(int oldfd); int dup2(int oldfd, int newfd);

説明

*dup* ()および *dup2* ()は、ファイル記述子_oldfd_のコピーを作成します。
*dup* ()または *dup2* ()から正常に戻った後、古いファイル記述子と新しいファイル記述子を同じ意味で使用できます。 これらは同じオープンファイルの説明を参照し( *open* (2)を参照)、ファイルオフセットとファイルステータスフラグを共有します。たとえば、一方の記述子で *lseek* (2)を使用してファイルオフセットが変更された場合、他方のオフセットも変更されます。

2つの記述子は、ファイル記述子フラグ(close-on-execフラグ)を共有しません。 重複記述子のclose-on-execフラグ( FD_CLOEXECfcntl (2)を参照)はオフです。

*dup* ()は、新しい記述子に最小番号の未使用記述子を使用します。
*dup2* ()は_newfd_を_oldfd_のコピーにし、必要に応じて最初に_newfd_を閉じます。

返り値

*dup* ()および *dup2* ()は新しい記述子を返します。エラーが発生した場合は-1を返します(この場合、_errno_は適切に設定されます)。

エラー

Tag Description
EBADF oldfd isn’t an open file descriptor, or newfd is out of the allowed range for file descriptors.
*EBUSY * (Linux only) This may be returned by* dup2*() during a race condition with open() and dup().
*EINTR * The* dup2*() call was interrupted by a signal.
EMFILE The process already has the maximum number of file descriptors open and tried to open a new one.

警告

_newfd_が範囲外の場合、 dup2 ()によって返されるエラーは、* fcntl(* …​、 F_DUPFD 、…​ )*によって返されるエラーとは異なります。 一部のシステムでは、 *dup2 ()は F_DUPFD のような EINVAL を返すこともあります。

_newfd_が開いていた場合、 close ()の時点で報告されていたエラーは失われます。 注意深いプログラマーは、_newfd_を最初に閉じずに dup2 ()を使用することはありません。

準拠

SVr4、4.3BSD、POSIX.1-2001。

関連項目

[[File:]] image :http://www.finddevguides.com/images/next.gif [next] [[File:]]

広告

|  

[cols="^",]

|Advertisements