1 /*---------------------------------------------------------------------------*
2 
3   Copyright (C) Nintendo.  All rights reserved.
4 
5   These coded instructions, statements, and computer programs contain
6   proprietary information of Nintendo of America Inc. and/or Nintendo
7   Company Ltd., and are protected by Federal copyright law.  They may
8   not be disclosed to third parties or copied or duplicated in any form,
9   in whole or in part, without the prior written consent of Nintendo.
10 
11  *---------------------------------------------------------------------------*/
12 
13 #ifndef __DEMOWIN_HELPERS_H_
14 #define __DEMOWIN_HELPERS_H_
15 
16     // Returns darker or lighter with a higher status (opposite brightness if status == -1)
17 CVec4 WhiteDarker(int status);
18 CVec4 BlackLighter(int status);
19 
20     // Literally does nothing
21 void DoNothing();
22 void DoNothingVoidP(void*);
23 
24     // Does nothing, returns true
25 bool BoolDoNothing();
26 bool BoolDoNothingVoidP(void*);
27 
28     // Returns if the values are close
29 bool CloseEnough(float a, float b);
30 
31     // Takes the core as 0, 1, or 2 and turns it into the value the system wants (1, 2, 4)
32 int GetCore(int core);
33 
34     // A "safe" version of strcat
35 char* strcat_s(char* dest, int len, const char* src);
36 
37     // A "safe" version of strcpy
38 char* strcpy_s(char* dest, int len, const char* src);
39 
40     // A "safe" version of sprintf
41 int sprintf_s(char* dest, int len, const char* src, ...);
42 
43     // A "safe" version of vsprintf
44 int vsprintf_s(char* dest, int len, const char* src, va_list list);
45 
46     // A "safe" version of strcat
47 template <int len>
strcat_s(char (& dest)[len],const char * src)48 char* strcat_s(char (&dest)[len], const char* src)
49 {
50     return strcat_s(dest, len, src);
51 }
52 
53     // A "safe" version of strcpy
54 template <int len>
strcpy_s(char (& dest)[len],const char * src)55 char* strcpy_s(char (&dest)[len], const char* src)
56 {
57     return strcpy_s(dest, len, src);
58 }
59 
60     // A "safe" version of sprintf
61 template <int len>
sprintf_s(char (& dest)[len],const char * src,...)62 int sprintf_s(char (&dest)[len], const char* src, ...)
63 {
64     dest[len - 1] = 0;
65 
66     va_list args;
67     va_start (args, src);
68     int count = vsprintf(dest, src, args);
69     va_end (args);
70 
71     ASSERT(dest[len - 1] == 0);
72 
73     return count;
74 }
75 
76     // A "safe" version of vsprintf
77 template <int len>
vsprintf_s(char (& dest)[len],const char * src,va_list list)78 int vsprintf_s(char (&dest)[len], const char* src, va_list list)
79 {
80     dest[len - 1] = 0;
81 
82     int count = vsprintf(dest, src, list);
83 
84     ASSERT(dest[len - 1] == 0);
85 
86     return count;
87 }
88 
89 #endif
90