2021-11-25 09:44:06 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* libs/libc/misc/lib_err.c
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2023-02-01 11:05:58 +01:00
|
|
|
#include <nuttx/sched.h>
|
|
|
|
|
2021-11-25 09:44:06 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define VA(call) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
va_list ap; \
|
|
|
|
va_start(ap, fmt); \
|
|
|
|
call; \
|
|
|
|
va_end(ap); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: vwarn
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void vwarn(FAR const char *fmt, va_list ap)
|
|
|
|
{
|
2023-10-18 03:17:28 +02:00
|
|
|
int error = get_errno();
|
2021-11-25 09:44:06 +01:00
|
|
|
struct va_format vaf;
|
|
|
|
|
|
|
|
#ifdef va_copy
|
|
|
|
va_list copy;
|
|
|
|
|
|
|
|
va_copy(copy, ap);
|
|
|
|
|
|
|
|
vaf.fmt = fmt;
|
|
|
|
vaf.va = ©
|
|
|
|
#else
|
|
|
|
vaf.fmt = fmt;
|
|
|
|
vaf.va = ≈
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_FILE_STREAM
|
2023-02-01 11:05:58 +01:00
|
|
|
fprintf(stderr, "%d: %pV: %s\n", _SCHED_GETTID(), &vaf, strerror(error));
|
2021-11-25 09:44:06 +01:00
|
|
|
#else
|
2023-02-01 11:05:58 +01:00
|
|
|
dprintf(STDERR_FILENO, "%d: %pV: %s\n", _SCHED_GETTID(),
|
|
|
|
&vaf, strerror(error));
|
2021-11-25 09:44:06 +01:00
|
|
|
#endif
|
2022-04-01 10:01:41 +02:00
|
|
|
|
|
|
|
#ifdef va_copy
|
|
|
|
va_end(copy);
|
|
|
|
#endif
|
2021-11-25 09:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: vwarnx
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void vwarnx(FAR const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
struct va_format vaf;
|
|
|
|
|
|
|
|
#ifdef va_copy
|
|
|
|
va_list copy;
|
|
|
|
|
|
|
|
va_copy(copy, ap);
|
|
|
|
|
|
|
|
vaf.fmt = fmt;
|
|
|
|
vaf.va = ©
|
|
|
|
#else
|
|
|
|
vaf.fmt = fmt;
|
|
|
|
vaf.va = ≈
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_FILE_STREAM
|
2023-02-01 11:05:58 +01:00
|
|
|
fprintf(stderr, "%d: %pV\n", _SCHED_GETTID(), &vaf);
|
2021-11-25 09:44:06 +01:00
|
|
|
#else
|
2023-02-01 11:05:58 +01:00
|
|
|
dprintf(STDERR_FILENO, "%d: %pV\n", _SCHED_GETTID(), &vaf);
|
2021-11-25 09:44:06 +01:00
|
|
|
#endif
|
2022-03-19 07:23:36 +01:00
|
|
|
|
|
|
|
#ifdef va_copy
|
|
|
|
va_end(copy);
|
|
|
|
#endif
|
2021-11-25 09:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: warn
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void warn(FAR const char *fmt, ...)
|
|
|
|
{
|
|
|
|
VA(vwarn(fmt, ap));
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: warnx
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void warnx(FAR const char *fmt, ...)
|
|
|
|
{
|
|
|
|
VA(vwarnx(fmt, ap));
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: verr
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void verr(int status, FAR const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
vwarn(fmt, ap);
|
|
|
|
exit(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: verrx
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void verrx(int status, FAR const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
vwarnx(fmt, ap);
|
|
|
|
exit(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: err
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void err(int status, FAR const char *fmt, ...)
|
|
|
|
{
|
|
|
|
VA(verr(status, fmt, ap));
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: errx
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void errx(int status, FAR const char *fmt, ...)
|
|
|
|
{
|
|
|
|
VA(verrx(status, fmt, ap));
|
|
|
|
}
|