Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
triazo
/
kernel
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
3
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6a39fd0b
authored
Dec 06, 2015
by
triazo
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
write simple memcpy function
parent
55d156d8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
13 deletions
src/string.c
src/string.h
src/string.c
View file @
6a39fd0b
#include "string.h"
#include <stdbool.h>
void
*
memset
(
void
*
s
,
int
c
,
size_t
n
){
void
*
memset
(
void
*
s
,
int
c
,
size_t
n
)
{
unsigned
char
*
p
=
s
;
while
(
n
--
)
*
p
++=
(
unsigned
char
)
c
;
return
s
;
}
void
memcpy
(
void
*
dest
,
void
*
src
,
size_t
n
)
{
size_t
i
;
char
*
d
=
(
char
*
)
dest
;
char
*
s
=
(
char
*
)
src
;
for
(
i
=
0
;
i
<
n
;
++
i
)
{
d
[
i
]
=
s
[
i
];
}
}
void
reverse
(
char
s
[]
)
{
int
c
,
i
,
j
;
for
(
i
=
0
,
j
=
strlen
(
s
)
-
1
;
i
<
j
;
i
++
,
j
--
)
{
c
=
s
[
i
];
...
...
@@ -23,7 +35,7 @@ void reverse ( char s[] )
void
itoa
(
int
n
,
char
s
[])
{
int
i
,
sign
;
if
((
sign
=
n
)
<
0
)
/* record sign */
{
n
=
-
n
;
/* make n positive */
...
...
@@ -42,7 +54,7 @@ void itoa(int n, char s[])
}
size_t
strlen
(
const
char
*
str
)
size_t
strlen
(
const
char
*
str
)
{
size_t
ret
=
0
;
while
(
str
[
ret
]
!=
0
)
...
...
@@ -69,7 +81,7 @@ int strncmp(const char *s1, const char *s2, size_t n)
return
0
;
}
int
atoi
(
const
char
*
p
)
int
atoi
(
const
char
*
p
)
{
int
k
=
0
;
while
(
*
p
)
{
...
...
@@ -88,36 +100,36 @@ int stoi(const char *str)
{
if
((
*
str
)
==
0
)
return
0
;
int
res
=
0
;
int
sign
=
1
;
int
i
=
0
;
int
i
=
0
;
if
(
str
[
0
]
==
'-'
)
{
sign
=
-
1
;
i
++
;
}
for
(;
str
[
i
]
!=
'\0'
;
++
i
)
{
if
(
isNumericChar
(
str
[
i
])
==
false
)
return
0
;
res
=
res
*
10
+
str
[
i
]
-
'0'
;
}
return
sign
*
res
;
}
double
atof
(
const
char
*
num
)
{
if
(
!
num
||
!*
num
)
return
0
;
return
0
;
double
integerPart
=
0
;
double
fractionPart
=
0
;
int
divisorForFraction
=
1
;
int
sign
=
1
;
bool
inFraction
=
false
;
if
(
*
num
==
'-'
)
{
++
num
;
...
...
src/string.h
View file @
6a39fd0b
...
...
@@ -2,7 +2,8 @@
#define _STRING_ING
#include<stddef.h>
void
*
memset
(
void
*
s
,
int
c
,
size_t
n
);
void
*
memset
(
void
*
s
,
int
c
,
size_t
n
);
void
memcpy
(
void
*
dest
,
void
*
src
,
size_t
n
);
void
itoa
(
int
n
,
char
s
[]);
size_t
strlen
(
const
char
*
str
);
int
strcmp
(
const
char
*
s1
,
const
char
*
s2
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment