.\" -*- coding: UTF-8 -*- .\" Copyright (c) 1990, 1991 The Regents of the University of California. .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" Chris Torek and the American National Standards Committee X3, .\" on Information Processing Systems. .\" .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB) .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" %%%LICENSE_END .\" .\" @(#)fopen.3 6.8 (Berkeley) 6/29/91 .\" .\" Converted for Linux, Mon Nov 29 15:22:01 1993, faith@cs.unc.edu .\" Modified, aeb, 960421, 970806 .\" Modified, joey, aeb, 2002-01-03 .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH FOPEN 3 "21 Diciembre 2020" GNU "Manual del Programador de Linux" .SH NOMBRE fopen, fdopen, freopen \- funciones de apertura de flujos .SH SINOPSIS .nf \fB#include \fP .PP \fBFILE *fopen(const char *\fP\fIcamino\fP\fB, const char *\fP\fImodo\fP\fB);\fP .PP \fBFILE *fdopen(int \fP\fIdescf\fP\fB, const char *\fP\fImodo\fP\fB);\fP .PP \fBFILE *freopen(const char *\fP\fIcamino\fP\fB, const char *\fP\fImodo\fP\fB, FILE *\fP\fIflujo\fP\fB);\fP .fi .PP .RS -4 Requisitos de Macros de Prueba de Características para glibc (véase \fBfeature_test_macros\fP(7)): .RE .PP \fBfdopen\fP(): _POSIX_C_SOURCE .SH DESCRIPCIÓN La función \fBfopen\fP() abre el fichero cuyo nombre es la cadena apuntada por \fIcamino\fP y asocia un flujo de datos a él. .PP The argument \fImode\fP points to a string beginning with one of the following sequences (possibly followed by additional characters, as described below): .TP \fBr\fP Abre un fichero de texto para lectura. El flujo se posiciona al principio del fichero. .TP \fBr+\fP Abre para lectura y escritura. El flujo se posiciona al principio del fichero. .TP \fBw\fP Trunca el fichero a longitud cero o crea un fichero de texto para escritura. El flujo se posiciona al principio del fichero. .TP \fBw+\fP Abre para lectura y escritura. El fichero se crea si no existe, en otro caso se trunca. El flujo se posiciona al principio del fichero. .TP \fBa\fP Abre para añadir (escribir al final del fichero). El fichero se crea si no existe. El flujo se posiciona al final del fichero. .TP \fBa+\fP Open for reading and appending (writing at end of file). The file is created if it does not exist. Output is always appended to the end of the file. POSIX is silent on what the initial read position is when using this mode. For glibc, the initial file position for reading is at the beginning of the file, but for Android/BSD/MacOS, the initial file position for reading is at the end of the file. .PP La cadena \fImodo\fP también puede incluir la letra \(aqb\(aq como último carácter o entre los de cualquiera de las cadenas de dos caracteres descritas anteriormente. Todo esto es estrictamente por compatibilidad con C89 y no tiene efecto. La \(aqb\(aq se ignora en todos los sistemas conformes con POSIX, incluido Linux. (Otros sistemas pueden tratar los ficheros de texto y los ficheros binarios de forma diferente, y añadir la \(aqb\(aq puede ser una buena idea si realiza E/S de un fichero binario y espera que su programa pueda ser transportado a entornos no UNIX). .PP See NOTES below for details of glibc extensions for \fImode\fP. .PP Cualquier fichero creado tendrá de permisos \fBS_IRUSR\fP | \fBS_IWUSR\fP | \fBS_IRGRP\fP | \fBS_IWGRP\fP | \fBS_IROTH\fP | \fBS_IWOTH\fP (0666), modificados por el valor de la máscara umask del proceso (vea \fBumask\fP(2)). .PP Las lecturas y las escrituras pueden mezclarse en flujos abiertos para lectura/escritura en cualquier orden. Observe que C ANSI requiere que intervenga una función de posicionamiento entre la salida y la entrada, a menos que una operación de entrada encuentre el fin\-de\-fichero. (Si esta condición no se cumple, entonces se permite a una lectura devolver el resultado de escrituras distintas a la más reciente.) Por lo tanto es buena práctica (y desde luego necesario algunas veces bajo Linux) hacer una operación \fBfseek\fP(3) o \fBfgetpos\fP(3) entre operaciones de escritura y lectura en tal flujo. Esta operación puede ser aparentemente inútil (como en \fIfseek(..., 0L, SEEK_CUR)\fP), llamada por su efecto lateral de sincronización. .PP Abrir un fichero para añadir (\fBa\fP como primer carácter de \fImodo\fP) implica que todas las operaciones de escritura posteriores sobre el flujo se realicen al final del fichero, como si fueran precedidas por una llamada: .PP .in +4n .EX fseek(stream, 0, SEEK_END); .EE .in .PP The file descriptor associated with the stream is opened as if by a call to \fBopen\fP(2) with the following flags: .RS .TS allbox; lb lb c l. fopen() mode open() flags \fIr\fP O_RDONLY \fIw\fP O_WRONLY | O_CREAT | O_TRUNC \fIa\fP O_WRONLY | O_CREAT | O_APPEND \fIr+\fP O_RDWR \fIw+\fP O_RDWR | O_CREAT | O_TRUNC \fIa+\fP O_RDWR | O_CREAT | O_APPEND .TE .RE .\" .SS fdopen() .\" La función \fBfdopen\fP() asocia un flujo con el descriptor de fichero existente, \fIdescf\fP. El \fImodo\fP del flujo (uno de los valores "r", "r+", "w", "w+", "a", "a+") debe ser compatible con el del descriptor de fichero. Al indicador de posición de fichero del nuevo flujo se le asigna el valor del indicador de posición perteneciente a \fIdescf\fP y los indicadores de error y de fin\-de\-fichero se limpian. Los modos "w" y "w+" no provocan el trucamiento del fichero. El descriptor de fichero no es \fIdup\fPlicado y se cerrará cuando el flujo creado por \fBfdopen\fP() se cierre. El resultado de aplicar \fIfdopen\fP() a un objeto compartido de memoria es indefinido. .SS freopen() La función \fBfreopen\fP() abre el fichero cuyo nombre es la cadena apuntada por \fIcamino\fP y asocia el flujo apuntado por \fIflujo\fP con él. El flujo original (si existe) se cierra. El argumento \fImodo\fP se emplea igual que en la función \fBfopen\fP(). .PP If the \fIpathname\fP argument is a null pointer, \fBfreopen\fP() changes the mode of the stream to that specified in \fImode\fP; that is, \fBfreopen\fP() reopens the pathname that is associated with the stream. The specification for this behavior was added in the C99 standard, which says: .PP .RS In this case, the file descriptor associated with the stream need not be closed if the call to \fBfreopen\fP() succeeds. It is implementation\-defined which changes of mode are permitted (if any), and under what circumstances. .RE .PP The primary use of the \fBfreopen\fP() function is to change the file associated with a standard text stream (\fIstderr\fP, \fIstdin\fP, or \fIstdout\fP). .SH "VALOR DEVUELTO" Cuando acaban bien, \fBfopen\fP(), \fBfdopen\fP() y \fBfreopen\fP() devuelven un puntero a \fIFILE\fP. Cuando no, devuelven NULL y \fIerrno\fP contiene un valor que indica el error. .SH ERRORES .TP \fBEINVAL\fP El \fImodo\fP pasado a \fBfopen\fP(), \fBfdopen\fP() o \fBfreopen\fP() no era válido. .PP Las funciones \fBfopen\fP(), \fBfdopen\fP() y \fBfreopen\fP() también pueden fallar y poner un valor en \fIerrno\fP para cualquiera de los errores especificados para la rutina \fBmalloc\fP(3). .PP La función \fBfopen\fP() también puede fallar y poner un valor en \fIerrno\fP para cualquiera de los errores especificados para la rutina \fBopen\fP(2). .PP La función \fBfdopen\fP() también puede fallar y poner un valor en \fIerrno\fP para cualquiera de los errores especificados para la rutina \fBfcntl\fP(2). .PP La función \fBfreopen\fP() también puede fallar y poner un valor en \fIerrno\fP para cualquiera de los errores especificados para las rutinas \fBopen\fP(2), \fBfclose\fP(3) y \fBfflush\fP(3). .SH ATRIBUTOS Para obtener una explicación de los términos usados en esta sección, véase \fBattributes\fP(7). .TS allbox; lbw28 lb lb l l l. Interfaz Atributo Valor T{ \fBfopen\fP(), \fBfdopen\fP(), \fBfreopen\fP() T} Seguridad del hilo Multi\-hilo seguro .TE .SH "CONFORME A" \fBfopen\fP(), \fBfreopen\fP(): POSIX.1\-2001, POSIX.1\-2008, C89, C99. .PP \fBfdopen\fP(): POSIX.1\-2001, POSIX.1\-2008. .SH NOTAS .SS "Glibc notes" The GNU C library allows the following extensions for the string specified in \fImode\fP: .TP \fBc\fP (desde glibc 2.3.3) Do not make the open operation, or subsequent read and write operations, thread cancellation points. This flag is ignored for \fBfdopen\fP(). .TP \fBe\fP (desde glibc 2.7) Open the file with the \fBO_CLOEXEC\fP flag. See \fBopen\fP(2) for more information. This flag is ignored for \fBfdopen\fP(). .TP \fBm\fP (desde glibc 2.3) .\" As at glibc 2.4: Attempt to access the file using \fBmmap\fP(2), rather than I/O system calls (\fBread\fP(2), \fBwrite\fP(2)). Currently, use of \fBmmap\fP(2) is attempted only for a file opened for reading. .TP \fBx\fP .\" Since glibc 2.0? .\" FIXME . C11 specifies this flag Open the file exclusively (like the \fBO_EXCL\fP flag of \fBopen\fP(2)). If the file already exists, \fBfopen\fP() fails, and sets \fIerrno\fP to \fBEEXIST\fP. This flag is ignored for \fBfdopen\fP(). .PP In addition to the above characters, \fBfopen\fP() and \fBfreopen\fP() support the following syntax in \fImode\fP: .PP \fB ,ccs=\fP\fIcadena\fP .PP The given \fIstring\fP is taken as the name of a coded character set and the stream is marked as wide\-oriented. Thereafter, internal conversion functions convert I/O to and from the character set \fIstring\fP. If the \fB,ccs=\fP\fIstring\fP syntax is not specified, then the wide\-orientation of the stream is determined by the first file operation. If that operation is a wide\-character operation, the stream is marked wide\-oriented, and functions to convert to the coded character set are loaded. .SH ERRORES .\" FIXME . http://sourceware.org/bugzilla/show_bug.cgi?id=12685 When parsing for individual flag characters in \fImode\fP (i.e., the characters preceding the "ccs" specification), the glibc implementation of \fBfopen\fP() and \fBfreopen\fP() limits the number of characters examined in \fImode\fP to 7 (or, in glibc versions before 2.14, to 6, which was not enough to include possible specifications such as "rb+cmxe"). The current implementation of \fBfdopen\fP() parses at most 5 characters in \fImode\fP. .SH "VÉASE TAMBIÉN" \fBopen\fP(2), \fBfclose\fP(3), \fBfileno\fP(3), \fBfmemopen\fP(3), \fBfopencookie\fP(3), \fBopen_memstream\fP(3) .SH COLOFÓN Esta página es parte de la versión 5.10 del proyecto Linux \fIman\-pages\fP. Puede encontrar una descripción del proyecto, información sobre cómo informar errores y la última versión de esta página en \%https://www.kernel.org/doc/man\-pages/. .SH TRADUCCIÓN La traducción al español de esta página del manual fue creada por Gerardo Aburruzaga García , Juan Piernas y Miguel Pérez Ibars . Esta traducción es documentación libre; lea la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 .UE o posterior con respecto a las condiciones de copyright. No existe NINGUNA RESPONSABILIDAD. Si encuentra algún error en la traducción de esta página del manual, envíe un correo electrónico a .MT debian-l10n-spanish@lists.debian.org>. .ME .