1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     os_Utility.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 "precompiled.h"
17 
18 #include <nw/types.h>
19 #include <nw/os/os_Utility.h>
20 
21 #if 1
22 // NW_ADAPTIVE_HEADER マクロが使用可能な場合の処理。
23 #include <nw/config/macros.h>
24 
25 #include NW_ADAPTIVE_HEADER_LOCAL(./platform/os_Utility, NW_PLATFORM_NAME.cpp)
26 
27 #else
28 // 使用が不可であれば、#if文の羅列で代替する。
29 
30 #if defined( NW_PLATFORM_RVL )
31     #include "./platform/os_UtilityRVL.cpp"
32 #elif defined( NW_PLATFORM_TWL )
33     #include "./platform/os_UtilityTWL.cpp"
34 #elif defined( NW_PLATFORM_CTR )
35     #include "./platform/os_UtilityCTR.cpp"
36 #elif defined( NW_PLATFORM_CTRWIN )
37     #include "./platform/os_UtilityCTRWIN.cpp"
38 #elif defined( NW_PLATFORM_WIN32 )
39     #include "./platform/os_UtilityWIN32.cpp"
40 #else
41 
42 #error "Unknown platform"
43 
44 #endif
45 
46 #endif
47 
48 
49 namespace nw {
50 namespace os {
51 namespace internal {
52 
53 /*!--------------------------------------------------------------------------*
54   Name:        Printf
55 
56   @brief       書式付き文字列を出力します。
57 
58   @param[in]   fmt    出力文字列フォーマット
59 
60   @return      None.
61  *---------------------------------------------------------------------------*/
62 void
Printf(const char * fmt,...)63 Printf(const char *fmt, ...)
64 {
65     std::va_list vlist;
66     va_start(vlist, fmt);
67 
68     VPrintf(fmt, vlist);
69 
70     va_end(vlist);
71 }
72 
73 /*!--------------------------------------------------------------------------*
74   Name:        Warning
75 
76   @brief       ワーニングを出力します。
77 
78   @param[in]   fileName Warning の発生したソースファイル名
79   @param[in]   line     Warning の発生した行番号
80   @param[in]   fmt      出力文字列フォーマット
81 
82   @return      None.
83  *---------------------------------------------------------------------------*/
84 void
Warning(const char * fileName,int line,const char * fmt,...)85 Warning( const char* fileName, int line, const char* fmt, ...)
86 {
87     va_list vlist;
88     va_start(vlist, fmt);
89 
90     Printf("%s:%d Warning:", fileName, line);
91     VPrintf(fmt, vlist);
92     Printf("\n");
93 
94     va_end(vlist);
95 }
96 
97 /*!--------------------------------------------------------------------------*
98   Name:        Panic
99 
100   @brief       メッセージを出力して停止します。
101 
102   @param[in]   fileName Panic の発生したソースファイル名
103   @param[in]   line     Panic の発生した行番号
104   @param[in]   fmt      出力文字列フォーマット
105 
106   @return      None.
107  *---------------------------------------------------------------------------*/
108 void
Panic(const char * fileName,int line,const char * fmt,...)109 Panic( const char* fileName, int line, const char* fmt, ...)
110 {
111     std::va_list vlist;
112     va_start(vlist, fmt);
113 
114     Printf("%s:%d Panic:", fileName, line);
115     VPrintf(fmt, vlist);
116     Printf("\n");
117 
118     va_end(vlist);
119 
120     Halt();
121 }
122 
123 } // namespace internal
124 
125 /*!--------------------------------------------------------------------------*
126   Name:        SNPrintf
127 
128   @brief       与えられたバッファへ書式付き文字列を出力します。
129 
130   @param[out]  dst     出力先バッファ
131   @param[in]   len     出力先バッファサイズ
132   @param[in]   fmt     出力文字列フォーマット
133 
134   @return      出力文字列の文字列長 ('\0'を除く)
135  *---------------------------------------------------------------------------*/
136 int
SNPrintf(char * dst,size_t len,const char * fmt,...)137 SNPrintf(char* dst, size_t len, const char* fmt, ...)
138 {
139     std::va_list vlist;
140     va_start(vlist, fmt);
141 
142     int ret = VSNPrintf(dst, len, fmt, vlist);
143 
144     va_end(vlist);
145     return ret;
146 }
147 
148 }  // namespace os
149 }  // namespace nw
150 
151 
152