.\" Copyright (c) 1994 Michael Haardt (michael@moria.de), Sat Jun 4 20:38:26 MET DST 1994 .\" Copyright (c) 1995 Michael Haardt (michael@cantor.informatik.rwth-aachen.de), Thu Mar 16 18:46:23 MET 1995 .\" Copyright (c) 1996 Andries Brouwer (aeb@cwi.nl), Sat Jan 13 00:16:41 MET 1996 .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2 of .\" the License, or (at your option) any later version. .\" .\" The GNU General Public License's references to "object code" .\" and "executables" are to be interpreted as the output of any .\" document formatting or typesetting system, including .\" intermediate and printed output. .\" .\" This manual is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. .\" .\" Sat Jan 13 00:16:41 MET 1996, aeb: merged in some text contributed .\" by Melvin Smith (msmith@falcon.mercer.peachnet.edu) and various .\" other changes. .\" Modified Fri May 16 23:41:15 1996 by Martin Schulze (joey@infodrom.north.de) .\" .\" Translated into Spanish Thu Mar 5 09:38:23 CET 1998 by Gerrado .\" Aburruzaga García .\" Traducción revisada por Miguel Pérez Ibars el 4-abril-2005 .\" .TH PERROR 3 "14 diciembre 2001" "Linux" "Funciones de Biblioteca" .SH NOMBRE perror \- muestra un mensaje correspondiente a un error del sistema .SH SINOPSIS .B #include .sp .BI "void perror(const char " *s ); .sp .B #include .sp .BI "const char *" sys_errlist []; .br .BI "int " sys_nerr ; .SH DESCRIPCIÓN La rutina .B perror() produce un mensaje que va a la salida estándar de errores, describiendo el último error encontrado durante una llamada al sistema o a ciertas funciones de biblioteca. Primero (si .I s es distinto de NULL y .RI * s no es NUL) se imprime la cadena .I s pasada como argumento, seguida de un signo de dos puntos y un espacio en blanco. Después se imprime el mensaje y un salto de línea. Para ser de más utilidad, la cadena de caracteres pasada como argumento debería incluir el nombre de la función que incurrió en el error. El código del error se toma de la variable externa .IR errno , que toma un valor cuando ocurre un error pero no es puesta a cero en una llamada no errónea. Puede utilizarse la lista global de errores .IR sys_errlist "[]", indexada por .IR errno, para obtener el mensaje del error sin el salto de línea. El número más alto de mensaje proporcionado en la tabla es .IR sys_nerr " \-1." Tenga cuidado cuando acceda directamente a esta lista porque puede que no se hayan añadido aún nuevos valores de error a .IR sys_errlist "[]." Cuando una llamada al sistema falla, normalmente devuelve \-1 y pone en la variable .I errno un valor que describe qué fue mal. (Estos valores pueden encontrarse en .IR "" .) Muchas funciones de biblioteca también hacen esto. La función .B perror() sirve para traducir este código de error a una forma que los humanos puedan entender. Observe que .I errno tiene un valor sin definir tras una llamada exitosa: esta llamada podría muy bien cambiar incluso el valor de esta variable, a pesar de haber acabado bien, por ejemplo porque internamente empleara alguna otra función de biblioteca que hubiera fallado. Así, si una llamada fallida no es seguida inmediatamente por una llamada a .BR perror , el valor de .I errno debe guardarse. .SH "CONFORME A" C ANSI, BSD 4.3, POSIX, X/OPEN .SH "VÉASE TAMBIÉN" .BR strerror (3)