Hallo, dies ist ein Test.
PWD: /www/data-lst1/unixsoft/unixsoft/kaempfer/.public_html
Running in File Mode
Relative path: ./../../.././../../../usr/man/man3c/fopen.3c
Real path: /usr/share/man/man3c/fopen.3c
Zurück
'\" te .\" Copyright (c) 1989, AT&T. All rights reserved. .\" Copyright (c) 2006, 2020, Oracle and/or its affiliates. .\" Portions Copyright (c) 1992, The X/Open Company Ltd. All rights reserved. .\" Oracle gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/. .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html. This notice shall appear on any product containing this material. .TH fopen 3C "11 June 2020" "Oracle Solaris 11.4" "Standard C Library Functions" .SH NAME fopen \- open a stream .br fopen_s \- open a stream with additional safety checks .SH SYNOPSIS .LP .nf #include <stdio.h> \fBFILE *\fR\fBfopen\fR(\fBconst char *\fR\fIfilename\fR, \fBconst char *\fR\fImode\fR); .fi .LP .nf #define __STDC_WANT_LIB_EXT1__ 1 #include <stdio.h> \fBerrno_t\fR \fBfopen_s\fR(\fBFILE *restrict *restrict\fR \fIstreamptr\fR, \fBconst char *restrict\fR \fIfilename\fR, \fBconst char *restrict\fR \fImode\fR); .fi .SH DESCRIPTION .sp .LP The \fBfopen()\fR function opens the file whose pathname is the string pointed to by \fIfilename\fR, and associates a stream with it. .sp .LP The argument \fImode\fR points to a string beginning with one of the following sequences: .sp .ne 2 .mk .na \fB\fBr\fR or \fBrb\fR\fR .ad .RS 20n .rt Open file for reading .RE .sp .ne 2 .mk .na \fB\fBw\fR or \fBwb\fR\fR .ad .RS 20n .rt Truncate to zero length or create file for writing .RE .sp .ne 2 .mk .na \fB\fBa\fR or \fBab\fR\fR .ad .RS 20n .rt Append; open or create file for writing at end-of-file .RE .sp .ne 2 .mk .na \fB\fBr+\fR or \fBrb+\fR or \fBr+b\fR\fR .ad .RS 20n .rt Open file for update (reading and writing) .RE .sp .ne 2 .mk .na \fB\fBw+\fR or \fBwb+\fR or \fBw+b\fR\fR .ad .RS 20n .rt Truncate to zero length or create file for update .RE .sp .ne 2 .mk .na \fB\fBa+\fR or \fBab+\fR or \fBa+b\fR\fR .ad .RS 20n .rt Append; open or create file for update, writing at end-of-file .RE .sp .LP The character \fBb\fR has no effect, but is allowed for ISO C standard conformance (see \fBstandards\fR(7)). Opening a file with read mode (\fBr\fR as the first character in the \fImode\fR argument) fails if the file does not exist or cannot be read. .sp .LP Opening a file with exclusive mode (\fBx\fR somewhere after the initial \fBw\fR or \fBa\fR in the \fImode\fR argument) fails if the file already exists or cannot be created. .sp .LP Opening a file with append mode (\fBa\fR as the first character in the \fImode\fR argument) causes all subsequent writes to the file to be forced to the then current end-of-file, regardless of intervening calls to \fBfseek\fR(3C). If two separate processes open the same file for append, each process may write freely to the file without fear of destroying output being written by the other. The output from the two processes will be intermixed in the file in the order in which it is written. .sp .LP When a file is opened with update mode (\fB+\fR as the second or third character in the \fImode\fR argument), both input and output may be performed on the associated stream. However, output must not be directly followed by input without an intervening call to \fBfflush\fR(3C) or to a file positioning function (\fBfseek\fR(3C), \fBfsetpos\fR(3C), or \fBrewind\fR(3C)), and input must not be directly followed by output without an intervening call to a file positioning function, unless the input operation encounters end-of-file. .sp .LP When opened, a stream is fully buffered if and only if it can be determined not to refer to an interactive device. The error and end-of-file indicators for the stream are cleared. .sp .LP If \fImode\fR begins with \fBw\fR or \fBa\fR and the file did not previously exist, upon successful completion, \fBfopen()\fR function will mark for update the \fBst_atime\fR, \fBst_ctime\fR and \fBst_mtime\fR fields of the file and the \fBst_ctime\fR and \fBst_mtime\fR fields of the parent directory. .sp .LP If \fImode\fR begins with \fBw\fR and the file did previously exist, upon successful completion, \fBfopen()\fR will mark for update the \fBst_ctime\fR and \fBst_mtime\fR fields of the file. The \fBfopen()\fR function will allocate a file descriptor as \fBopen\fR(2) does. .sp .LP The largest value that can be represented correctly in an object of type \fBoff_t\fR will be established as the offset maximum in the open file description. .sp .LP Additional mode characters are supported in this implementation. These additional characters must appear after \fBr\fR, \fBw\fR, or \fBa\fR. .sp .LP Specifying \fBe\fR in the \fImode\fR argument indicates the file is being opened with the \fBO_CLOEXEC\fR flag. This sets the \fBFD_CLOEXEC\fR for the underlying file descriptor. For more information, see the \fBopen\fR(2) man page. .sp .LP Specifying \fBf\fR in the \fImode\fR argument indicates the file is being opened with the \fBO_CLOFORK\fR flag. This sets the \fBFD_CLOFORK\fR for the underlying file descriptor. For more information, see the \fBopen\fR(2) man page. .sp .LP Specifying \fBx\fR in the \fImode\fR argument indicates the file is being opened in exclusive mode; the file is opened with the \fBO_EXCL\fR flag. For more information, see the \fBopen\fR(2) man page. .sp .LP The \fBfopen_s()\fR function is part of the bounds checking interfaces specified in the C11 standard, Annex K. It is similar to the \fBfopen()\fR function, except for a different return type and an additional parameter, providing extra safety checks in the form of explicit runtime-constraints as defined in the C11 standard. The \fBfopen_s()\fR function provides a new mode character, \fBu\fR which may precede any of the previously defined modes starting with the character \fBw\fR or \fBa\fR. See INCITS/ISO/IEC 9899:2011. .sp .LP Implementation specific details for \fBfopen_s()\fR include the following: .sp .LP Files opened for writing are opened with exclusive, (or non-shared), access. The file permission for the file will prevent other system users from accessing the file, that is \fBS_IRUSR\fR | \fBS_IWUSR\fR flags if the file is being created and the first character of the mode string is not \fBu\fR. For more information, see the \fBchmod\fR(2) man page. If the file is being created and first character of the mode string is \fBu\fR, the file shall have the system default file access permissions. .sp .LP A runtime-constraint violation will be generated if either \fBstreamptr\fR, \fBfilename\fR, or \fBmode\fR is a null pointer. .SH RETURN VALUES .sp .LP Upon successful completion, \fBfopen()\fR returns a pointer to the object controlling the stream. Otherwise, a null pointer is returned and \fBerrno\fR is set to indicate the error. .sp .LP The \fBfopen()\fR function may fail and not set \fBerrno\fR if there are no free \fBstdio\fR streams. .sp .LP If the \fBfopen_s()\fR function succeeds in opening a file, it returns zero. Otherwise, a non-zero value is returned if \fBfopen_s()\fR failed to open the file or if a runtime-constraint violation was encountered. .SH ERRORS .sp .LP The \fBfopen()\fR and \fBfopen_s()\fR functions will fail if: .sp .ne 2 .mk .na \fB\fBEACCES\fR\fR .ad .RS 16n .rt Search permission is denied on a component of the path prefix, or the file exists and the permissions specified by \fImode\fR are denied, or the file does not exist and write permission is denied for the parent directory of the file to be created. .RE .sp .ne 2 .mk .na \fB\fBEINTR\fR\fR .ad .RS 16n .rt A signal was caught during the execution of \fBfopen()\fR. .RE .sp .ne 2 .mk .na \fB\fBEISDIR\fR\fR .ad .RS 16n .rt The named file is a directory and \fImode\fR requires write access. .RE .sp .ne 2 .mk .na \fB\fBELOOP\fR\fR .ad .RS 16n .rt Too many symbolic links were encountered in resolving \fIfilename\fR. .RE .sp .ne 2 .mk .na \fB\fBEMFILE\fR\fR .ad .RS 16n .rt There are {\fBOPEN_MAX\fR} file descriptors currently open in the calling process. .RE .sp .ne 2 .mk .na \fB\fBENAMETOOLONG\fR\fR .ad .RS 16n .rt The length of the \fIfilename\fR exceeds \fIPATH_MAX\fR or a pathname component is longer than \fINAME_MAX\fR. .RE .sp .ne 2 .mk .na \fB\fBENFILE\fR\fR .ad .RS 16n .rt The maximum allowable number of files is currently open in the system. .RE .sp .ne 2 .mk .na \fB\fBENOENT\fR\fR .ad .RS 16n .rt A component of \fIfilename\fR does not name an existing file or \fIfilename\fR is an empty string. .RE .sp .ne 2 .mk .na \fB\fBENOSPC\fR\fR .ad .RS 16n .rt The directory or file system that would contain the new file cannot be expanded, the file does not exist, and it was to be created. .RE .sp .ne 2 .mk .na \fB\fBENOTDIR\fR\fR .ad .RS 16n .rt A component of the path prefix is not a directory. .RE .sp .ne 2 .mk .na \fB\fBENXIO\fR\fR .ad .RS 16n .rt The named file is a character special or block special file, and the device associated with this special file does not exist. .RE .sp .ne 2 .mk .na \fB\fBEOVERFLOW\fR\fR .ad .RS 16n .rt The current value of the file position cannot be represented correctly in an object of type \fBfpos_t\fR. .RE .sp .ne 2 .mk .na \fB\fBEROFS\fR\fR .ad .RS 16n .rt The named file resides on a read-only file system and \fImode\fR requires write access. .RE .sp .LP The \fBfopen()\fR function may fail if: .sp .ne 2 .mk .na \fB\fBEINVAL\fR\fR .ad .RS 16n .rt The value of the \fImode\fR argument is not valid. .RE .sp .ne 2 .mk .na \fB\fBEMFILE\fR\fR .ad .RS 16n .rt {\fBFOPEN_MAX\fR} streams are currently open in the calling process. .sp {\fBSTREAM_MAX\fR} streams are currently open in the calling process. .RE .sp .ne 2 .mk .na \fB\fBENAMETOOLONG\fR\fR .ad .RS 16n .rt Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {\fBPATH_MAX\fR}. .RE .sp .ne 2 .mk .na \fB\fBENOMEM\fR\fR .ad .RS 16n .rt Insufficient storage space is available. .RE .sp .ne 2 .mk .na \fB\fBETXTBSY\fR\fR .ad .RS 16n .rt The file is a pure procedure (shared text) file that is being executed and \fImode\fR requires write access. .RE .sp .LP The \fBfopen_s()\fR function will fail if: .sp .ne 2 .mk .na \fB\fBEINVAL\fR\fR .ad .RS 10n .rt Null pointer is passed. .RE .SH USAGE .sp .LP The \fBfopen()\fR function has a transitional interface for 64-bit file offsets. For more information, see the \fBlf64\fR(7) man page. .SH ATTRIBUTES .sp .LP See \fBattributes\fR(7) for descriptions of the following attributes: .sp .TS tab( ) box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPE ATTRIBUTE VALUE _ Interface Stability Committed _ MT-Level See below _ Standard See \fBstandards\fR(7). .TE .sp .sp .LP The \fBfopen()\fR function can be used safely in multithreaded applications. .sp .LP The \fBfopen_s()\fR function cannot be used safely in a multithreaded application due to the runtime constraint handler. For more information, see the \fBruntime_constraint_handler\fR(3C) man page. .SH SEE ALSO .sp .LP \fBfclose\fR(3C), \fBfdopen\fR(3C), \fBfflush\fR(3C), \fBfreopen\fR(3C), \fBfreopen_s\fR(3C), \fBfsetpos\fR(3C), \fBrewind\fR(3C), \fBattributes\fR(7), \fBlf64\fR(7), \fBstandards\fR(7), \fBruntime_constraint_handler\fR(3C)