From: Anup Patel Date: Wed, 4 Jan 2023 12:06:29 +0000 (+0530) Subject: lib: sbi: Add sbi_ngets() function X-Git-Tag: v1.3~111 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4e0572f57bc832b13f6e813dcdaebb1bf4d1172a;p=platform%2Fkernel%2Fopensbi-spacemit.git lib: sbi: Add sbi_ngets() function We add new sbi_ngets() which help us read characters into a physical memory location. Signed-off-by: Anup Patel Reviewed-by: Atish Patra Reviewed-by: Andrew Jones --- diff --git a/include/sbi/sbi_console.h b/include/sbi/sbi_console.h index dd6a905..3c1f5e5 100644 --- a/include/sbi/sbi_console.h +++ b/include/sbi/sbi_console.h @@ -37,6 +37,8 @@ unsigned long sbi_nputs(const char *str, unsigned long len); void sbi_gets(char *s, int maxwidth, char endchar); +unsigned long sbi_ngets(char *str, unsigned long len); + int __printf(2, 3) sbi_sprintf(char *out, const char *format, ...); int __printf(3, 4) sbi_snprintf(char *out, u32 out_sz, const char *format, ...); diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 2f83a26..c734bc0 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -76,6 +76,21 @@ void sbi_gets(char *s, int maxwidth, char endchar) *retval = '\0'; } +unsigned long sbi_ngets(char *str, unsigned long len) +{ + int ch; + unsigned long i; + + for (i = 0; i < len; i++) { + ch = sbi_getc(); + if (ch < 0) + break; + str[i] = ch; + } + + return i; +} + #define PAD_RIGHT 1 #define PAD_ZERO 2 #define PAD_ALTERNATE 4