Add strcmp and readline
This commit is contained in:
parent
694257c5ac
commit
9ffa7dde85
31
utils.c
31
utils.c
@ -1,6 +1,6 @@
|
||||
#include <stdint.h>
|
||||
#include "uart.h"
|
||||
#include "clock.h"
|
||||
#include "uart.h"
|
||||
#include <stdint.h>
|
||||
|
||||
// K&R inspirated
|
||||
|
||||
@ -71,3 +71,30 @@ void printclock()
|
||||
puts(" Hz\n");
|
||||
}
|
||||
}
|
||||
|
||||
int readline(char *buf, int maxlen)
|
||||
{
|
||||
int num = 0;
|
||||
while (num < maxlen - 1) {
|
||||
char c = uart_recv();
|
||||
// It seems like screen sends \r when I press enter
|
||||
if (c == '\n' || c == '\0' || c == '\r') {
|
||||
break;
|
||||
}
|
||||
buf[num] = c;
|
||||
num++;
|
||||
}
|
||||
buf[num] = '\0';
|
||||
return num;
|
||||
}
|
||||
|
||||
// Returns <0 if s1<s2, 0 if s1==s2, >0 if s1>s2
|
||||
int strcmp(const char s1[], const char s2[])
|
||||
{
|
||||
int i;
|
||||
for (i = 0; s1[i] == s2[i]; i++) {
|
||||
if (s1[i] == '\0')
|
||||
return 0;
|
||||
}
|
||||
return s1[i] - s2[i];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user