mirror of
https://github.com/rvtr/ctr_firmware.git
synced 2025-06-19 01:05:32 -04:00

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_firmware@276 b871894f-2f95-9b40-918c-086798483c85
344 lines
12 KiB
C
344 lines
12 KiB
C
/*---------------------------------------------------------------------------*
|
||
Project: TwlSDK - STD - include
|
||
File: string.h
|
||
|
||
Copyright 2005-2008 Nintendo. All rights reserved.
|
||
|
||
These coded instructions, statements, and computer programs contain
|
||
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||
Company Ltd., and are protected by Federal copyright law. They may
|
||
not be disclosed to third parties or copied or duplicated in any form,
|
||
in whole or in part, without the prior written consent of Nintendo.
|
||
|
||
$Date:: $
|
||
$Rev$
|
||
$Author$
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
#ifndef FIRM_STD_STRING_H_
|
||
#define FIRM_STD_STRING_H_
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#include <stddef.h>
|
||
#include <stdarg.h>
|
||
|
||
#include <brom/misc.h>
|
||
#include <brom/types.h>
|
||
#include <brom/mi/memory.h>
|
||
|
||
//---- aliases
|
||
#define stdStrCpy stdCopyString
|
||
#define stdStrLCpy stdCopyLString
|
||
#define stdStrChr stdSearchChar
|
||
#define stdStrRChr stdSearchCharReverse
|
||
#define stdStrStr stdSearchString
|
||
#define stdStrLen stdGetStringLength
|
||
#define stdStrNLen stdGetStringNLength
|
||
#define stdStrCat stdConcatenateString
|
||
#define stdStrLCat stdConcatenateLString
|
||
#define stdStrCmp stdCompareString
|
||
#define stdStrNCmp stdCompareNString
|
||
#define stdStrLCmp stdCompareLString
|
||
|
||
#define stdMemCpy stdCopyMemory
|
||
#define stdMemMove stdMoveMemory
|
||
#define stdMemSet stdFillMemory
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdCopyString
|
||
|
||
Description: same to strcpy
|
||
|
||
Arguments: destp : destination pointer
|
||
srcp : src pointer
|
||
|
||
Returns: pointer to destination
|
||
*---------------------------------------------------------------------------*/
|
||
extern char *stdCopyString(char *destp, const char *srcp);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdCopyLStringZeroFill
|
||
|
||
Description: do not correspond with strlcpy
|
||
|
||
Arguments: destp : destination pointer
|
||
srcp : src pointer
|
||
n : copy size + 1
|
||
|
||
Returns: size of src
|
||
*---------------------------------------------------------------------------*/
|
||
extern int stdCopyLStringZeroFill(char *destp, const char *srcp, int n);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdCopyLString
|
||
|
||
Description: same to strlcpy
|
||
|
||
Arguments: destp : destination pointer
|
||
srcp : src pointer
|
||
siz : copy size + 1
|
||
|
||
Returns: size of src
|
||
*---------------------------------------------------------------------------*/
|
||
extern int stdCopyLString(char *destp, const char *srcp, int siz);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdSearchChar
|
||
|
||
Description: same to strchr
|
||
|
||
Arguments: srcp : src string
|
||
c : character to search from src pointer
|
||
|
||
Returns: pointer to destination
|
||
*---------------------------------------------------------------------------*/
|
||
extern char *stdSearchChar(const char *srcp, int c);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdSearchCharReverse
|
||
|
||
Description: same to strrchr
|
||
|
||
Arguments: srcp : src string
|
||
c : character to search from src pointer
|
||
|
||
Returns: pointer to destination
|
||
*---------------------------------------------------------------------------*/
|
||
extern char *stdSearchCharReverse(const char *srcp, int c);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdSearchString
|
||
|
||
Description: same to strstr
|
||
|
||
Arguments: srcp : src string
|
||
str : string to search from src pointer
|
||
|
||
Returns: pointer to destination
|
||
*---------------------------------------------------------------------------*/
|
||
extern char *stdSearchString(const char *srcp, const char *str);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdGetStringLength
|
||
|
||
Description: get string length. same to strlen
|
||
|
||
Arguments: str : string
|
||
|
||
Returns: string length
|
||
*---------------------------------------------------------------------------*/
|
||
extern int stdGetStringLength(const char *str);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdGetStringNLength
|
||
|
||
Description: get string length below len. same to strnlen
|
||
|
||
Arguments: str : string
|
||
len : max length
|
||
|
||
Returns: string length
|
||
*---------------------------------------------------------------------------*/
|
||
extern int stdGetStringNLength(const char *str, int len);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdConcatenateString
|
||
|
||
Description: concatenate strings. same to strcat
|
||
|
||
Arguments: str1 : original string
|
||
str2 : string to concatenate
|
||
|
||
Returns: concatenated string
|
||
*---------------------------------------------------------------------------*/
|
||
extern char *stdConcatenateString(char *str1, const char *str2);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdConcatenateLString
|
||
|
||
Description: concatenate strings. same to strlcat
|
||
|
||
Arguments: str1 : original string
|
||
str2 : string to concatenate
|
||
size : buffer size of str1
|
||
|
||
Returns: length of str1 + length of str2
|
||
*---------------------------------------------------------------------------*/
|
||
extern int stdConcatenateLString(char *str1, const char *str2, int size);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdCompareString
|
||
|
||
Description: compare strings. same to strcmp
|
||
|
||
Arguments: str1, str2 : strings
|
||
|
||
Returns: 0 if same
|
||
*---------------------------------------------------------------------------*/
|
||
extern int stdCompareString(const char *str1, const char *str2);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdCompareNString
|
||
|
||
Description: same to strncmp
|
||
|
||
Arguments: str1, str2 : strings
|
||
len : max length
|
||
|
||
Returns: 0 if same
|
||
*---------------------------------------------------------------------------*/
|
||
extern int stdCompareNString(const char *str1, const char *str2, int len);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdCompareLString
|
||
|
||
Description: same to strlcmp
|
||
|
||
Arguments: str1, str2 : strings
|
||
len : max length
|
||
|
||
Returns: 0 if same
|
||
*---------------------------------------------------------------------------*/
|
||
extern int stdCompareLString(const char *str1, const char *str2, int len);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdCompareNString
|
||
|
||
Description: same to strncasecmp
|
||
|
||
Arguments: str1, str2 : strings
|
||
len : max length
|
||
|
||
Returns: 0 if same
|
||
*---------------------------------------------------------------------------*/
|
||
extern int stdCompareNIString(const char *str1, const char *str2, int len);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdTSScanf
|
||
|
||
Description: <20>ȃT<C883>C<EFBFBD>Y<EFBFBD><59><EFBFBD>ړI<DA93>Ƃ<EFBFBD><C682><EFBFBD> sscanf.
|
||
<20><><EFBFBD>{<7B>I<EFBFBD>ȏ<EFBFBD><C88F><EFBFBD><EFBFBD>w<EFBFBD><77> "%(*?)([lh]{,2})([diouxXpn])" <20>ɑΉ<C991>.
|
||
|
||
Arguments: src <20><><EFBFBD>͕<EFBFBD><CD95><EFBFBD><EFBFBD><EFBFBD>
|
||
fmt <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䕶<EFBFBD><E495B6><EFBFBD><EFBFBD>
|
||
|
||
Returns: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ꂽ<EFBFBD>l<EFBFBD>̑<EFBFBD><CC91><EFBFBD>.
|
||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ł̏I<CC8F>[<5B><><EFBFBD>邢<EFBFBD>͕s<CD95><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD> -1.
|
||
*---------------------------------------------------------------------------*/
|
||
extern int stdTSScanf(const char *src, const char *fmt, ...);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdTVSScanf
|
||
|
||
Description: stdTSScanf <20><> va_list <20>Ή<EFBFBD><CE89><EFBFBD>.
|
||
<20><><EFBFBD>{<7B>I<EFBFBD>ȏ<EFBFBD><C88F><EFBFBD><EFBFBD>w<EFBFBD><77> "%(*?)([lh]{,2})[diouxX]" <20>ɑΉ<C991>.
|
||
|
||
Arguments: src <20><><EFBFBD>͕<EFBFBD><CD95><EFBFBD><EFBFBD><EFBFBD>
|
||
fmt <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䕶<EFBFBD><E495B6><EFBFBD><EFBFBD>
|
||
vlist <20>p<EFBFBD><70><EFBFBD><EFBFBD><EFBFBD>[<5B>^
|
||
|
||
Returns: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ꂽ<EFBFBD>l<EFBFBD>̑<EFBFBD><CC91><EFBFBD>.
|
||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ł̏I<CC8F>[<5B><><EFBFBD>邢<EFBFBD>͕s<CD95><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD> -1.
|
||
*---------------------------------------------------------------------------*/
|
||
extern int stdTVSScanf(const char *src, const char *fmt, va_list vlist);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdTSPrintf
|
||
|
||
Description: <20><><EFBFBD><EFBFBD><EFBFBD>̌`<60><><EFBFBD>ȊO<C88A><4F> stdTVSNPrintf <20>Ɠ<EFBFBD><C693><EFBFBD>.
|
||
|
||
Arguments: dst <20><><EFBFBD>ʂ<EFBFBD><CA82>i<EFBFBD>[<5B><><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD>b<EFBFBD>t<EFBFBD>@
|
||
fmt <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䕶<EFBFBD><E495B6><EFBFBD><EFBFBD>
|
||
|
||
Returns: stdVSNPrintf <20>Ɠ<EFBFBD><C693><EFBFBD>.
|
||
*---------------------------------------------------------------------------*/
|
||
extern int stdTSPrintf(char *dst, const char *fmt, ...);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdTVSPrintf
|
||
|
||
Description: <20><><EFBFBD><EFBFBD><EFBFBD>̌`<60><><EFBFBD>ȊO<C88A><4F> stdTVSNPrintf <20>Ɠ<EFBFBD><C693><EFBFBD>.
|
||
|
||
Arguments: dst <20><><EFBFBD>ʂ<EFBFBD><CA82>i<EFBFBD>[<5B><><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD>b<EFBFBD>t<EFBFBD>@
|
||
fmt <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䕶<EFBFBD><E495B6><EFBFBD><EFBFBD>
|
||
vlist <20>p<EFBFBD><70><EFBFBD><EFBFBD><EFBFBD>[<5B>^
|
||
|
||
Returns: stdVSNPrintf <20>Ɠ<EFBFBD><C693><EFBFBD>.
|
||
*---------------------------------------------------------------------------*/
|
||
extern int stdTVSPrintf(char *dst, const char *fmt, va_list vlist);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdTSNPrintf
|
||
|
||
Description: <20><><EFBFBD><EFBFBD><EFBFBD>̌`<60><><EFBFBD>ȊO<C88A><4F> stdTVSNPrintf <20>Ɠ<EFBFBD><C693><EFBFBD>.
|
||
|
||
Arguments: dst <20><><EFBFBD>ʂ<EFBFBD><CA82>i<EFBFBD>[<5B><><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD>b<EFBFBD>t<EFBFBD>@
|
||
len <20>o<EFBFBD>b<EFBFBD>t<EFBFBD>@<40><>
|
||
fmt <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䕶<EFBFBD><E495B6><EFBFBD><EFBFBD>
|
||
|
||
Returns: stdVSNPrintf <20>Ɠ<EFBFBD><C693><EFBFBD>.
|
||
*---------------------------------------------------------------------------*/
|
||
extern int stdTSNPrintf(char *dst, size_t len, const char *fmt, ...);
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
Name: stdTVSNPrintf
|
||
|
||
Description: <20>ȃT<C883>C<EFBFBD>Y<EFBFBD><59><EFBFBD>ړI<DA93>Ƃ<EFBFBD><C682><EFBFBD> sprintf.
|
||
<20><><EFBFBD>{<7B>I<EFBFBD>ȏ<EFBFBD><C88F><EFBFBD><EFBFBD>w<EFBFBD><77><EFBFBD>ɑΉ<C991>.
|
||
%([-+# ]?)([0-9]*)(\.?)([0-9]*)([l|ll|h||hh]?)([diouxXpncs%])
|
||
|
||
Note: CodeWarrior <20><> MSL sprintf() <20>̋<EFBFBD><CC8B><EFBFBD><EFBFBD>ɂ<EFBFBD><C982>킹<EFBFBD><ED82B9>
|
||
'+' <20><> '#' <20>͖<EFBFBD><CD96><EFBFBD><EFBFBD>ɂ<EFBFBD><C982>Ă<EFBFBD><C482><EFBFBD>.
|
||
{ // exsample
|
||
char buf[5];
|
||
sprintf(buf, "%-i\n", 45); // "45" (OK)
|
||
sprintf(buf, "%0i\n", 45); // "45" (OK)
|
||
sprintf(buf, "% i\n", 45); // " 45" (OK)
|
||
sprintf(buf, "%+i\n", 45); // "%+i" ("+45" expected)
|
||
sprintf(buf, "%#x\n", 45); // "%#x" ("0x2d" expected)
|
||
// but, this works correctly!
|
||
sprintf(buf, "% +i\n", 45); // "+45" (OK)
|
||
}
|
||
|
||
Arguments: dst <20><><EFBFBD>ʂ<EFBFBD><CA82>i<EFBFBD>[<5B><><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD>b<EFBFBD>t<EFBFBD>@
|
||
len <20>o<EFBFBD>b<EFBFBD>t<EFBFBD>@<40><>
|
||
fmt <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䕶<EFBFBD><E495B6><EFBFBD><EFBFBD>
|
||
vlist <20>p<EFBFBD><70><EFBFBD><EFBFBD><EFBFBD>[<5B>^
|
||
|
||
Returns: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>𐳂<EFBFBD><F090B382><EFBFBD><EFBFBD>o<EFBFBD>͂<EFBFBD><CD82><EFBFBD><EFBFBD>ꍇ<EFBFBD>̕<EFBFBD><CC95><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԃ<EFBFBD>. ('\0'<27><><EFBFBD>܂܂Ȃ<DC82>)
|
||
<20>o<EFBFBD>b<EFBFBD>t<EFBFBD>@<40>T<EFBFBD>C<EFBFBD>Y<EFBFBD><59><EFBFBD>[<5B><><EFBFBD>Ȃ<EFBFBD><C882>S<EFBFBD>Ă̕<C482><CC95><EFBFBD><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD>͂<EFBFBD><CD82>ďI<C48F>[<5B><><EFBFBD>t<EFBFBD>^<5E><><EFBFBD><EFBFBD>.
|
||
<20>o<EFBFBD>b<EFBFBD>t<EFBFBD>@<40>T<EFBFBD>C<EFBFBD>Y<EFBFBD><59><EFBFBD>s<EFBFBD><73><EFBFBD>Ȃ<EFBFBD><C882><EFBFBD><D882>l<EFBFBD>߂<EFBFBD> dst[len-1] <20><><EFBFBD>I<EFBFBD>[<5B>Ƃ<EFBFBD><C682><EFBFBD>.
|
||
len <20><> 0 <20>̏ꍇ<CC8F>͉<EFBFBD><CD89><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȃ<EFBFBD>.
|
||
|
||
*---------------------------------------------------------------------------*/
|
||
extern int stdTVSNPrintf(char *dst, size_t len, const char *fmt, va_list vlist);
|
||
|
||
|
||
static inline void* stdCopyMemory(void *destp, const void *srcp, u32 size)
|
||
{
|
||
miCpuCopy(srcp, destp, size);
|
||
return destp;
|
||
}
|
||
|
||
static inline void* stdMoveMemory(void *destp, const void *srcp, u32 size)
|
||
{
|
||
miCpuMove(srcp, destp, size);
|
||
return destp;
|
||
}
|
||
|
||
static inline void* stdFillMemory(void *destp, u8 data, u32 size)
|
||
{
|
||
miCpuFill(destp, data, size);
|
||
return destp;
|
||
}
|
||
|
||
#ifdef __cplusplus
|
||
} /* extern "C" */
|
||
#endif
|
||
|
||
/* FIRM_STD_STRING_H_ */
|
||
#endif
|