Nugget
Bare-metal libraries and examples for the original PlayStation
Loading...
Searching...
No Matches
string.c
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2020 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
29
30// clang-format off
31
33 char b[32];
34 char * s;
35
36 b[16] = 'a';
37 b[17] = 'b';
38 b[18] = 'c';
39 b[19] = 0;
40
41 s = syscall_strcpy(b, b + 16);
44)
45
47 char b[9];
48 char * s;
49
50 b[8] = 0;
51 s = syscall_memset(b, 's', sizeof(b) - 1);
54)
55
57 char b[8];
58 char * s;
59
60 syscall_memset(b, 0, sizeof(b));
61 s = syscall_strncpy(b, "0123456789abcdef", sizeof(b) - 1);
63 cester_assert_str_equal("0123456", b);
64)
65
66CESTER_TEST(strncpySmaller, test_instance,
67 char b[8] = { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'};
68 char * s;
69
70 s = syscall_strncpy(b, "abc", sizeof(b));
81)
82
84 char b[8] = { 'a', 'b', 'c', 0, 'x', 'x', 'x', 'x' };
85 char * s;
86
87 s = syscall_strncat(b, "123456", 3);
89 cester_assert_str_equal("abc123", b);
91 cester_assert_int_eq('x', b[7]);
92)
93
94CESTER_TEST(strncatSmaller, test_instance,
95 char b[8] = { 'a', 'b', 'c', 0, 'x', 'x', 'x', 'x' };
96 char * s;
97
98 s = syscall_strncat(b, "123", 6);
101 cester_assert_int_eq(0, b[6]);
103)
104
105CESTER_TEST(strchrTerminator, test_instance,
106 char b[8] = { 'a', 'b', 'a', 0, 'a', 'x', 'x', 0 };
107 char e[1] = { 0 };
108
109 cester_assert_ptr_equal(b + 3, syscall_strchr(b, 0));
110 cester_assert_ptr_equal(b + 3, syscall_strrchr(b, 0));
111 cester_assert_ptr_equal(b + 3, syscall_index(b, 0));
112 cester_assert_ptr_equal(b + 3, syscall_rindex(b, 0));
113 cester_assert_ptr_equal(e, syscall_strchr(e, 0));
114 cester_assert_ptr_equal(e, syscall_strrchr(e, 0));
115)
116
117CESTER_TEST(strchrCharacter, test_instance,
118 char b[8] = { 'a', 'b', 'a', 0, 'a', 'x', 'x', 0 };
119 char e[1] = { 0 };
120
121 cester_assert_ptr_equal(b, syscall_strchr(b, 'a'));
122 cester_assert_ptr_equal(b + 2, syscall_strrchr(b, 'a'));
123 cester_assert_ptr_equal(b + 1, syscall_strchr(b, 'b'));
124 cester_assert_ptr_equal(b + 1, syscall_strrchr(b, 'b'));
125 cester_assert_null(syscall_strchr(b, 'x'));
126 cester_assert_null(syscall_strrchr(b, 'x'));
127 cester_assert_null(syscall_strchr(e, 'a'));
128 cester_assert_null(syscall_strrchr(e, 'a'));
129)
130
131CESTER_TEST(strchrLowByte, test_instance,
132 char b[4] = { 'a', (char)0xe9, 'a', 0 };
133
134 cester_assert_ptr_equal(b + 1, syscall_strchr(b, 0xe9));
135 cester_assert_ptr_equal(b + 1, syscall_strrchr(b, 0xe9));
136 cester_assert_ptr_equal(b + 1, syscall_strchr(b, (char)0xe9));
137 cester_assert_ptr_equal(b, syscall_strchr(b, 0x161));
138 cester_assert_ptr_equal(b + 2, syscall_strrchr(b, 0x161));
139 cester_assert_ptr_equal(b + 3, syscall_strchr(b, 0x100));
140)
void * memset(void *s, int c, size_t n)
cester_assert_null(syscall_strchr(b, 'x'))
char * s
Definition string.c:48
CESTER_TEST(strcpy, test_instance, char b[32];char *s;b[16]='a';b[17]='b';b[18]='c';b[19]=0;s=syscall_strcpy(b, b+16);cester_assert_ptr_equal(b, s);cester_assert_str_equal(b, b+16);) CESTER_TEST(memset
char b[9]
Definition string.c:47
test_instance
Definition string.c:46
cester_assert_str_equal("ssssssss", b)
cester_assert_ptr_equal(b, s)
char e[1]
Definition string.c:119
cester_assert_int_eq('a', b[0])