Browse Source

* Implemented strcmp() and strdup() and added an fflush() stub to the

kernel code.
tags/v0.99.beta14
Sam Hocevar sam 18 years ago
parent
commit
bc11640fdf
2 changed files with 31 additions and 0 deletions
  1. +28
    -0
      kernel/kernel.c
  2. +3
    -0
      kernel/kernel.h

+ 28
- 0
kernel/kernel.c View File

@@ -164,6 +164,17 @@ size_t strlen(const char *s)
return len;
}

int strcmp(const char *s1, const char *s2)
{
while(*s1 && *s1 == *s2)
{
s1++;
s2++;
}

return (int)*s1 - (int)*s2;
}

int strcasecmp(const char *s1, const char *s2)
{
while(*s1 && *s2 && UPPER(*s1) == UPPER(*s2))
@@ -189,6 +200,17 @@ int memcmp(const void *_s1, const void *_s2, size_t n)
return 0;
}

char *strdup(const char *s)
{
char *new;
unsigned int len = strlen(s);

new = malloc(len + 1);
memcpy(new, s, len + 1);

return new;
}

/* stdarg.h functions */
int vsnprintf(char *str, size_t size, const char *format, va_list ap)
{
@@ -238,6 +260,12 @@ int fprintf(FILE *stream, const char *format, ...)
return 0;
}

int fflush(FILE *stream)
{
/* FIXME */
return 0;
}

int sprintf(char *str, const char *format, ...)
{
/* FIXME */


+ 3
- 0
kernel/kernel.h View File

@@ -82,8 +82,10 @@ FILE *stdin, *stdout, *stderr;
void *memset(void *s, int c, size_t n);
void *memcpy(void *dest, const void *src, size_t n);
size_t strlen(const char *s);
int strcmp(const char *s1, const char *s2);
int strcasecmp(const char *s1, const char *s2);
int memcmp(const void *s1, const void *s2, size_t n);
char *strdup(const char *s);

/* stdarg.h functions */
typedef void * va_list;
@@ -99,6 +101,7 @@ size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
int fclose(FILE *fp);
int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
int fflush(FILE *stream);
int sprintf(char *str, const char *format, ...);
int sscanf(const char *str, const char *format, ...);



Loading…
Cancel
Save