diff -r 000000000000 -r e4d67989cc36 genericopenlibs/cstdlib/LSTDIO/PERROR.C --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/genericopenlibs/cstdlib/LSTDIO/PERROR.C Tue Feb 02 02:01:42 2010 +0200 @@ -0,0 +1,90 @@ +/* +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* FUNCTION +* <>---print an error message on standard error +* INDEX +* perror +* INDEX +* _perror_r +* ANSI_SYNOPSIS +* #include +* void perror(char *<[prefix]>); +* void _perror_r(void *<[reent]>, char *<[prefix]>); +* TRAD_SYNOPSIS +* #include +* void perror(<[prefix]>) +* char *<[prefix]>; +* void _perror_r(<[reent]>, <[prefix]>) +* char *<[reent]>; +* char *<[prefix]>; +* Use <> to print (on standard error) an error message +* corresponding to the current value of the global variable <>. +* Unless you use <> as the value of the argument <[prefix]>, the +* error message will begin with the string at <[prefix]>, followed by a +* colon and a space (<<: >>). The remainder of the error message is one +* of the strings described for <>. +* The alternate function <<_perror_r>> is a reentrant version. The +* extra argument <[reent]> is a pointer to a reentrancy structure. +* RETURNS +* <> returns no result. +* PORTABILITY +* ANSI C requires <>, but the strings issued vary from one +* implementation to another. +* Supporting OS subroutines required: <>, <>, <>, +* <>, <>, <>, <>. +* +* +*/ + + + +#include +#include +#include + +/** +A reentrant version of perror(). +*/ +EXPORT_C void +_perror_r (struct _reent *ptr, const char *s) +{ + char *error; + FILE *efp = _stderr_r(ptr); + + if (s != NULL && *s != '\0') + { + fputs (s, efp); + fputs (": ", efp); + } + + error = strerror (ptr->_errno); + if (*error == '\0') + fprintf (efp, "error %d\n", ptr->_errno); + else + { + fputs (error, efp); + fputc ('\n', efp); + } +} + +#ifndef _REENT_ONLY + +EXPORT_C void +perror (const char *s) +{ + _perror_r (_REENT, s); +} + +#endif