mirror of
https://github.com/rvtr/ctr_firmware.git
synced 2025-06-19 01:05:32 -04:00
(shirait)stdライブラリ追加
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_firmware@276 b871894f-2f95-9b40-918c-086798483c85
This commit is contained in:
parent
2d36dffa45
commit
ba4a3554cf
343
trunk/firmware/include/firm/std/string.h
Normal file
343
trunk/firmware/include/firm/std/string.h
Normal file
@ -0,0 +1,343 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
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: 省サイズを目的とした sscanf.
|
||||
基本的な書式指定 "%(*?)([lh]{,2})([diouxXpn])" に対応.
|
||||
|
||||
Arguments: src 入力文字列
|
||||
fmt 書式制御文字列
|
||||
|
||||
Returns: 代入された値の総数.
|
||||
未代入での終端あるいは不正を検出すれば -1.
|
||||
*---------------------------------------------------------------------------*/
|
||||
extern int stdTSScanf(const char *src, const char *fmt, ...);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: stdTVSScanf
|
||||
|
||||
Description: stdTSScanf の va_list 対応版.
|
||||
基本的な書式指定 "%(*?)([lh]{,2})[diouxX]" に対応.
|
||||
|
||||
Arguments: src 入力文字列
|
||||
fmt 書式制御文字列
|
||||
vlist パラメータ
|
||||
|
||||
Returns: 代入された値の総数.
|
||||
未代入での終端あるいは不正を検出すれば -1.
|
||||
*---------------------------------------------------------------------------*/
|
||||
extern int stdTVSScanf(const char *src, const char *fmt, va_list vlist);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: stdTSPrintf
|
||||
|
||||
Description: 引数の形式以外は stdTVSNPrintf と同じ.
|
||||
|
||||
Arguments: dst 結果を格納するバッファ
|
||||
fmt 書式制御文字列
|
||||
|
||||
Returns: stdVSNPrintf と同じ.
|
||||
*---------------------------------------------------------------------------*/
|
||||
extern int stdTSPrintf(char *dst, const char *fmt, ...);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: stdTVSPrintf
|
||||
|
||||
Description: 引数の形式以外は stdTVSNPrintf と同じ.
|
||||
|
||||
Arguments: dst 結果を格納するバッファ
|
||||
fmt 書式制御文字列
|
||||
vlist パラメータ
|
||||
|
||||
Returns: stdVSNPrintf と同じ.
|
||||
*---------------------------------------------------------------------------*/
|
||||
extern int stdTVSPrintf(char *dst, const char *fmt, va_list vlist);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: stdTSNPrintf
|
||||
|
||||
Description: 引数の形式以外は stdTVSNPrintf と同じ.
|
||||
|
||||
Arguments: dst 結果を格納するバッファ
|
||||
len バッファ長
|
||||
fmt 書式制御文字列
|
||||
|
||||
Returns: stdVSNPrintf と同じ.
|
||||
*---------------------------------------------------------------------------*/
|
||||
extern int stdTSNPrintf(char *dst, size_t len, const char *fmt, ...);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: stdTVSNPrintf
|
||||
|
||||
Description: 省サイズを目的とした sprintf.
|
||||
基本的な書式指定に対応.
|
||||
%([-+# ]?)([0-9]*)(\.?)([0-9]*)([l|ll|h||hh]?)([diouxXpncs%])
|
||||
|
||||
Note: CodeWarrior の MSL sprintf() の挙動にあわせて
|
||||
'+' と '#' は無効にしてある.
|
||||
{ // 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 結果を格納するバッファ
|
||||
len バッファ長
|
||||
fmt 書式制御文字列
|
||||
vlist パラメータ
|
||||
|
||||
Returns: 書式文字列を正しく出力した場合の文字数を返す. ('\0'を含まない)
|
||||
バッファサイズが充分なら全ての文字を出力して終端を付与する.
|
||||
バッファサイズが不足なら切り詰めて dst[len-1] を終端とする.
|
||||
len が 0 の場合は何もしない.
|
||||
|
||||
*---------------------------------------------------------------------------*/
|
||||
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
|
Loading…
Reference in New Issue
Block a user