summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-07-01 14:32:21 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-07-01 14:32:21 +0200
commitaf70f178d8fe801d05fe83d00a09509834f4f65c (patch)
treed44c5fc05a544b10592db9701bfe32baf8181bbe
parent554c9da1d6116eee356b45b579e5086ef66f21eb (diff)
downloadabaos-af70f178d8fe801d05fe83d00a09509834f4f65c.tar.gz
abaos-af70f178d8fe801d05fe83d00a09509834f4f65c.tar.bz2
added a strlcat
-rw-r--r--src/gui/text_widget.c7
-rw-r--r--src/gui/text_widget.h2
-rw-r--r--src/libc/string.c24
-rw-r--r--src/libc/string.h1
-rw-r--r--tests/libc/Makefile29
-rw-r--r--tests/libc/test_strlcat.c19
6 files changed, 71 insertions, 11 deletions
diff --git a/src/gui/text_widget.c b/src/gui/text_widget.c
index db237af..dc12c11 100644
--- a/src/gui/text_widget.c
+++ b/src/gui/text_widget.c
@@ -62,3 +62,10 @@ void text_widget_set_text( void *obj, const char *s )
strlcpy( widget->s, s, TEXT_WIDGET_MAX_TEXT_SIZE );
}
+void text_widget_on_key_down( void *obj, char c )
+{
+}
+
+void text_widget_on_key_up( void *obj, char c )
+{
+}
diff --git a/src/gui/text_widget.h b/src/gui/text_widget.h
index 7e87a3c..4919e26 100644
--- a/src/gui/text_widget.h
+++ b/src/gui/text_widget.h
@@ -20,5 +20,7 @@ void text_widget_init( text_widget_t *widget, widget_t *parent, const int x, con
void text_widget_draw( void *obj, graphics_context_t *context );
void text_widget_set_text( void *obj, const char *s );
+void text_widget_on_key_down( void *obj, char c );
+void text_widget_on_key_up( void *obj, char c );
#endif // TEXT_WIDGET_H
diff --git a/src/libc/string.c b/src/libc/string.c
index 904f33c..2dd351d 100644
--- a/src/libc/string.c
+++ b/src/libc/string.c
@@ -88,3 +88,27 @@ size_t strlcpy( char *d, const char *s, size_t n )
return len;
}
+
+size_t strlcat( char *d, const char *s, size_t n )
+{
+ size_t len = 0;
+ const char *ss = s;
+ char *dd = d;
+
+ while( len < n && *dd != '\0' ) {
+ len++;
+ dd++;
+ }
+
+ if( len == n ) {
+ return len + strlen( s );
+ }
+
+ while( len + 1 < n && ( *dd++ = *ss++ ) ) {
+ len++;
+ }
+
+ *dd = '\0';
+
+ return len;
+}
diff --git a/src/libc/string.h b/src/libc/string.h
index fc29ae9..6c0fa01 100644
--- a/src/libc/string.h
+++ b/src/libc/string.h
@@ -10,5 +10,6 @@ void *memcpy( void *d, const void *s, size_t n );
size_t strlen( const char *s );
int strcmp( const char *s1, const char *s2 );
size_t strlcpy( char *d, const char *s, size_t n );
+size_t strlcat( char *d, const char *s, size_t n );
#endif // STRING_H
diff --git a/tests/libc/Makefile b/tests/libc/Makefile
index 6b91c9b..8e0c01d 100644
--- a/tests/libc/Makefile
+++ b/tests/libc/Makefile
@@ -1,31 +1,38 @@
CC := gcc
CFLAGS := -std=c99 -m32 -ffreestanding -O0 -g -Wall -Werror
-INCLUDES = -I../src
+INCLUDES = -I../../src/libc
LD := ld
all: test
-test_strlcpy: test_strlcpy.o ../src/string.o
- $(CC) -o test_strlcpy test_strlcpy.o ../src/string.o
+test_strlcpy: test_strlcpy.o ../../src/libc/string.o
+ $(CC) -o test_strlcpy test_strlcpy.o ../../src/libc/string.o
test_strlcpy.o: test_strlcpy.c
$(CC) $(CFLAGS) $(INCLUDES) -c -o test_strlcpy.o test_strlcpy.c
-test_itoa: test_itoa.o ../src/stdlib.o ../src/string.o
- $(CC) -o test_itoa test_itoa.o ../src/stdlib.o ../src/string.o
+test_strlcat: test_strlcat.o ../../src/libc/string.o
+ $(CC) -o test_strlcat test_strlcat.o ../../src/libc/string.o
-test_itoa.o: test_itoa.c ../src/stdlib.o
+test_strlcat.o: test_strlcat.c
+ $(CC) $(CFLAGS) $(INCLUDES) -c -o test_strlcat.o test_strlcat.c
+
+test_itoa: test_itoa.o ../../src/libc/stdlib.o ../../src/libc/string.o
+ $(CC) -o test_itoa test_itoa.o ../../src/libc/stdlib.o ../../src/libc/string.o
+
+test_itoa.o: test_itoa.c ../../src/libc/stdlib.o
$(CC) $(CFLAGS) $(INCLUDES) -c -o test_itoa.o test_itoa.c
-../src/string.o: ../src/string.c
- $(CC) $(CFLAGS) -c -o ../src/string.o ../src/string.c
+../../src/libc/string.o: ../../src/libc/string.c
+ $(CC) $(CFLAGS) -c -o ../../src/libc/string.o ../../src/libc/string.c
-../src/stdlib.o: ../src/stdlib.c
+../../src/libc/stdlib.o: ../../src/libc/stdlib.c
$(CC) $(CFLAGS) -c -o ../src/stdlib.o ../src/stdlib.c
-test: test_strlcpy test_itoa
+test: test_strlcpy test_strlcat test_itoa
./test_strlcpy
+ ./test_strlcat
./test_itoa
clean:
- -rm -f test_strlcpy test_itoa *.o
+ -rm -f test_strlcpy test_strlcat test_itoa *.o
diff --git a/tests/libc/test_strlcat.c b/tests/libc/test_strlcat.c
new file mode 100644
index 0000000..074cb98
--- /dev/null
+++ b/tests/libc/test_strlcat.c
@@ -0,0 +1,19 @@
+#include "string.h"
+
+int main( void )
+{
+ char *s1 = "test_string";
+ char *s2 = "append";
+ char d[15];
+ size_t n;
+
+ *d = '\0';
+ n = strlcat( d, s1, 15 );
+ if( n != 11 ) return 1;
+ if( strcmp( d, s1 ) != 0 ) return 1;
+ n = strlcat( d, s2, 15 );
+ if( n != 14 ) return 1;
+ if( strcmp( d, "test_stringapp" ) != 0 ) return 1;
+
+ return 0;
+}