1fdopen(3C) Standard C Library Functions fdopen(3C)
2
3
4
6 fdopen - associate a stream with a file descriptor
7
9 #include <stdio.h>
10
11 FILE *fdopen(int fildes, const char *mode);
12
13
15 The fdopen() function associates a stream with a file descriptor
16 fildes.
17
18
19 The mode argument is a character string having one of the following
20 values:
21
22
23
24
25 r or rb Open a file for reading.
26 w or wb Open a file for writing.
27 a or ab Open a file for writing at end of file.
28 r+, rb+ or r+b Open a file for update (reading and
29 writing).
30 w+, wb+ or w+b Open a file for update (reading and
31 writing).
32 a+, ab+ or a+b Open a file for update (reading and
33 writing) at end of file.
34
35
36
37 The meaning of these flags is exactly as specified for the fopen(3C)
38 function, except that modes beginning with w do not cause truncation of
39 the file. A trailing F character can also be included in the mode argu‐
40 ment as described in fopen(3C) to enable extended FILE facility.
41
42
43 The mode of the stream must be allowed by the file access mode of the
44 open file. The file position indicator associated with the new stream
45 is set to the position indicated by the file offset associated with the
46 file descriptor.
47
48
49 The fdopen() function preserves the offset maximum previously set for
50 the open file description corresponding to fildes.
51
52
53 The error and end-of-file indicators for the stream are cleared. The
54 fdopen() function may cause the st_atime field of the underlying file
55 to be marked for update.
56
57
58 If fildes refers to a shared memory object, the result of the fdopen()
59 function is unspecified.
60
62 Upon successful completion, fdopen() returns a pointer to a stream.
63 Otherwise, a null pointer is returned and errno is set to indicate the
64 error.
65
66
67 The fdopen() function may fail and not set errno if there are no free
68 stdio streams.
69
71 The fdopen() function may fail if:
72
73 EBADF The fildes argument is not a valid file descriptor.
74
75
76 EINVAL The mode argument is not a valid mode.
77
78
79 EMFILE {FOPEN_MAX} streams are currently open in the calling
80 process.
81
82 {STREAM_MAX} streams are currently open in the calling
83 process.
84
85
86 ENOMEM There is insufficient space to allocate a buffer.
87
88
90 A process is allowed to have at least {FOPEN_MAX} stdio streams open at
91 a time. For 32-bit applications, however, the underlying ABIs formerly
92 required that no file descriptor used to access the file underlying a
93 stdio stream have a value greater than 255. To maintain binary compati‐
94 bility with earlier Solaris releases, this limit still constrains
95 32-bit applications.
96
97
98 File descriptors are obtained from calls like open(2), dup(2), creat(2)
99 or pipe(2), which open files but do not return streams. Streams are
100 necessary input for almost all of the standard I/O library functions.
101
103 See attributes(5) for descriptions of the following attributes:
104
105
106
107
108 ┌─────────────────────────────┬─────────────────────────────┐
109 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
110 ├─────────────────────────────┼─────────────────────────────┤
111 │Interface Stability │See below. │
112 ├─────────────────────────────┼─────────────────────────────┤
113 │MT-Level │MT-Safe │
114 └─────────────────────────────┴─────────────────────────────┘
115
116
117 The F character in the mode argument is Evolving. In all other respects
118 this function is Standard.
119
121 creat(2), dup(2), open(2), pipe(2), fclose(3C), fopen(3C),
122 attributes(5), standards(5)
123
124
125
126SunOS 5.11 18 Apr 2006 fdopen(3C)