Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FlightOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Armin Luntzer
FlightOS
Commits
cc24e285
Commit
cc24e285
authored
6 years ago
by
Armin Luntzer
Browse files
Options
Downloads
Patches
Plain Diff
implement:
memmove() puts() make public: putchar()
parent
17144112
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/kernel/string.h
+4
-0
4 additions, 0 deletions
include/kernel/string.h
lib/string.c
+99
-0
99 additions, 0 deletions
lib/string.c
lib/vsnprintf.c
+0
-21
0 additions, 21 deletions
lib/vsnprintf.c
with
103 additions
and
21 deletions
include/kernel/string.h
+
4
−
0
View file @
cc24e285
...
...
@@ -28,6 +28,8 @@ int memcmp(const void *s1, const void *s2, size_t n);
void
*
memset
(
void
*
s
,
int
c
,
size_t
n
);
void
*
memcpy
(
void
*
dest
,
const
void
*
src
,
size_t
n
);
void
*
memmove
(
void
*
dest
,
const
void
*
src
,
size_t
n
);
char
*
strcpy
(
char
*
dest
,
const
char
*
src
);
void
bzero
(
void
*
s
,
size_t
n
);
...
...
@@ -45,5 +47,7 @@ int vprintf(const char *format, va_list ap);
int
vsprintf
(
char
*
str
,
const
char
*
format
,
va_list
ap
);
int
vsnprintf
(
char
*
str
,
size_t
size
,
const
char
*
format
,
va_list
ap
);
int
puts
(
const
char
*
s
);
int
putchar
(
int
c
);
#endif
/* _KERNEL_STRING_H_ */
This diff is collapsed.
Click to expand it.
lib/string.c
+
99
−
0
View file @
cc24e285
...
...
@@ -326,6 +326,53 @@ void *memcpy(void *dest, const void *src, size_t n)
EXPORT_SYMBOL
(
memcpy
);
/**
* @brief copy a memory area src that may overlap with area dest
*
* @param dest the destination memory area
* @param src the source memory area
* @param n the number of bytes to copy
*
* @returns a pointer to dest
*/
void
*
memmove
(
void
*
dest
,
const
void
*
src
,
size_t
n
)
{
char
*
d
;
const
char
*
s
;
if
(
dest
<=
src
)
{
d
=
dest
;
s
=
src
;
while
(
n
--
)
{
(
*
d
)
=
(
*
s
);
d
++
;
s
++
;
}
}
else
{
d
=
dest
;
d
+=
n
;
s
=
src
;
s
+=
n
;
while
(
n
--
)
{
d
--
;
s
--
;
(
*
d
)
=
(
*
s
);
}
}
return
dest
;
}
EXPORT_SYMBOL
(
memmove
);
/**
* @brief copy a '\0' terminated string
*
...
...
@@ -378,6 +425,58 @@ void bzero(void *s, size_t n)
EXPORT_SYMBOL
(
bzero
);
/**
* @brief writes the string s and a trailing newline to stdout
*
* @param str the destination buffer
* @param format the format string buffer
* @param ... arguments to the format string
*
* @return the number of characters written to buf
*/
int
puts
(
const
char
*
s
)
{
int
n
;
n
=
vsnprintf
(
NULL
,
INT_MAX
,
s
,
NULL
);
n
+=
vsnprintf
(
NULL
,
INT_MAX
,
"
\n
"
,
NULL
);
return
n
;
}
EXPORT_SYMBOL
(
puts
);
/**
* @brief writes the character c, cast to an unsigned char, to stdout
*
* @param c the character to write
*
* @return the number of characters written to buf
*
* FIXME: this must be replaced by a different mechanic, e.g. provided
* by the architecture or a driver
*/
int
putchar
(
int
c
)
{
#define TREADY 4
static
volatile
int
*
console
=
(
int
*
)
0x80000100
;
while
(
!
(
console
[
1
]
&
TREADY
));
console
[
0
]
=
0x0ff
&
c
;
if
(
c
==
'\n'
)
{
while
(
!
(
console
[
1
]
&
TREADY
));
console
[
0
]
=
(
int
)
'\r'
;
}
return
c
;
}
/**
* @brief print a string into a buffer
...
...
This diff is collapsed.
Click to expand it.
lib/vsnprintf.c
+
0
−
21
View file @
cc24e285
...
...
@@ -58,27 +58,6 @@ struct fmt_spec {
};
#define TREADY 4
static
volatile
int
*
console
=
(
int
*
)
0x80000100
;
static
int
putchar
(
int
c
)
{
while
(
!
(
console
[
1
]
&
TREADY
));
console
[
0
]
=
0x0ff
&
c
;
if
(
c
==
'\n'
)
{
while
(
!
(
console
[
1
]
&
TREADY
));
console
[
0
]
=
(
int
)
'\r'
;
}
return
c
;
}
/**
* @brief print a single character
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment