Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
fopen(3)
Edit
PageHistory
Diff
Info
LikePages
FOPEN !!!FOPEN NAME SYNOPSIS DESCRIPTION RETURN VALUE ERRORS CONFORMING TO SEE ALSO ---- !!NAME fopen, fdopen, freopen - stream open functions !!SYNOPSIS __#include __ __FILE *fopen (const char *__''path''__, const char *__''mode''__);__%%% __FILE *fdopen (int__ ''fildes''__, const char *__''mode''__);__%%% __FILE *freopen (const char *__''path''__, const char *__''mode''__, FILE *__''stream''__);__ !!DESCRIPTION The __fopen__ function opens the file whose name is the string pointed to by ''path'' and associates a stream with it. The argument ''mode'' points to a string beginning with one of the following sequences (Additional characters may follow these sequences.): __r__ Open text file for reading. The stream is positioned at the beginning of the file. __r+__ Open for reading and writing. The stream is positioned at the beginning of the file. __w__ Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. __w+__ Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file. __a__ Open for writing. The file is created if it does not exist. The stream is positioned at the end of the file. __a+__ Open for reading and writing. The file is created if it does not exist. The stream is positioned at the end of the file. The ''mode'' string can also include the letter ``b'' either as a last character or as a character between the characters in any of the two-character strings described above. This is strictly for compatibility with ANSI X3.159-1989 (``ANSI C'') and has no effect; the ``b'' is ignored on all POSIX conforming systems, including Linux. (Other systems may treat text files and binary files differently, and adding the ``b'' may be a good idea if you do I/O to a binary file and expect that your program may be ported to non-Unix environments.) Any created files will have mode __S_IRUSR__|__S_IWUSR__|__S_IRGRP__|__S_IWGRP__|__S_IROTH__|__S_IWOTH__ (0666), as modified by the process' umask value (see umask(2). Reads and writes may be intermixed on read/write streams in any order. Note that ANSI C requires that a file positioning function intervene between output and input, unless an input operation encounters end-of-file. (If this condition is not met, then a read is allowed to return the result of writes other than the most recent.) Therefore it is good practice (and indeed sometimes necessary under Linux) to put an __fseek__ or __fgetpos__ operation between write and read operations on such a stream. This operation may be an apparent no-op (as in ''fseek(..., 0L, SEEK_CUR)'' called for its synchronizing side effect. The __fdopen__ function associates a stream with the existing file descriptor, ''fildes''. The ''mode'' of the stream (one of the values ''fildes'', and the error and end-of-file indicators are cleared. Modes ''fdopen__ is closed. The result of applying __fdopen__ to a shared memory object is undefined. The __freopen__ function opens the file whose name is the string pointed to by ''path'' and associates the stream pointed to by ''stream'' with it. The original stream (if it exists) is closed. The ''mode'' argument is used just as in the __fopen__ function. The primary use of the __freopen__ function is to change the file associated with a standard text stream (''stderr'', ''stdin'', or ''stdout''). !!RETURN VALUE Upon successful completion __fopen__, __fdopen__ and __freopen__ return a __FILE__ pointer. Otherwise, __NULL__ is returned and the global variable ''errno'' is set to indicate the error. !!ERRORS __EINVAL__ The ''mode'' provided to __fopen__, __fdopen__, or __freopen__ was invalid. The __fopen__, __fdopen__ and __freopen__ functions may also fail and set ''errno'' for any of the errors specified for the routine malloc(3). The __fopen__ function may also fail and set ''errno'' for any of the errors specified for the routine open(2). The __fdopen__ function may also fail and set ''errno'' for any of the errors specified for the routine fcntl(2). The __freopen__ function may also fail and set ''errno'' for any of the errors specified for the routines open(2), fclose(3) and fflush(3). !!CONFORMING TO The __fopen__ and __freopen__ functions conform to ANSI X3.159-1989 (``ANSI C''). The __fdopen__ function conforms to IEEE Std1003.1-1988 (``POSIX.1''). !!SEE ALSO open(2), fclose(3), fileno(3) ----
33 pages link to
fopen(3)
:
stdout(3)
pclose(3)
perlfunc(1)
perlopentut(1)
Man3f
addmntent(3)
endmntent(3)
fclose(3)
fcloseall(3)
fflush(3)
fgetc(3)
fputc(3)
fputs(3)
getc(3)
getchar(3)
getmntent(3)
gets(3)
hasmntopt(3)
putc(3)
putchar(3)
puts(3)
setbuf(3)
setbuffer(3)
setlinebuf(3)
setmntent(3)
setvbuf(3)
ungetc(3)
stdin(3)
creat(2)
fgets(3)
mknod(2)
open(2)
popen(3)
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.