Reactos
at master 78 lines 2.0 kB view raw
1/*** 2*errmode.c - modify __error_mode and __acrt_app_type 3* 4* Copyright (c) Microsoft Corporation. All rights reserved. 5* 6*Purpose: 7* Defines _set_error_mode() and _set_app_type(), the routines used 8* to modify __error_mode and __acrt_app_type variables. Together, these 9* two variables determine how/where the C runtime writes error 10* messages. 11* 12*******************************************************************************/ 13 14#include <corecrt_internal.h> 15#include <stdlib.h> 16 17extern "C" { 18 19 20 21/* 22 * __error_mode, together with __acrt_app_type, determine how error messages 23 * are written out. 24 */ 25static int __acrt_error_mode = _OUT_TO_DEFAULT; 26 27/*** 28*int _set_error_mode(int modeval) - interface to change __error_mode 29* 30*Purpose: 31* Control the error (output) sink by setting the value of __error_mode. 32* Explicit controls are to direct output t o standard error (FILE * or 33* C handle or NT HANDLE) or to use the MessageBox API. This routine is 34* exposed and documented for the users. 35* 36*Entry: 37* int modeval = _OUT_TO_DEFAULT, error sink is determined by __acrt_app_type 38* _OUT_TO_STDERR, error sink is standard error 39* _OUT_TO_MSGBOX, error sink is a message box 40* _REPORT_ERRMODE, report the current __error_mode value 41* 42*Exit: 43* Returns old setting or -1 if an error occurs. 44* 45*Exceptions: 46* 47*******************************************************************************/ 48 49int __cdecl _set_error_mode(int const new_error_mode) 50{ 51 switch (new_error_mode) 52 { 53 case _OUT_TO_DEFAULT: 54 case _OUT_TO_STDERR: 55 case _OUT_TO_MSGBOX: 56 { 57 int const old_error_mode = __acrt_error_mode; 58 __acrt_error_mode = new_error_mode; 59 return old_error_mode; 60 } 61 62 case _REPORT_ERRMODE: 63 { 64 return __acrt_error_mode; 65 } 66 67 default: 68 { 69 _VALIDATE_RETURN(("Invalid error_mode", 0), EINVAL, -1); 70 } 71 } 72 73 return 0; 74} 75 76 77 78} // extern "C"