Home | History | Annotate | Download | only in Main
      1 /** @file
      2   The implementation of the __assert function used internally by the assert macro
      3   to insert diagnostic messages into code.
      4 
      5   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
      6   This program and the accompanying materials are licensed and made available under
      7   the terms and conditions of the BSD License that accompanies this distribution.
      8   The full text of the license may be found at
      9   http://opensource.org/licenses/bsd-license.
     10 
     11   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     12   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     13 **/
     14 #include  <LibConfig.h>
     15 #include  <sys/EfiCdefs.h>
     16 
     17 #include  <stdio.h>
     18 #include  <stdlib.h>
     19 
     20 /** Internal helper function for the assert macro.
     21     The __assert function prints a diagnostic message then exits the
     22     currently running application.
     23 
     24     This function should NEVER be called directly.
     25 
     26     Some pre-processors do not provide the __func__ identifier.  When that is
     27     the case, __func__ will be NULL.  This function accounts for this and
     28     will modify the diagnostic message appropriately.
     29 
     30 
     31     @param[in]    file          The name of the file containing the assert.
     32     @param[in]    func          The name of the function containing the assert
     33                                 or NULL.
     34     @param[in]    line          The line number the assert is located on.
     35     @param[in]    failedexpr    A literal representation of the assert's expression.
     36 
     37     @return       The __assert function will never return.  It terminates execution
     38                   of the current application and returns to the environment that
     39                   the application was launched from.
     40 **/
     41 void
     42 __assert(
     43   IN  const char *file,
     44   IN  const char *func,
     45   IN  int         line,
     46   IN  const char *failedexpr
     47   )
     48 {
     49   if (func == NULL)
     50     printf("Assertion failed: (%s), file %s, line %d.\n",
     51                 failedexpr, file, line);
     52   else
     53     printf("Assertion failed: (%s), file %s, function %s, line %d.\n",
     54                 failedexpr, file, func, line);
     55   abort();
     56   /* NOTREACHED */
     57 }
     58