FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
osdev/stdlib/string.c at master · cstack/osdev · GitHub
cstack
/
osdev
Public
Notifications
You must be signed in to change notification settings
Fork
29
Star
253
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
osdev
/
stdlib
/
string.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (42 loc) · 1.07 KB
Breadcrumbs
osdev
/
stdlib
/
string.c
Copy path
File metadata and controls
51 lines (42 loc) · 1.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include
"string.h"
/*
Returns an integral value indicating the relationship between the strings:
return value indicates
<0 the first character that does not match has a lower value in ptr1 than in ptr2
0 the contents of both strings are equal
>0 the first character that does not match has a greater value in ptr1 than in ptr2
*/
int
strcmp
(
const
char
*
str1
,
const
char
*
str2
) {
while
(
*
str1
!=
0
&&
*
str2
!=
0
) {
int
diff
=
*
str1
-
*
str2
;
if
(
diff
!=
0
) {
return
diff
;
}
str1
++
;
str2
++
;
}
// One of these points to 0
return
*
str1
-
*
str2
;
}
int
strncmp
(
const
char
*
str1
,
const
char
*
str2
,
uint32_t
num
) {
while
(
*
str1
!=
0
&&
*
str2
!=
0
&&
num
>
1
) {
int
diff
=
*
str1
-
*
str2
;
if
(
diff
!=
0
) {
return
diff
;
}
str1
++
;
str2
++
;
num
--
;
}
return
*
str1
-
*
str2
;
}
void
*
memcpy
(
void
*
dest
,
const
void
*
src
,
uint32_t
count
) {
char
*
dest_byte
=
(
char
*
)
dest
;
char
*
src_byte
=
(
char
*
)
src
;
for
(
uint32_t
i
=
0
;
i
<
count
;
i
++
) {
*
dest_byte
=
*
src_byte
;
dest_byte
++
;
src_byte
++
;
}
return
dest
;
}
Back
|
FazBrowse Home
|
New Git URL