os/ossrv/genericopenlibs/cstdlib/LSTDIO/PERROR.C
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 * FUNCTION
    16 * <<perror>>---print an error message on standard error
    17 * INDEX
    18 * perror
    19 * INDEX
    20 * _perror_r
    21 * ANSI_SYNOPSIS
    22 * #include <stdio.h>
    23 * void perror(char *<[prefix]>);
    24 * void _perror_r(void *<[reent]>, char *<[prefix]>);
    25 * TRAD_SYNOPSIS
    26 * #include <stdio.h>
    27 * void perror(<[prefix]>)
    28 * char *<[prefix]>;
    29 * void _perror_r(<[reent]>, <[prefix]>)
    30 * char *<[reent]>;
    31 * char *<[prefix]>;
    32 * Use <<perror>> to print (on standard error) an error message
    33 * corresponding to the current value of the global variable <<errno>>.
    34 * Unless you use <<NULL>> as the value of the argument <[prefix]>, the
    35 * error message will begin with the string at <[prefix]>, followed by a
    36 * colon and a space (<<: >>). The remainder of the error message is one
    37 * of the strings described for <<strerror>>.
    38 * The alternate function <<_perror_r>> is a reentrant version.  The
    39 * extra argument <[reent]> is a pointer to a reentrancy structure.
    40 * RETURNS
    41 * <<perror>> returns no result.
    42 * PORTABILITY
    43 * ANSI C requires <<perror>>, but the strings issued vary from one
    44 * implementation to another.
    45 * Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
    46 * <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
    47 * 
    48 *
    49 */
    50 
    51 
    52 
    53 #include <stddef.h>
    54 #include <stdio_r.h>
    55 #include <string.h>
    56 
    57 /**
    58 A reentrant version of perror().
    59 */
    60 EXPORT_C void
    61 _perror_r (struct _reent *ptr, const char *s)
    62 {
    63   char *error;
    64   FILE *efp = _stderr_r(ptr);
    65 
    66   if (s != NULL && *s != '\0')
    67     {
    68       fputs (s, efp);
    69       fputs (": ", efp);
    70     }
    71 
    72   error = strerror (ptr->_errno);
    73   if (*error == '\0')
    74       fprintf (efp, "error %d\n", ptr->_errno);
    75   else
    76     {
    77       fputs (error, efp);
    78       fputc ('\n', efp);
    79     }
    80 }
    81 
    82 #ifndef _REENT_ONLY
    83 
    84 EXPORT_C void
    85 perror (const char *s)
    86 {
    87   _perror_r (_REENT, s);
    88 }
    89 
    90 #endif