]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
New function vfatal which should be used for user messages
authorFlorian Krohm <florian@eich-krohm.de>
Wed, 10 Dec 2014 16:08:09 +0000 (16:08 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Wed, 10 Dec 2014 16:08:09 +0000 (16:08 +0000)
to indicate a situation that can legitimately occur but that
we cannot handle today. The function does not return.

git-svn-id: svn://svn.valgrind.org/vex/trunk@3037

VEX/priv/main_util.c
VEX/priv/main_util.h

index 2031b8869e221c8531503e36db17e4b43e09d6a0..ce93ba516c0a406e6498335600bf5d8c6bf44518 100644 (file)
@@ -263,6 +263,7 @@ void vex_assert_fail ( const HChar* expr,
    (*vex_failure_exit)();
 }
 
+/* To be used in assert-like (i.e. should never ever happen) situations */
 __attribute__ ((noreturn))
 void vpanic ( const HChar* str )
 {
@@ -543,11 +544,9 @@ static void add_to_myprintf_buf ( HChar c )
    }
 }
 
-UInt vex_printf ( const HChar* format, ... )
+static UInt vex_vprintf ( const HChar* format, va_list vargs )
 {
    UInt ret;
-   va_list vargs;
-   va_start(vargs,format);
    
    n_myprintf_buf = 0;
    myprintf_buf[n_myprintf_buf] = 0;      
@@ -557,11 +556,33 @@ UInt vex_printf ( const HChar* format, ... )
       (*vex_log_bytes)( myprintf_buf, n_myprintf_buf );
    }
 
+   return ret;
+}
+
+UInt vex_printf ( const HChar* format, ... )
+{
+   UInt ret;
+   va_list vargs;
+   va_start(vargs, format);
+   ret = vex_vprintf(format, vargs);
    va_end(vargs);
 
    return ret;
 }
 
+/* Use this function to communicate to users that a (legitimate) situation
+   occured that we cannot handle (yet). */
+__attribute__ ((noreturn))
+void vfatal ( const HChar* format, ... )
+{
+   va_list vargs;
+   va_start(vargs, format);
+   vex_vprintf( format, vargs );
+   va_end(vargs);
+   vex_printf("Cannot continue. Good-bye\n\n");
+
+   (*vex_failure_exit)();
+}
 
 /* A general replacement for sprintf(). */
 
index 7573a20639608d2220e510a43a2bd8573bcd7918..85f13a420db2dc312808f3dfb4131d7368c64cb3 100644 (file)
@@ -62,6 +62,9 @@ extern void vex_assert_fail ( const HChar* expr, const HChar* file,
 __attribute__ ((__noreturn__))
 extern void vpanic ( const HChar* str );
 
+__attribute__ ((__noreturn__)) __attribute__ ((format (printf, 1, 2)))
+extern void vfatal ( const HChar* format, ... );
+
 
 /* Printing */