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
63d7197e
authored
Nov 09, 2015
by
malcolm
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Added more string functions
parent
3e410fcd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
1 deletions
src/string.c
src/string.h
src/string.c
View file @
63d7197e
#include "string.h"
#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
;
unsigned
char
*
p
=
s
;
...
@@ -48,3 +49,62 @@ size_t strlen(const char* str)
...
@@ -48,3 +49,62 @@ size_t strlen(const char* str)
ret
++
;
ret
++
;
return
ret
;
return
ret
;
}
}
int
strcmp
(
const
char
*
s1
,
const
char
*
s2
)
{
while
(
*
s1
&&
(
*
s1
==*
s2
))
{
s1
++
,
s2
++
;
}
return
*
(
const
unsigned
char
*
)
s1
-*
(
const
unsigned
char
*
)
s2
;
}
int
strncmp
(
const
char
*
s1
,
const
char
*
s2
,
size_t
n
)
{
for
(
;
n
>
0
;
s1
++
,
s2
++
,
--
n
)
if
(
*
s1
!=
*
s2
)
return
((
*
(
unsigned
char
*
)
s1
<
*
(
unsigned
char
*
)
s2
)
?
-
1
:
+
1
);
else
if
(
*
s1
==
'\0'
)
return
0
;
return
0
;
}
int
atoi
(
char
*
p
)
{
int
k
=
0
;
while
(
*
p
)
{
k
=
(
k
<<
3
)
+
(
k
<<
1
)
+
(
*
p
)
-
'0'
;
p
++
;
}
return
k
;
}
bool
isNumericChar
(
char
x
)
{
return
(
x
>=
'0'
&&
x
<=
'9'
)
?
true
:
false
;
}
int
stoi
(
char
*
str
)
{
if
(
*
str
==
NULL
)
return
0
;
int
res
=
0
;
int
sign
=
1
;
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
;
}
src/string.h
View file @
63d7197e
...
@@ -5,5 +5,8 @@
...
@@ -5,5 +5,8 @@
void
*
memset
(
void
*
s
,
int
c
,
size_t
n
);
void
*
memset
(
void
*
s
,
int
c
,
size_t
n
);
void
itoa
(
int
n
,
char
s
[]);
void
itoa
(
int
n
,
char
s
[]);
size_t
strlen
(
const
char
*
str
);
size_t
strlen
(
const
char
*
str
);
int
strcmp
(
const
char
*
s1
,
const
char
*
s2
);
int
strncmp
(
const
char
*
s1
,
const
char
*
s2
,
size_t
n
);
int
atoi
(
char
*
p
);
int
stoi
(
char
*
str
);
#endif
#endif
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