Skip to content

Commit 8b4d1c0

Browse files
mysterywolfRbb666
authored andcommitted
[klibc] add rt_sscanf
cherry-pick from: https://github.com/PetteriAimonen/Baselibc/blob/master/src/vsscanf.c BSD license
1 parent b7520e2 commit 8b4d1c0

File tree

8 files changed

+553
-2
lines changed

8 files changed

+553
-2
lines changed

include/klibc/kerrno.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define __RT_KERRNO_H__
1313

1414
#include <rtconfig.h>
15+
#include <rttypes.h>
1516

1617
#ifdef __cplusplus
1718
extern "C" {

include/klibc/kstdio.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#ifndef __RT_KSTDIO_H__
1212
#define __RT_KSTDIO_H__
1313

14+
#include <rttypes.h>
15+
#include <stdarg.h>
16+
1417
#ifdef __cplusplus
1518
extern "C" {
1619
#endif
@@ -19,6 +22,8 @@ int rt_vsprintf(char *dest, const char *format, va_list arg_ptr);
1922
int rt_vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list args);
2023
int rt_sprintf(char *buf, const char *format, ...);
2124
int rt_snprintf(char *buf, rt_size_t size, const char *format, ...);
25+
int rt_vsscanf(const char *buffer, const char *format, va_list ap);
26+
int rt_sscanf(const char *str, const char *format, ...);
2227

2328
#ifdef __cplusplus
2429
}

include/klibc/kstring.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#ifndef __RT_KSTRING_H__
1212
#define __RT_KSTRING_H__
1313

14+
#include <rttypes.h>
15+
1416
#ifdef __cplusplus
1517
extern "C" {
1618
#endif
@@ -19,6 +21,7 @@ void *rt_memset(void *src, int c, rt_ubase_t n);
1921
void *rt_memcpy(void *dest, const void *src, rt_ubase_t n);
2022
void *rt_memmove(void *dest, const void *src, rt_size_t n);
2123
rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_size_t count);
24+
2225
char *rt_strdup(const char *s);
2326
rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen);
2427
char *rt_strstr(const char *str1, const char *str2);

src/SConscript

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ from building import *
22
import os
33

44
src = Glob('*.c')
5-
src += Glob('klibc/*.c')
65
cwd = GetCurrentDir()
76
inc = [os.path.join(cwd, '..', 'include')]
87

@@ -49,4 +48,9 @@ group = DefineGroup('Kernel', src, depend=[''], CPPPATH=inc,
4948
LINKFLAGS=LINKFLAGS, LOCAL_CFLAGS=LOCAL_CFLAGS,
5049
CPPDEFINES=['__RTTHREAD__'], LOCAL_CPPDEFINES=['__RT_KERNEL_SOURCE__'])
5150

51+
list = os.listdir(cwd)
52+
for item in list:
53+
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
54+
group = group + SConscript(os.path.join(item, 'SConscript'))
55+
5256
Return('group')

src/klibc/SConscript

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from building import *
2+
import os
3+
4+
cwd = GetCurrentDir()
5+
src = Glob('*.c')
6+
7+
group = DefineGroup('klibc', src, depend = [''])
8+
9+
list = os.listdir(cwd)
10+
for item in list:
11+
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
12+
group = group + SConscript(os.path.join(item, 'SConscript'))
13+
14+
Return('group')

src/klibc/kstdio.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,25 @@ int rt_sprintf(char *buf, const char *format, ...)
7272
return n;
7373
}
7474
RTM_EXPORT(rt_sprintf);
75+
76+
/**
77+
* @brief This function parses a formatted string from the input string.
78+
*
79+
* @param str the input string to be parsed.
80+
*
81+
* @param format the format string that specifies how to interpret the input.
82+
*
83+
* @return The number of input items successfully matched and assigned.
84+
*/
85+
int rt_sscanf(const char *str, const char *format, ...)
86+
{
87+
va_list ap;
88+
int rv;
89+
90+
va_start(ap, format);
91+
rv = rt_vsscanf(str, format, ap);
92+
va_end(ap);
93+
94+
return rv;
95+
}
96+
RTM_EXPORT(rt_sscanf);

src/klibc/rt_vsnprintf_std.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2021-11-27 Meco Man porting for rt_vsnprintf as the fully functional version
9-
* 2024-11-19 Meco Man move into rtklibc
9+
* 2024-11-19 Meco Man move to klibc
1010
*/
1111

1212
/**

0 commit comments

Comments
 (0)