Skip to content

Commit 939d7fd

Browse files
authored
Merge pull request #672 from sanpeqf/feat-xprintf
Feat xprintf
2 parents 7e5da16 + 790bcbd commit 939d7fd

File tree

9 files changed

+812
-1
lines changed

9 files changed

+812
-1
lines changed

include/bfdev/xprintf.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* SPDX-License-Identifier: LGPL-3.0-or-later */
2+
/*
3+
* Copyright(c) 2025 John Sanpe <sanpeqf@gmail.com>
4+
*/
5+
6+
#ifndef _BFDEV_XPRINTF_H_
7+
#define _BFDEV_XPRINTF_H_
8+
9+
#include <bfdev/config.h>
10+
#include <bfdev/types.h>
11+
#include <bfdev/stddef.h>
12+
#include <bfdev/stdarg.h>
13+
14+
BFDEV_BEGIN_DECLS
15+
16+
typedef struct bfdev_vxprintf bfdev_vxprintf_t;
17+
18+
typedef void
19+
(*bfdev_vxprintf_write)(const char *buff, bfdev_size_t len, void *pdata);
20+
21+
struct bfdev_vxprintf {
22+
bfdev_vxprintf_write write;
23+
void *pdata;
24+
};
25+
26+
extern __bfdev_printf(2, 0) bfdev_size_t
27+
bfdev_vxfprintf(bfdev_vxprintf_t *ctx, const char *fmt, bfdev_va_list args);
28+
29+
extern __bfdev_printf(2, 3) bfdev_size_t
30+
bfdev_xfprintf(bfdev_vxprintf_t *ctx, const char *fmt, ...);
31+
32+
extern __bfdev_printf(3, 0) bfdev_size_t
33+
bfdev_xnprintf(char *buff, bfdev_size_t size, const char *fmt, bfdev_va_list args);
34+
35+
extern __bfdev_printf(3, 4) bfdev_size_t
36+
bfdev_xprintf(char *buff, bfdev_size_t size, const char *fmt, ...);
37+
38+
BFDEV_END_DECLS
39+
40+
#endif /* _BFDEV_XPRINTF_H_ */

port/generic/stdio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright(c) 2025 John Sanpe <sanpeqf@gmail.com>
44
*/
55

6+
#include <bfdev/xprintf.h>
67
#include <port/stdio.h>
78
#include <export.h>
89

@@ -12,5 +13,5 @@ __bfdev_weak int
1213
bfport_vsnprintf(char *s, bfdev_size_t maxlen, const char *fmt,
1314
bfdev_va_list arg)
1415
{
15-
return 0;
16+
return bfdev_xnprintf(s, maxlen, fmt, arg);
1617
}

src/libc/build.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ set(BFDEV_SOURCE
88
${CMAKE_CURRENT_LIST_DIR}/ctype.c
99
${CMAKE_CURRENT_LIST_DIR}/strdup.c
1010
${CMAKE_CURRENT_LIST_DIR}/string.c
11+
${CMAKE_CURRENT_LIST_DIR}/xfprintf.c
12+
${CMAKE_CURRENT_LIST_DIR}/xprintf.c
1113
)

0 commit comments

Comments
 (0)