--- /dev/null
+OBJS=string.o
+CC=gcc
+CFLAGS=-c
+minilibc: $(OBJS)
+ ar rcs libminic.a $(OBJS)
+ ranlib libminic.a
+ cp libminic.a tests
+
+string.o: string.c string.h
+ $(CC) $(CFLAGS) string.c
+
+tests: minilibc
+ make -f tests/Makefile
+
\ No newline at end of file
--- /dev/null
+Minilibc is a simple C implementation. For the moment it doesn't implement memory allocation, therefore it requires a working malloc() implementation.
--- /dev/null
+#ifndef __CTYPE_H__
+#define __CTYPE_H__
+
+#define toupper(c) (c >= 97 && c <= 122) ? (c - 32) : c
+#define tolower(c) (c >= 65 && c <= 90) ? (c + 32) : c
+
+#endif
--- /dev/null
+#ifndef __STDDEF_H__
+#define __STDDEF_H__
+
+#define max(a,b) (a > b) ? a : b
+
+#define NULL 0
+
+typedef long size_t;
+
+#endif
--- /dev/null
+#ifndef __STDIO_H__
+#define __STDIO_H__
+
+#define NULL 0
+
+#endif
--- /dev/null
+#include "stdlib.h"
+
+static int *malloc_base = 0x804a000; /* It seems to be the value choosen by glibc on ia32 */
+
+void *malloc(size_t size)
+{
+ size_t retval = malloc_base;
+ malloc_base += size;
+ if (brk(malloc_base) == -1)
+ return NULL;
+
+ return (void *) retval;
+}
--- /dev/null
+#ifndef __STDLIB_H__
+#define __STDLIB_H__
+
+#include "stddef.h"
+
+void *malloc(size_t size);
+
+#endif
--- /dev/null
+/*
+ Note : most of theses routines assume that strings end with '\0'
+*/
+
+#include "string.h"
+
+size_t strlen(char *str)
+{
+ int i = 0;
+ for (i = 0; *(str + i) != '\0'; i++)
+ ;
+
+ return i;
+}
+
+
+void *memcpy(char *dest, char *src, size_t n)
+{
+ char *ptr = dest;
+ int i = 0;
+ for(i = 0; i < n; i++)
+ *dest++ = *src++;
+ return (void *) ptr;
+}
+
+
+char *strcat(char *dest, char *src)
+{
+ memcpy(dest + strlen(dest) - 1, src, strlen(src));
+ return dest;
+}
+
+char *strncat(char * dest, char *src, size_t n)
+{
+ memcpy(dest + max(n, strlen(src)) - 1, src, max(n, strlen(src)));
+ return dest;
+}
+
+size_t strcmp(char *s1, char *s2)
+{
+ size_t ret = 0;
+ while(*s1 != '\0' && *s2 != '\0')
+ ret = (*s1++ - *s2++);
+
+ return ret;
+}
+
+size_t strncmp(char *s1, char *s2, size_t n)
+{
+ size_t i = 0;
+ size_t ret = 0;
+ for (i = 0; i < n && *s1 != '\0' && *s2 != '\0'; i++)
+ ret = (*s1++ - *s2++);
+
+ return ret;
+}
+
+char *strstr(char *haystack, char *needle)
+{
+ int i;
+
+ for (i = 0; i < max(strlen(needle),strlen(haystack)); i++) {
+ /* Skip the first elements of the string that are not in needle */
+ for(; *haystack != *needle; haystack++);
+ ptr = haystack;
+ if (strlen(haystack) < strlen(needle))
+ return NULL;
+
+ if (strncmp(needle, haystack, strlen(needle)) == 0)
+ return haystack;
+ }
+}
+
+void swap(void *a, void *b)
+{
+ void *c = b;
+ b = a;
+ a = c;
+}
+
+char *strrev(char *s)
+{
+ int i = 0;
+ for (i = 0; i < strlen(s); i++)
+ swap(s + i, s + strlen(s) - i);
+}
+
+char *strchr(char *s, int c)
+{
+ size_t i = 0;
+ for (i = 0; i < strlen(s); i++)
+ if (*(s + i) == c)
+ return (s + i);
+ return NULL;
+}
+
+char *strtok(char *str, const char *delim)
+{
+ static char **strtok_arr;
+ static int strtok_called; /* We have to know if strtok was previously called with this string or not */
+ if (str != NULL) {
+ strtok_arr = NULL;
+ strtok_called = 1;
+ }
+ if (strtok_called != 1 && str == NULL) {
+ return NULL; /* This is the first time the user calls strtok and he calls it with a NULL argument*/
+ }
+
+ int occur = 0;
+ while(strstr(str, delim) != NULL)
+ /* First compute the number of occurences :*/
+ occur++;
+ strtok_arr = malloc(occur * sizeof(char *));
+
+ if (strtok_arr == NULL)
+ return NULL;
+
+ char *p = strstr(str, delim);;
+ while (p != NULL) {
+ malloc(strlen(p) * sizeof(char));
+ }
+}
--- /dev/null
+#ifndef __STRING_H__
+#define __STRING_H__
+
+#include "stddef.h"
+#include "ctype.h"
+
+size_t strlen(char *str);
+void *memcpy(char *dest, char *src, size_t n);
+char *strcat(char *dest, char *src);
+char *strncat(char * dest, char *src, size_t n);
+size_t strcmp(char *s1, char *s2);
+size_t strncmp(char *s1, char *s2, size_t n);
+char *strstr(char *haystack, char *needle);
+char *strrev(char *s);
+
+
+#endif
--- /dev/null
+#include "strings.h"
+
+size_t strcasecmp(char *s1, char *s2)
+{
+ size_t ret = 0;
+ while(*s1 != '\0' && *s2 != '\0')
+ ret = (toupper(*s1++) - toupper(*s2++));
+
+ return ret;
+}
+
+size_t strncasecmp(char *s1, char *s2, size_t n)
+{
+ size_t i = 0;
+ for (i = 0; i < n && *s1 != '\0' && *s2 != '\0'; i++)
+ ret = (toupper(*s1++) - toupper(*s2++));
+
+ return ret;
+}
+
+char *index(const char *s, int c)
+{
+ int i;
+ for (i = 0; i < strlen(s) && s[i] != c; i++)
+ ;
+
+ return (s + i);
+}
+
+char *rindex(const char *s, int c)
+{
+ int i;
+ for (i = strlen(s); i > 0 && s[i] != c; i--)
+ ;
+
+ return (s + i);
+}
+
+
--- /dev/null
+#ifndef __STRINGS_H__
+#define __STRINGS_H__
+
+size_t strcasecmp(char *s1, char *s2);
+size_t strncasecmp(char *s1, char *s2, size_t n);
+char *index(const char *s, int c);
+char *rindex(const char *s, int c);
+
+#endif
--- /dev/null
+CC=gcc
+CFLAGS=-c
+
+tests:
+ $(CC) -o tests/test_string tests/test_string.c
\ No newline at end of file
--- /dev/null
+/*
+ Simple unit test for the functions defined by string.h
+*/
+
+#include "string.h"
+#include <stdio.h>
+
+
+main(void)
+{
+ if (strcmp("cadabra", "cadabra") == 0)
+ puts("cadabra = cadabra");
+
+
+
+}
--- /dev/null
+#include "string.h"
+#include <stdio.h>
+