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