summaryrefslogtreecommitdiff
path: root/src/library/std
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2010-04-07 11:37:21 +0200
committerAlexis211 <alexis211@gmail.com>2010-04-07 11:37:21 +0200
commitee348973b0cb0f6481e4fd6e7494c63167c9759c (patch)
treea9f1cd82703aaeeefbf4cf449203881cfcafc0a5 /src/library/std
parentca4f5906f284e60a7a59ca7450e3e09c4f9356e5 (diff)
downloadTCE-ee348973b0cb0f6481e4fd6e7494c63167c9759c.tar.gz
TCE-ee348973b0cb0f6481e4fd6e7494c63167c9759c.zip
More work on manager
Diffstat (limited to 'src/library/std')
-rw-r--r--src/library/std/stdio.c51
-rw-r--r--src/library/std/string.c40
2 files changed, 91 insertions, 0 deletions
diff --git a/src/library/std/stdio.c b/src/library/std/stdio.c
new file mode 100644
index 0000000..3b24da1
--- /dev/null
+++ b/src/library/std/stdio.c
@@ -0,0 +1,51 @@
+#include <stdlib.h>
+
+void printk_int(int number) {
+ if (number == 0) {
+ printk("0");
+ return;
+ }
+ int negative = 0;
+ if (number < 0) {
+ negative = 1;
+ number = 0 - number;
+ }
+ int order = 0, temp = number, i;
+ char numbers[] = "0123456789";
+ while (temp > 0) {
+ order++;
+ temp /= 10;
+ }
+
+ char *s, *r;
+ s = malloc(order + (negative ? 2 : 1));
+ if (negative) {
+ s[0] = '-';
+ r = s + 1;
+ } else {
+ r = s;
+ }
+
+ for (i = order; i > 0; i--) {
+ r[i - 1] = numbers[number % 10];
+ number /= 10;
+ }
+ r[order] = 0;
+ printk(s);
+ free(s);
+}
+
+void printk_hex(unsigned v) {
+ char s[11] = {'0', 'x', 0};
+
+ int i;
+
+ char hexdigits[] = "0123456789ABCDEF";
+
+ for (i = 0; i < 8; i++) {
+ s[i + 2] = (hexdigits[v >> 28]);
+ v = v << 4;
+ }
+ s[11] = 0;
+ printk(s);
+}
diff --git a/src/library/std/string.c b/src/library/std/string.c
index 869256a..4c374ad 100644
--- a/src/library/std/string.c
+++ b/src/library/std/string.c
@@ -6,6 +6,46 @@ int strlen(const char *str) {
return i;
}
+char *strchr(const char *str, char c) {
+ while (*str) {
+ if (*str == c) return (char*)str;
+ str++;
+ }
+ return NULL;
+}
+
+char *strcpy(char *dest, const char *src) {
+ memcpy(dest, src, strlen(src) + 1);
+ return (char*)src;
+}
+
+char *strdup(const char *src) {
+ char* ret = malloc(strlen(src) + 1);
+ if (ret == NULL) return ret;
+ strcpy(ret, src);
+ return ret;
+}
+
+char *strcat(char *dest, const char *src) {
+ char *dest2 = dest;
+ dest2 += strlen(dest) - 1;
+ while (*src) {
+ *dest2 = *src;
+ src++;
+ dest2++;
+ }
+ *dest2 = 0;
+ return dest;
+}
+
+int strcmp(const char *s1, const char *s2) {
+ while ((*s1) && (*s1 == *s2)) {
+ s1++;
+ s2++;
+ }
+ return (* (unsigned char*)s1 - *(unsigned char*)s2);
+}
+
void *memcpy(void *vd, const void *vs, int count) {
uint8_t *dest = (uint8_t*)vd, *src = (uint8_t*)vs;
uint32_t f = count % 4, n = count / 4, i;