1FDOPEN(P)                  POSIX Programmer's Manual                 FDOPEN(P)
2
3
4

NAME

6       fdopen - associate a stream with a file descriptor
7

SYNOPSIS

9       #include <stdio.h>
10
11       FILE *fdopen(int fildes, const char *mode);
12
13

DESCRIPTION

15       The fdopen() function shall associate a stream with a file descriptor.
16
17       The  mode  argument  is  a character string having one of the following
18       values:
19
20       r or rb
21              Open a file for reading.
22
23       w or wb
24              Open a file for writing.
25
26       a or ab
27              Open a file for writing at end-of-file.
28
29       r+ or rb+ or r+b
30              Open a file for update (reading and writing).
31
32       w+ or wb+ or w+b
33              Open a file for update (reading and writing).
34
35       a+ or ab+ or a+b
36              Open a file for update (reading and writing) at end-of-file.
37
38
39       The meaning of these flags is exactly as specified in  fopen(),  except
40       that modes beginning with w shall not cause truncation of the file.
41
42       Additional  values  for the mode argument may be supported by an imple‐
43       mentation.
44
45       The application shall ensure that the mode of the stream  as  expressed
46       by  the  mode  argument  is allowed by the file access mode of the open
47       file description to which fildes refers. The  file  position  indicator
48       associated  with the new stream is set to the position indicated by the
49       file offset associated with the file descriptor.
50
51       The error and end-of-file indicators for the stream shall  be  cleared.
52       The  fdopen()  function  may cause the st_atime field of the underlying
53       file to be marked for update.
54
55       If fildes refers to a shared memory object, the result of the  fdopen()
56       function is unspecified.
57
58       If  fildes  refers to a typed memory object, the result of the fdopen()
59       function is unspecified.
60
61       The fdopen() function shall preserve the offset maximum previously  set
62       for the open file description corresponding to fildes.
63

RETURN VALUE

65       Upon  successful  completion,  fdopen()  shall  return  a  pointer to a
66       stream; otherwise, a null pointer shall be returned and  errno  set  to
67       indicate the error.
68

ERRORS

70       The fdopen() function may fail if:
71
72       EBADF  The fildes argument is not a valid file descriptor.
73
74       EINVAL The mode argument is not a valid mode.
75
76       EMFILE {FOPEN_MAX} streams are currently open in the calling process.
77
78       EMFILE {STREAM_MAX} streams are currently open in the calling process.
79
80       ENOMEM Insufficient space to allocate a buffer.
81
82
83       The following sections are informative.
84

EXAMPLES

86       None.
87

APPLICATION USAGE

89       File  descriptors  are obtained from calls like open(), dup(), creat(),
90       or pipe(), which open files but do not return streams.
91

RATIONALE

93       The file descriptor  may  have  been  obtained  from  open(),  creat(),
94       pipe(), dup(), or fcntl(); inherited through fork() or exec; or perhaps
95       obtained by implementation-defined means, such as the 4.3 BSD  socket()
96       call.
97
98       The  meanings  of  the  mode  arguments of fdopen() and fopen() differ.
99       With fdopen(), open for write (w or w+) does not truncate,  and  append
100       (a  or  a+)  cannot  create for writing. The mode argument formats that
101       include a b are allowed for consistency with the ISO C  standard  func‐
102       tion fopen(). The b has no effect on the resulting stream. Although not
103       explicitly required by this  volume  of  IEEE Std 1003.1-2001,  a  good
104       implementation  of  append (a) mode would cause the O_APPEND flag to be
105       set.
106

FUTURE DIRECTIONS

108       None.
109

SEE ALSO

111       Interaction of File Descriptors and Standard I/O Streams ,  fclose()  ,
112       fopen() , open() , the Base Definitions volume of IEEE Std 1003.1-2001,
113       <stdio.h>
114
116       Portions of this text are reprinted and reproduced in  electronic  form
117       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
118       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
119       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
120       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
121       event of any discrepancy between this version and the original IEEE and
122       The Open Group Standard, the original IEEE and The Open Group  Standard
123       is  the  referee document. The original Standard can be obtained online
124       at http://www.opengroup.org/unix/online.html .
125
126
127
128IEEE/The Open Group                  2003                            FDOPEN(P)
Impressum