summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnup Patel <[email protected]>2023-01-04 17:36:29 +0530
committerAnup Patel <[email protected]>2023-02-09 22:30:06 +0530
commit4e0572f57bc832b13f6e813dcdaebb1bf4d1172a (patch)
treec1297293a92b4bcd7f116dec10da41795e966f5c
parent0ee3a86fedafccaa5f57df86b07547747920972e (diff)
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 <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
-rw-r--r--include/sbi/sbi_console.h2
-rw-r--r--lib/sbi/sbi_console.c15
2 files changed, 17 insertions, 0 deletions
diff --git a/include/sbi/sbi_console.h b/include/sbi/sbi_console.h
index dd6a905d..3c1f5e59 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 2f83a26c..c734bc0a 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