1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LSTDIO/PERROR.C Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,90 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* FUNCTION
1.19 +* <<perror>>---print an error message on standard error
1.20 +* INDEX
1.21 +* perror
1.22 +* INDEX
1.23 +* _perror_r
1.24 +* ANSI_SYNOPSIS
1.25 +* #include <stdio.h>
1.26 +* void perror(char *<[prefix]>);
1.27 +* void _perror_r(void *<[reent]>, char *<[prefix]>);
1.28 +* TRAD_SYNOPSIS
1.29 +* #include <stdio.h>
1.30 +* void perror(<[prefix]>)
1.31 +* char *<[prefix]>;
1.32 +* void _perror_r(<[reent]>, <[prefix]>)
1.33 +* char *<[reent]>;
1.34 +* char *<[prefix]>;
1.35 +* Use <<perror>> to print (on standard error) an error message
1.36 +* corresponding to the current value of the global variable <<errno>>.
1.37 +* Unless you use <<NULL>> as the value of the argument <[prefix]>, the
1.38 +* error message will begin with the string at <[prefix]>, followed by a
1.39 +* colon and a space (<<: >>). The remainder of the error message is one
1.40 +* of the strings described for <<strerror>>.
1.41 +* The alternate function <<_perror_r>> is a reentrant version. The
1.42 +* extra argument <[reent]> is a pointer to a reentrancy structure.
1.43 +* RETURNS
1.44 +* <<perror>> returns no result.
1.45 +* PORTABILITY
1.46 +* ANSI C requires <<perror>>, but the strings issued vary from one
1.47 +* implementation to another.
1.48 +* Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
1.49 +* <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
1.50 +*
1.51 +*
1.52 +*/
1.53 +
1.54 +
1.55 +
1.56 +#include <stddef.h>
1.57 +#include <stdio_r.h>
1.58 +#include <string.h>
1.59 +
1.60 +/**
1.61 +A reentrant version of perror().
1.62 +*/
1.63 +EXPORT_C void
1.64 +_perror_r (struct _reent *ptr, const char *s)
1.65 +{
1.66 + char *error;
1.67 + FILE *efp = _stderr_r(ptr);
1.68 +
1.69 + if (s != NULL && *s != '\0')
1.70 + {
1.71 + fputs (s, efp);
1.72 + fputs (": ", efp);
1.73 + }
1.74 +
1.75 + error = strerror (ptr->_errno);
1.76 + if (*error == '\0')
1.77 + fprintf (efp, "error %d\n", ptr->_errno);
1.78 + else
1.79 + {
1.80 + fputs (error, efp);
1.81 + fputc ('\n', efp);
1.82 + }
1.83 +}
1.84 +
1.85 +#ifndef _REENT_ONLY
1.86 +
1.87 +EXPORT_C void
1.88 +perror (const char *s)
1.89 +{
1.90 + _perror_r (_REENT, s);
1.91 +}
1.92 +
1.93 +#endif