Files
mr-library/libc/scanf.c
MacRsh 3d8fcd2fdc fix(kobject): Add an empty string ("") check.
1.New parameter checking has been added. Fixed the issue where an empty string ("", that is, only the end character) was passed in. The parameter checking of kobject failed to detect the problem, resulting in data errors.
2025-05-10 22:24:59 +08:00

30 lines
664 B
C

/**
* @copyright (c) 2024, MacRsh
*
* @license SPDX-License-Identifier: Apache-2.0
*
* @date 2024-09-06 MacRsh First version
*/
#include <libc/mr_scanf.h>
#if (!defined(MR_USE_LIBC_SCANF)) && (!defined(MR_USE_3PARTY_SCANF))
#include <stdarg.h>
#include <stdio.h>
int mr_sscanf(const char *buf, const char *fmt, ...) {
va_list args;
int ret;
/* Check arguments */
if ((!buf) || (!fmt) || (fmt[0] == '\0')) {
return -1;
}
/* Scan string */
va_start(args, fmt);
ret = vsscanf(buf, fmt, args);
va_end(args);
return ret;
}
#endif /* !defined(MR_USE_LIBC_SCANF) && !defined(MR_USE_3PARTY_SCANF) */