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

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       fdopen - associate a stream with a file descriptor
13

SYNOPSIS

15       #include <stdio.h>
16
17       FILE *fdopen(int fildes, const char *mode);
18
19

DESCRIPTION

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

RETURN VALUE

71       Upon successful completion,  fdopen()  shall  return  a  pointer  to  a
72       stream;  otherwise,  a  null pointer shall be returned and errno set to
73       indicate the error.
74

ERRORS

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

EXAMPLES

92       None.
93

APPLICATION USAGE

95       File descriptors are obtained from calls like open(),  dup(),  creat(),
96       or pipe(), which open files but do not return streams.
97

RATIONALE

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

FUTURE DIRECTIONS

114       None.
115

SEE ALSO

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