static int snprintf(char *str, size_t n, char const *fmt, ...) { va_list ap; int rval; #ifdef VSPRINTF_CHARSTAR char *rp; VA_START(ap, fmt); rp = vsprintf(str, fmt, ap); VA_END(ap); rval = strlen(rp); #else VA_START(ap, fmt); rval = vsprintf(str, fmt, ap); VA_END(ap); #endif if (rval > n) { fprintf(stderr, "snprintf buffer overrun %d > %d\n", rval, (int)n); abort(); } return rval; }
/** Uninstalls a list of protocol interface in the boot services environment. This function calls UnisatllProtocolInterface() in a loop. This is basically a lib function to save space. @param Handle The handle to uninstall the protocol @param ... EFI_GUID followed by protocol instance. A NULL terminates the list. The pairs are the arguments to UninstallProtocolInterface(). All the protocols are added to Handle. @return Status code **/ EFI_STATUS EFIAPI CoreUninstallMultipleProtocolInterfaces ( IN EFI_HANDLE Handle, ... ) { EFI_STATUS Status; VA_LIST Args; EFI_GUID *Protocol; VOID *Interface; UINTN Index; VA_START (Args, Handle); for (Index = 0, Status = EFI_SUCCESS; !EFI_ERROR (Status); Index++) { // // If protocol is NULL, then it's the end of the list // Protocol = VA_ARG (Args, EFI_GUID *); if (Protocol == NULL) { break; } Interface = VA_ARG (Args, VOID *); // // Uninstall it // Status = CoreUninstallProtocolInterface (Handle, Protocol, Interface); } VA_END (Args); // // If there was an error, add all the interfaces that were // uninstalled without any errors // if (EFI_ERROR (Status)) { // // Reset the va_arg back to the first argument. // VA_START (Args, Handle); for (; Index > 1; Index--) { Protocol = VA_ARG(Args, EFI_GUID *); Interface = VA_ARG(Args, VOID *); CoreInstallProtocolInterface (&Handle, Protocol, EFI_NATIVE_INTERFACE, Interface); } VA_END (Args); } return Status; }
/** Prints a debug message to the debug output device if the specified error level is enabled. If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function GetDebugPrintErrorLevel (), then print the message specified by Format and the associated variable argument list to the debug output device. If Format is NULL, then ASSERT(). @param ErrorLevel The error level of the debug message. @param Format Format string for the debug message to print. @param ... A variable argument list whose contents are accessed based on the format string specified by Format. **/ VOID EFIAPI DebugPrint ( IN UINTN ErrorLevel, IN CONST CHAR8 *Format, ... ) { CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; VA_LIST Marker; // // If Format is NULL, then ASSERT(). // ASSERT (Format != NULL); // // Check driver debug mask value and global mask // if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) { return; } // // Convert the DEBUG() message to an ASCII String // VA_START (Marker, Format); AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker); VA_END (Marker); // // Send the print string to EFI_DEBUGPORT_PROTOCOL.Write. // UefiDebugLibDebugPortProtocolWrite (Buffer, AsciiStrLen (Buffer)); }
VOID EFIAPI PrintString ( IN CONST CHAR8 *FormatString, ... ) { #if (DEBUG_PRINT_LEVEL & 0x7FFFFFFF) UINTN Index; CHAR8 PrintBuffer[1000]; VA_LIST Marker; VA_START (Marker, FormatString); AsciiVSPrint (PrintBuffer, sizeof (PrintBuffer), FormatString, Marker); VA_END (Marker); for (Index = 0; PrintBuffer[Index] != 0; Index++) { if (PrintBuffer[Index] == '\n') { mCursor = (UINT8 *) (UINTN) (0xb8000 + (((((UINTN)mCursor - 0xb8000) + 160) / 160) * 160)); } else if (PrintBuffer[Index] != '\r') { // skip non-displayable character *mCursor = (UINT8) PrintBuffer[Index]; mCursor += 2; } } // // All information also output to serial port. // SerialPortWrite ((UINT8 *) PrintBuffer, Index); #endif }
void Logging::Printf(const TDesC8& aSubTag, TRefByValue<const TDesC8> aFmt, ...) { VA_LIST list; VA_START(list,aFmt); Printf(aSubTag, Logging::ELogInfo, aFmt, list); VA_END(list); }
VOID EFIAPI PrintString ( IN CONST CHAR8 *FormatString, ... ) { UINTN Index; CHAR8 PrintBuffer[256]; VA_LIST Marker; VA_START (Marker, FormatString); AsciiVSPrint (PrintBuffer, sizeof (PrintBuffer), FormatString, Marker); VA_END (Marker); for (Index = 0; PrintBuffer[Index] != 0; Index++) { if (PrintBuffer[Index] == '\n') { mCursor = (UINT8 *) (UINTN) (0xb8000 + (((((UINTN)mCursor - 0xb8000) + 160) / 160) * 160)); } else { *mCursor = (UINT8) PrintBuffer[Index]; mCursor += 2; } } // // All information also output to serial port. // SerialPortWrite ((UINT8 *) PrintBuffer, Index); }
VOID EfiDebugPrint ( IN UINTN ErrorLevel, IN CHAR8 *Format, ... ) /*++ Routine Description: Worker function for DEBUG (). If Error Logging hub is loaded log ASSERT information. If Error Logging hub is not loaded do nothing. We use UINT64 buffers due to IPF alignment concerns. Arguments: ErrorLevel - If error level is set do the debug print. Format - String to use for the print, followed by Print arguments. ... - VAR args for Format Returns: None --*/ { VA_LIST Marker; VA_START (Marker, Format); EfiDebugVPrint (ErrorLevel, Format, Marker); VA_END (Marker); }
/** Formatted Print using a Hii Token to reference the localized format string. @param[in] Token A HII token associated with a localized Unicode string. @param[in] ... The variable argument list. @return The number of characters converted by UnicodeVSPrint(). **/ UINTN EFIAPI PrintToken ( IN UINT16 Token, ... ) { VA_LIST Marker; EFI_STRING StringPtr; UINTN Return; UINTN BufferSize; StringPtr = HiiGetString (gHiiHandle, Token, NULL); ASSERT (StringPtr != NULL); VA_START (Marker, Token); BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16); if (mPrintTokenBuffer == NULL) { mPrintTokenBuffer = AllocatePool (BufferSize); ASSERT (mPrintTokenBuffer != NULL); } SetMem( mPrintTokenBuffer, BufferSize, 0); Return = UnicodeVSPrint (mPrintTokenBuffer, BufferSize, StringPtr, Marker); VA_END (Marker); if (Return > 0 && gST->ConOut != NULL) { gST->ConOut->OutputString (gST->ConOut, mPrintTokenBuffer); } FreePool (StringPtr); return Return; }
/** This function prints a series of strings. @param ConOut Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL @param ... A variable argument list containing series of strings, the last string must be NULL. @retval EFI_SUCCESS Success print out the string using ConOut. @retval EFI_STATUS Return the status of the ConOut->OutputString (). **/ EFI_STATUS EFIAPI BdsLibOutputStrings ( IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut, ... ) { VA_LIST Args; EFI_STATUS Status; CHAR16 *String; Status = EFI_SUCCESS; VA_START (Args, ConOut); while (!EFI_ERROR (Status)) { // // If String is NULL, then it's the end of the list // String = VA_ARG (Args, CHAR16 *); if (String == NULL) { break; } Status = ConOut->OutputString (ConOut, String); if (EFI_ERROR (Status)) { break; } } VA_END(Args); return Status; }
UINTN Aprint ( IN CONST CHAR8 *Format, ... ) /*++ Routine Description: Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii characters. Arguments: Format - Ascii format string see file header for more details. ... - Vararg list consumed by processing Format. Returns: Number of characters printed. --*/ { UINTN Return; VA_LIST Marker; UINTN Index; UINTN MaxIndex; CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER]; CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER]; MaxIndex = EfiAsciiStrLen ((CHAR8 *) Format); if (MaxIndex >= EFI_DRIVER_LIB_MAX_PRINT_BUFFER) { // // Format string was too long for use to process. // return 0; } for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER; Index++) { UnicodeFormat[Index] = (CHAR16) Format[Index]; } VA_START (Marker, Format); Return = VSPrint (Buffer, sizeof (Buffer), UnicodeFormat, Marker); VA_END (Marker); // // Need to convert to Unicode to do an OutputString // if (gST->ConOut != NULL) { // // To be extra safe make sure ConOut has been initialized // gST->ConOut->OutputString (gST->ConOut, Buffer); } return Return; }
/** Transfers control to a function starting with a new stack. Transfers control to the function specified by EntryPoint using the new stack new stack specified by NewStack and passing in the parameters specified by Context1 and Context2. Context1 and Context2 are optional and may be NULL. The function EntryPoint must never return. This function supports a variable number of arguments following the NewStack parameter. These additional arguments are ignored on IA-32, x64, and EBC. IPF CPUs expect one additional parameter of type VOID * that specifies the new backing store pointer. If EntryPoint is NULL, then ASSERT(). If NewStack is NULL, then ASSERT(). @param EntryPoint A pointer to function to call with the new stack. @param Context1 A pointer to the context to pass into the EntryPoint function. @param Context2 A pointer to the context to pass into the EntryPoint function. @param NewStack A pointer to the new stack to use for the EntryPoint function. **/ VOID EFIAPI SwitchStack ( IN SWITCH_STACK_ENTRY_POINT EntryPoint, IN VOID *Context1, OPTIONAL IN VOID *Context2, OPTIONAL IN VOID *NewStack, ... ) { VA_LIST Marker; ASSERT (EntryPoint != NULL); ASSERT (NewStack != NULL); VA_START (Marker, NewStack); InternalSwitchStack (EntryPoint, Context1, Context2, NewStack, Marker); VA_END (Marker); // // InternalSwitchStack () will never return // ASSERT (FALSE); }
GLDEF_C void Debug( TRefByValue<const TDesC> aText, ... ) { #ifdef WINS VA_LIST args; VA_START( args, aText ); TBuf<KLogLineLength> buf; buf.FormatList( aText, args ); RFileLogger logger; TInt ret=logger.Connect(); if (ret==KErrNone) { logger.SetDateAndTime( EFalse,EFalse ); logger.CreateLog( KLogFolder, KLogFileName, EFileLoggingModeAppend ); TBuf<KLogTimeFormatLength> timeStamp; TTime now; now.HomeTime(); TDateTime dateTime; dateTime = now.DateTime(); timeStamp.Format( KLogTimeFormat, dateTime.Hour(), dateTime.Minute(), dateTime.Second(), dateTime.MicroSecond() ); buf.Insert( 0, timeStamp ); logger.Write(buf); } logger.Close(); VA_END( args ); #else RDebug::Print(aText); #endif }
EFI_STATUS EFIAPI EfiBootManagerRegisterContinueKeyOption ( IN UINT32 Modifier, ... ) { EFI_STATUS Status; EFI_BOOT_MANAGER_KEY_OPTION KeyOption; VA_LIST Args; if (mContinueKeyOption != NULL) { return EFI_ALREADY_STARTED; } ZeroMem (&KeyOption, sizeof (EFI_BOOT_MANAGER_KEY_OPTION)); VA_START (Args, Modifier); Status = InitializeKeyFields (Modifier, Args, &KeyOption); VA_END (Args); if (!EFI_ERROR (Status)) { mContinueKeyOption = AllocateCopyPool (sizeof (EFI_BOOT_MANAGER_KEY_OPTION), &KeyOption); ASSERT (mContinueKeyOption != NULL); if (mHotkeyServiceStarted) { ProcessKeyOption (mContinueKeyOption); } } return Status; }
UINTN EFIAPI PrintToken ( IN UINT16 Token, IN EFI_HII_HANDLE Handle, ... ) { VA_LIST Marker; UINTN Return; CHAR16 *Format; VA_START (Marker, Handle); Format = HiiGetString (Handle, Token, NULL); ASSERT (Format != NULL); Return = InternalPrintToken (Format, gST->ConOut, Marker); FreePool (Format); VA_END (Marker); return Return; }
UINTN USPrint ( OUT CHAR16 *Buffer, IN UINTN BufferSize, IN CONST CHAR16 *Format, ... ) /*++ Routine Description: Process format and place the results in Buffer for wide chars. Arguments: Buffer - Wide char buffer to print the results of the parsing of Format into. BufferSize - Maximum number of characters to put into buffer. Format - Format string ... - Vararg list consumed by processing Format. Returns: Number of characters printed. --*/ { UINTN Return; VA_LIST Marker; VA_START (Marker, Format); Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker); VA_END (Marker); return Return; }
void CMainControlEngine::WriteLog16(TRefByValue<const TDesC> aFmt, ...) { #ifdef __WRITE_LOG__ //UtilityTools::WriteLogsL(_L("WriteLog16")); TBuf<400> tBuf; VA_LIST list; VA_START(list,aFmt); tBuf.Zero(); tBuf.AppendFormatList(aFmt,list); VA_END(list); HBufC8* buf=CnvUtfConverter::ConvertFromUnicodeToUtf8L(tBuf); ASSERT(buf); CleanupStack::PushL(buf); TBuf<64> time16; TBuf8<64> time8; TTime tTime; tTime.HomeTime(); tTime.FormatL(time16, _L("%D%M%Y%2/%3 %H:%T:%S ")); time8.Copy(time16); iFile.Write(time8); iFile.Write(*buf); iFile.Write(_L8("\x0a\x0d")); CleanupStack::PopAndDestroy(1); //UtilityTools::WriteLogsL(_L("WriteLog16 End")); #endif }
VOID EFIAPI DebugPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format, ...) { CHAR8 szBuf[256]; VA_LIST va; UINTN cch; RTCCUINTREG SavedFlags; /* No pool noise, please. */ if (ErrorLevel == DEBUG_POOL) return; VA_START(va, Format); cch = AsciiVSPrint(szBuf, sizeof(szBuf), Format, va); VA_END(va); /* make sure it's terminated and doesn't end with a newline */ if (cch >= sizeof(szBuf)) cch = sizeof(szBuf) - 1; while (cch > 0 && (szBuf[cch - 1] == '\n' || szBuf[cch - 1] == '\r')) cch--; szBuf[cch] = '\0'; SavedFlags = ASMIntDisableFlags(); VBoxPrintString("dbg/"); VBoxPrintHex(ErrorLevel, sizeof(ErrorLevel)); VBoxPrintChar(' '); VBoxPrintString(szBuf); VBoxPrintChar('\n'); ASMSetFlags(SavedFlags); }
void Logging::Printf(const TDesC8& aSubTag, TLogEntryType aType, TRefByValue<const TDesC8> aFmt, ...) { VA_LIST list; VA_START(list,aFmt); Printf(aSubTag, aType, aFmt, list); VA_END(list); }
VOID EfiDebugPrint ( IN UINTN ErrorLevel, IN CHAR8 *Format, ... ) /*++ Routine Description: Worker function for DEBUG(). If Error Logging hub is loaded log ASSERT information. If Error Logging hub is not loaded do nothing. Arguments: ErrorLevel - If error level is set do the debug print. Format - String to use for the print, followed by Print arguments. Returns: None --*/ { VA_LIST Marker; VA_START (Marker, Format); if (mDebugAssert != NULL) { mDebugAssert->Print (mDebugAssert, ErrorLevel, Format, Marker); } VA_END (Marker); }
VOID UhciError ( IN CHAR8 *Format, ... ) /*++ Routine Description: Debug error print interface for UHCI Arguments: Format - String to use for the print, followed by print arguments Returns: None --*/ { VA_LIST Marker; VA_START (Marker, Format); EfiDebugVPrint (EFI_D_ERROR, Format, Marker); VA_END (Marker); }
/** Prints a debug message to the debug output device if the specified error level is enabled. If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print the message specified by Format and the associated variable argument list to the debug output device. If Format is NULL, then ASSERT(). @param ErrorLevel The error level of the debug message. @param Format Format string for the debug message to print. **/ VOID EFIAPI DebugPrint ( IN UINTN ErrorLevel, IN CONST CHAR8 *Format, ... ) { CHAR8 AsciiBuffer[MAX_DEBUG_MESSAGE_LENGTH]; VA_LIST Marker; // // If Format is NULL, then ASSERT(). // ASSERT (Format != NULL); // // Check driver debug mask value and global mask // if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) { return; } // // Convert the DEBUG() message to a Unicode String // VA_START (Marker, Format); AsciiVSPrint (AsciiBuffer, sizeof (AsciiBuffer), Format, Marker); VA_END (Marker); SemihostWriteString (AsciiBuffer); }
EXPORT_C void NSmlDebugPrintArgs16L( const TText16* aFmt, ... ) { VA_LIST args; VA_START (args, aFmt); TInt err(KErrNone); TRAP(err, _NSmlDebugPrintArgs16L(TPtrC16(aFmt), args)); VA_END(args); }
// ------------------------------------------------------------------------------------------------------------------------------------------------------- void LogClass::MsgBoxError(LPCCH Message, ...) { VA_START ( m_pArguments, Message ); vsprintf ( &szTemp[0], Message, m_pArguments ); VA_END ( m_pArguments ); // ----- MessageBoxA(NULL, szTemp, ErrorMSGCaption, MB_OK|MB_ICONERROR); }
// ------------------------------------------------------------------------------------------------------------------------------------------------------- void LogClass::MsgBox(const char* Caption, LPCCH Message, ...) { VA_START ( m_pArguments, Message ); vsprintf ( &szTemp[0], Message, m_pArguments ); VA_END ( m_pArguments ); // ----- MessageBoxA(NULL, szTemp, Caption, MB_OK | MB_APPLMODAL); }
void pline VA_DECL(const char *, line) { VA_START(line); VA_INIT(line, char *); vpline(line, VA_ARGS); VA_END(); }
/** Prints a debug message to the debug output device if the specified error level is enabled. If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print the message specified by Format and the associated variable argument list to the debug output device. If Format is NULL, then ASSERT(). @param ErrorLevel The error level of the debug message. @param Format Format string for the debug message to print. **/ VOID EFIAPI DebugPrint ( IN UINTN ErrorLevel, IN CONST CHAR8 *Format, ... ) { UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)]; EFI_DEBUG_INFO *DebugInfo; UINTN TotalSize; UINTN Index; VA_LIST Marker; UINT64 *ArgumentPointer; // // If Format is NULL, then ASSERT(). // ASSERT (Format != NULL); // // Check driver Debug Level value and global debug level // if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) { return; } TotalSize = sizeof (EFI_DEBUG_INFO) + 12 * sizeof (UINT64) + AsciiStrLen (Format) + 1; if (TotalSize > EFI_STATUS_CODE_DATA_MAX_SIZE) { return; } // // Then EFI_DEBUG_INFO // DebugInfo = (EFI_DEBUG_INFO *)Buffer; DebugInfo->ErrorLevel = (UINT32)ErrorLevel; // // 256 byte mini Var Arg stack. That is followed by the format string. // VA_START (Marker, Format); for (Index = 0, ArgumentPointer = (UINT64 *)(DebugInfo + 1); Index < 12; Index++, ArgumentPointer++) { WriteUnaligned64(ArgumentPointer, VA_ARG (Marker, UINT64)); } VA_END (Marker); AsciiStrCpy ((CHAR8 *)ArgumentPointer, Format); REPORT_STATUS_CODE_EX ( EFI_DEBUG_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_DC_UNSPECIFIED), 0, NULL, &gEfiStatusCodeDataTypeDebugGuid, DebugInfo, TotalSize ); }
void devd_printf(devd_t *d, const char *fmt, ...) { char buf[SPRINTF_BUFSIZE]; va_list ap; VA_START(ap, fmt); vsnprintf(buf, SPRINTF_BUFSIZE, fmt, ap); VA_END(ap); }
// ------------------------------------------------------------------------------------------------------------------------------------------------------- void LogClass::VLogAddFormat(COLORREF colorText, LPCCH& AddressOfFmt) { PrepareLogBuff(); // ----- VA_START ( m_pArguments, AddressOfFmt ); vsprintf ( &m_LogTempBuff[0], AddressOfFmt, m_pArguments ); VA_END ( m_pArguments ); // ----- LogAddStr(colorText, m_LogTempBuff); }
/*VARARGS1*/ void Norep VA_DECL(const char *, line) { VA_START(line); VA_INIT(line, const char *); no_repeat = TRUE; vpline(line, VA_ARGS); no_repeat = FALSE; VA_END(); return; }
int sprintf_s(char *str, size_t sizeOfBuffer, char const *fmt, ...) { VA_LIST Marker; int NumberOfPrinted; VA_START (Marker, fmt); NumberOfPrinted = (int)AsciiVSPrint (str, sizeOfBuffer, fmt, Marker); VA_END (Marker); return NumberOfPrinted; }