1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     os_UtilityCTRWIN.cpp
4 
5   Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Revision: 13145 $
14  *---------------------------------------------------------------------------*/
15 
16 #include <nn/types.h>
17 #include <nn/os.h>
18 #include <nw/ut/ut_Inlines.h>
19 #include <cstdio>
20 #include <cstdlib>
21 #include <memory.h>
22 #include <windows.h>
23 
24 namespace nw {
25 namespace os {
26 
27 namespace internal {
28 
29 /*!--------------------------------------------------------------------------*
30   Name:        VPrintf
31 
32   @brief       引数リスト指定で書式付き文字列を出力します。
33 
34   @param[in]   fmt     出力文字列フォーマット
35   @param[in]   vlist   可変長引数リスト
36 
37   @return      None.
38  *---------------------------------------------------------------------------*/
39 void
VPrintf(const char * fmt,va_list vlist)40 VPrintf(const char *fmt, va_list vlist)
41 {
42     static const size_t MAX_DEBUG_STRING_LENGTH = 260;
43     static char sDebugString[MAX_DEBUG_STRING_LENGTH];
44 
45     nw::ut::vsnprintf(sDebugString, MAX_DEBUG_STRING_LENGTH, sizeof(sDebugString) - 1, fmt, vlist);
46 
47     printf(sDebugString);
48     OutputDebugStringA( sDebugString );
49 }
50 
51 } // namespace internal
52 
53 /*!--------------------------------------------------------------------------*
54   Name:        Halt
55 
56   @brief       プログラムを異常終了します。
57 
58   @return      None.
59  *---------------------------------------------------------------------------*/
60 void
Halt()61 Halt()
62 {
63     throw "abort!\n";
64     //::std::abort();
65 }
66 
67 /*!--------------------------------------------------------------------------*
68   Name:        VSNPrintf
69 
70   @brief       引数リスト指定で、与えられたバッファへ書式付き文字列を出力します。
71 
72   @param[out]  dst
73   @param[in]   len
74   @param[in]   fmt     出力文字列フォーマット
75   @param[in]   vlist   可変長引数リスト
76 
77   @return      出力文字列の文字列長 ('\0'を除く)
78  *---------------------------------------------------------------------------*/
79 int
VSNPrintf(char * dst,size_t len,const char * fmt,std::va_list vlist)80 VSNPrintf(char* dst, size_t len, const char* fmt, std::va_list vlist)
81 {
82     return vsnprintf_s(dst, len, len - 1, fmt, vlist);
83 }
84 
85 
86 }  // namespace os
87 }  // namespace nw
88