1681cc25c179fdf3462d8366edbc3a886443964c7darylm/** @file
2681cc25c179fdf3462d8366edbc3a886443964c7darylm  The implementation of the __assert function used internally by the assert macro
3681cc25c179fdf3462d8366edbc3a886443964c7darylm  to insert diagnostic messages into code.
4681cc25c179fdf3462d8366edbc3a886443964c7darylm
5681cc25c179fdf3462d8366edbc3a886443964c7darylm  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
62aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm  This program and the accompanying materials are licensed and made available under
72aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm  the terms and conditions of the BSD License that accompanies this distribution.
82aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm  The full text of the license may be found at
9681cc25c179fdf3462d8366edbc3a886443964c7darylm  http://opensource.org/licenses/bsd-license.
102aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm
112aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
122aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
132aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/
142aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm#include  <LibConfig.h>
152aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm#include  <sys/EfiCdefs.h>
162aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm
172aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm#include  <stdio.h>
182aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm#include  <stdlib.h>
192aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm
20681cc25c179fdf3462d8366edbc3a886443964c7darylm/** Internal helper function for the assert macro.
21681cc25c179fdf3462d8366edbc3a886443964c7darylm    The __assert function prints a diagnostic message then exits the
22681cc25c179fdf3462d8366edbc3a886443964c7darylm    currently running application.
23681cc25c179fdf3462d8366edbc3a886443964c7darylm
24681cc25c179fdf3462d8366edbc3a886443964c7darylm    This function should NEVER be called directly.
25681cc25c179fdf3462d8366edbc3a886443964c7darylm
26681cc25c179fdf3462d8366edbc3a886443964c7darylm    Some pre-processors do not provide the __func__ identifier.  When that is
27681cc25c179fdf3462d8366edbc3a886443964c7darylm    the case, __func__ will be NULL.  This function accounts for this and
28681cc25c179fdf3462d8366edbc3a886443964c7darylm    will modify the diagnostic message appropriately.
29681cc25c179fdf3462d8366edbc3a886443964c7darylm
30681cc25c179fdf3462d8366edbc3a886443964c7darylm
31681cc25c179fdf3462d8366edbc3a886443964c7darylm    @param[in]    file          The name of the file containing the assert.
32681cc25c179fdf3462d8366edbc3a886443964c7darylm    @param[in]    func          The name of the function containing the assert
33681cc25c179fdf3462d8366edbc3a886443964c7darylm                                or NULL.
34681cc25c179fdf3462d8366edbc3a886443964c7darylm    @param[in]    line          The line number the assert is located on.
35681cc25c179fdf3462d8366edbc3a886443964c7darylm    @param[in]    failedexpr    A literal representation of the assert's expression.
36681cc25c179fdf3462d8366edbc3a886443964c7darylm
37681cc25c179fdf3462d8366edbc3a886443964c7darylm    @return       The __assert function will never return.  It terminates execution
38681cc25c179fdf3462d8366edbc3a886443964c7darylm                  of the current application and returns to the environment that
39681cc25c179fdf3462d8366edbc3a886443964c7darylm                  the application was launched from.
40681cc25c179fdf3462d8366edbc3a886443964c7darylm**/
412aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmvoid
42681cc25c179fdf3462d8366edbc3a886443964c7darylm__assert(
43681cc25c179fdf3462d8366edbc3a886443964c7darylm  IN  const char *file,
44681cc25c179fdf3462d8366edbc3a886443964c7darylm  IN  const char *func,
45681cc25c179fdf3462d8366edbc3a886443964c7darylm  IN  int         line,
46681cc25c179fdf3462d8366edbc3a886443964c7darylm  IN  const char *failedexpr
47681cc25c179fdf3462d8366edbc3a886443964c7darylm  )
482aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm{
492aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm  if (func == NULL)
502aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm    printf("Assertion failed: (%s), file %s, line %d.\n",
512aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm                failedexpr, file, line);
522aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm  else
53681cc25c179fdf3462d8366edbc3a886443964c7darylm    printf("Assertion failed: (%s), file %s, function %s, line %d.\n",
54681cc25c179fdf3462d8366edbc3a886443964c7darylm                failedexpr, file, func, line);
552aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm  abort();
562aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm  /* NOTREACHED */
572aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm}
58