1fopen(3UCB)        SunOS/BSD Compatibility Library Functions       fopen(3UCB)
2
3
4

NAME

6       fopen, freopen - open a stream
7

SYNOPSIS

9       /usr/ucb/cc [ flag ... ] file ...
10       #include <stdio.h>
11
12       FILE *fopen(file, mode)
13       const char *file, *mode;
14
15
16       FILE *freopen(file, mode, iop)
17       const char *file, *mode;
18       register FILE *iop;
19
20

DESCRIPTION

22       The  fopen() function opens the file specified by file and associates a
23       stream with it. If the open succeeds, fopen() returns a pointer  to  be
24       used to identify the stream in subsequent operations. The file argument
25       points to a character string that contains the name of the file  to  be
26       opened.  The mode argument is a character string having one of the fol‐
27       lowing values:
28
29       r     open for reading
30
31
32       w     truncate or create for writing
33
34
35       a     append: open for writing at end of file, or create for writing
36
37
38       r+    open for update (reading and writing)
39
40
41       w+    truncate or create for update
42
43
44       a+    append; open or create for update at EOF
45
46
47
48       The freopen() function opens the file specified by file and  associates
49       the stream pointed to by iop with it. The mode argument is used just as
50       in fopen(). The original stream is closed, regardless  of  whether  the
51       open  ultimately  succeeds. If the open succeeds, freopen() returns the
52       original value of iop.
53
54
55       The freopen() function is  typically  used  to  attach  the  pre-opened
56       streams associated withstdin, stdout, and stderr to other files.
57
58
59       When  a  file  is  opened for update, both input and output can be per‐
60       formed on the resulting stream. Output cannot be directly  followed  by
61       input  without  an intervening fseek(3C) or rewind(3C). Input cannot be
62       directly  followed  by  output  without  an  intervening  fseek(3C)  or
63       rewind(3C). An input operation that encounters  EOF will fail.
64

RETURN VALUES

66       The fopen() and freopen() functions return a NULL pointer on failure.
67

USAGE

69       The  fopen()  and  freopen() functions have transitional interfaces for
70       64-bit file offsets.  See lf64(5).
71

SEE ALSO

73       open(2), fclose(3C),  fopen(3C),  freopen(3C),  fseek(3C),  malloc(3C),
74       rewind(3C), lf64(5)
75

NOTES

77       Use  of these functions should be restricted to applications written on
78       BSD platforms.  Use of these functions with any of the system libraries
79       or in multithreaded applications is unsupported.
80
81
82       To  support  the  same number of open files as the system, fopen() must
83       allocate additional memory for data structures using  malloc(3C)  after
84       64  files  have been opened. This confuses some programs that use their
85       own memory allocators.
86
87
88       The fopen() and  freopen() functions differ from the standard I/O func‐
89       tions fopen(3C) and freopen(3C). The standard I/O functions distinguish
90       binary from text files with an additional use of 'b'  as  part  of  the
91       mode,  enabling  portability  of fopen(3C) and freopen(3C) beyond SunOS
92       4.x systems.
93
94
95
96SunOS 5.11                        30 Oct 2007                      fopen(3UCB)
Impressum