2012-11-10 17:06:01 +01:00
|
|
|
/****************************************************************************
|
2018-05-29 21:21:26 +02:00
|
|
|
* libs/libc/stdio/lib_perror.c
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2013-05-01 17:21:13 +02:00
|
|
|
#include <string.h>
|
2012-11-10 17:06:01 +01:00
|
|
|
#include <errno.h>
|
2021-11-14 20:25:15 +01:00
|
|
|
#include <unistd.h>
|
2012-11-10 17:06:01 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* POSIX requires that perror provide its output on stderr. This option may
|
|
|
|
* be defined, however, to provide perror output that is serialized with
|
|
|
|
* other stdout messages.
|
|
|
|
*/
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2012-11-10 17:06:01 +01:00
|
|
|
#ifdef CONFIG_LIBC_PERROR_STDOUT
|
|
|
|
# define PERROR_STREAM stdout
|
2021-11-14 20:25:15 +01:00
|
|
|
# define PERROR_FILENO STDOUT_FILENO
|
2012-11-10 17:06:01 +01:00
|
|
|
#else
|
|
|
|
# define PERROR_STREAM stderr
|
2021-11-14 20:25:15 +01:00
|
|
|
# define PERROR_FILENO STDERR_FILENO
|
2012-11-10 17:06:01 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: perror
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void perror(FAR const char *s)
|
|
|
|
{
|
|
|
|
/* If strerror() is not enabled, then just print the error number */
|
|
|
|
|
|
|
|
#ifdef CONFIG_LIBC_STRERROR
|
2023-05-20 00:32:34 +02:00
|
|
|
# ifdef CONFIG_FILE_STREAM
|
2021-02-15 09:08:51 +01:00
|
|
|
fprintf(PERROR_STREAM, "%s: %s\n", s, strerror(get_errno()));
|
2023-05-20 00:32:34 +02:00
|
|
|
# else
|
2021-11-14 20:25:15 +01:00
|
|
|
dprintf(PERROR_FILENO, "%s: %s\n", s, strerror(get_errno()));
|
2023-05-20 00:32:34 +02:00
|
|
|
# endif
|
2012-11-10 17:06:01 +01:00
|
|
|
#else
|
2023-05-20 00:32:34 +02:00
|
|
|
# ifdef CONFIG_FILE_STREAM
|
2021-02-15 09:08:51 +01:00
|
|
|
fprintf(PERROR_STREAM, "%s: Error %d\n", s, get_errno());
|
2023-05-20 00:32:34 +02:00
|
|
|
# else
|
2021-11-14 20:25:15 +01:00
|
|
|
dprintf(PERROR_FILENO, "%s: Error %d\n", s, get_errno());
|
2023-05-20 00:32:34 +02:00
|
|
|
# endif
|
2012-11-10 17:06:01 +01:00
|
|
|
#endif
|
|
|
|
}
|