17bf9143922ccfeb1bae1b885ed53bf0426ea5c1
1 /******************************************************************************
2 @file fatal.c
4 @brief TIMAC 2.0 API Handle fatal exit conditions
6 Group: WCS LPC
7 $Target Devices: Linux: AM335x, Embedded Devices: CC1310, CC1350$
9 ******************************************************************************
10 $License: BSD3 2016 $
12 Copyright (c) 2015, Texas Instruments Incorporated
13 All rights reserved.
15 Redistribution and use in source and binary forms, with or without
16 modification, are permitted provided that the following conditions
17 are met:
19 * Redistributions of source code must retain the above copyright
20 notice, this list of conditions and the following disclaimer.
22 * Redistributions in binary form must reproduce the above copyright
23 notice, this list of conditions and the following disclaimer in the
24 documentation and/or other materials provided with the distribution.
26 * Neither the name of Texas Instruments Incorporated nor the names of
27 its contributors may be used to endorse or promote products derived
28 from this software without specific prior written permission.
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
32 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
37 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
38 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
39 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
40 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 ******************************************************************************
42 $Release Name: TI-15.4Stack Linux x64 SDK$
43 $Release Date: July 14, 2016 (2.00.00.30)$
44 *****************************************************************************/
46 #include <compiler.h>
48 #include "fatal.h"
49 #include "log.h"
51 #include <stdio.h>
52 #include <string.h>
53 #include <errno.h>
54 #include <stdarg.h>
55 #include <stdlib.h>
56 #include "hlos_specific.h"
58 /*
59 * printf() a fatal message and exit.
60 *
61 * Public function defined in fatal.h
62 */
63 void FATAL_printf(_Printf_format_string_ const char *fmt, ...)
64 {
65 va_list ap;
66 va_start(ap,fmt);
67 FATAL_vprintf(fmt, ap);
68 /* UNREACHABLE: va_end(ap); */
69 }
71 /*
72 * building block for FATAL_printf()
73 *
74 * Public function defined in fatal.h
75 */
76 void FATAL_vprintf(const char *fmt, va_list ap)
77 {
78 va_list ap_copy;
79 va_copy(ap_copy, ap);
81 LOG_vprintf(LOG_FATAL, fmt, ap);
82 vfprintf(stderr, fmt, ap_copy);
83 _FATAL_exit(1);
84 }
86 /*
87 * print a message followed by a unix error number and message
88 *
89 * Public function defined in fatal.h
90 * see fatal.h
91 */
92 void FATAL_perror(const char *msg)
93 {
94 const char *cp;
95 cp = strerror(errno);
96 if(cp == NULL)
97 {
98 cp = "";
99 }
100 FATAL_printf("%s: (%d) %s\n", msg, errno, cp);
101 }
103 /*
104 * ========================================
105 * Texas Instruments Micro Controller Style
106 * ========================================
107 * Local Variables:
108 * mode: c
109 * c-file-style: "bsd"
110 * tab-width: 4
111 * c-basic-offset: 4
112 * indent-tabs-mode: nil
113 * End:
114 * vim:set filetype=c tabstop=4 shiftwidth=4 expandtab=true
115 */