added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / x86_64-pc / bootstrap / support.c
blob68e17d036aba37169e3776dd2fc85497b5691694
1 /*
2 Copyright (C) 2006 The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: A very primitive clib replacements.
6 Lang: English
7 */
9 #include "support.h"
11 void *memset(void *ptr, int c, long len)
13 void *p = ptr;
14 long c32 = c | (c << 8) | (c << 16) | (c << 24);
16 while (len >= 4)
18 *(unsigned long *)ptr = c32;
19 len-=4;
20 ptr+=4;
22 if (len >= 2)
24 *(unsigned short *)ptr = c32;
25 ptr+=2;
26 len-=2;
28 if (len == 1)
30 *(unsigned char *)ptr = c32;
32 return p;
35 void *bzero(void *ptr, long len)
37 return memset(ptr, 0, len);
40 void memcpy(void *dest, const void *src, long len)
42 while (len >= 4)
44 *(unsigned long *)dest = *(unsigned long *)src;
45 len-=4;
46 dest+=4;
47 src+=4;
49 if (len >= 2)
51 *(unsigned short *)dest = *(unsigned short *)src;
52 dest+=2;
53 src+=2;
54 len-=2;
56 if (len == 1)
58 *(unsigned char *)dest = *(unsigned char *)src;
62 int strncmp(const char *s1, const char*s2, long length)
64 if (!length)
65 return 0;
67 while (length-- && *s1 && *s2)
69 if (*s1 != *s2) return (*s1-*s2);
70 s1++; s2++;
72 return 0;
75 int strlen(const char *s)
77 int len=0;
78 while(*s++ != 0) len++;
79 return len;
82 const char *remove_path(const char *in)
84 const char *p = &in[strlen(in)-1];
85 while (p > in && p[-1] != '/' && p[-1] != ':') p--;
86 return p;
89 char *strstr (const char * str, const char * search)
91 long done;
92 long len_s = strlen(search);
93 const char * t;
97 if (*search == *str)
99 done = len_s;
101 t = search + 1;
102 str++;
104 while ((--done) && (*t == *str))
106 t++;
107 str++;
110 if (!done)
112 str -= len_s;
113 return ((char *)str);
115 else
117 str -= len_s - done;
120 } while (*str++);
122 return(0);